Skip to content

Commit

Permalink
BBj: Improve regexes (#3512)
Browse files Browse the repository at this point in the history
* BBj: extend BBj keywords list

* BBj: fix strings regex does not match single quotes

* BBj: add `declare` as keyword
  • Loading branch information
hyyan authored Aug 1, 2022
1 parent 1134bdf commit 0cad9ae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
4 changes: 2 additions & 2 deletions components/prism-bbj.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
greedy: true
},
'string': {
pattern: /"(?:""|[!#$%&'()*,\/:;<=>?^\w +\-.])*"/,
pattern: /(['"])(?:(?!\1|\\).|\\.)*\1/,
greedy: true
},
'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:E[+-]?\d+)?/i,
'keyword': /\b(?:abstract|all|argc|begin|bye|callback|case|chn|class|classend|ctl|day|delete|dom|dread|dsz|else|endif|err|exitto|extends|fi|field|for|from|gosub|goto|if|implements|interface|interfaceend|iol|iolist|let|list|load|method|methodend|methodret|on|opts|pfx|private|process_events|protected|psz|public|read_resource|remove_callback|restore|rev|seterr|setesc|sqlchn|sqlunt|ssn|start|static|swend|switch|sys|then|tim|unt|until|use|void|wend|where|while)\b/i,
'keyword': /\b(?:abstract|all|argc|begin|bye|callback|case|chn|class|classend|ctl|day|declare|delete|dim|dom|dread|dsz|else|end|endif|err|exitto|extends|fi|field|for|from|gosub|goto|if|implements|interface|interfaceend|iol|iolist|let|list|load|method|methodend|methodret|on|opts|pfx|print|private|process_events|protected|psz|public|read|read_resource|release|remove_callback|repeat|restore|return|rev|seterr|setesc|sqlchn|sqlunt|ssn|start|static|swend|switch|sys|then|tim|unt|until|use|void|wend|where|while)\b/i,
'function': /\b\w+(?=\()/,
'boolean': /\b(?:BBjAPI\.TRUE|BBjAPI\.FALSE)\b/i,
'operator': /<[=>]?|>=?|[+\-*\/^=&]|\b(?:and|not|or|xor)\b/i,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bbj.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions tests/languages/bbj/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
abstract all argc begin bye callback case chn class classend ctl day delete dom dread dsz else
endif err exitto extends fi field field for from gosub goto if implements interface interfaceend
iol iolist let list load method methodend methodret on opts pfx private private process_events
protected protected psz public public read_resource remove_callback restore rev seterr setesc sqlchn
sqlunt ssn start static static swend switch sys then tim unt until void void wend where while use
abstract all argc begin bye callback case chn class classend ctl day delete dim dom
dread dsz else end endif err exitto extends fi field for from gosub goto if implements
interface interfaceend iol iolist let list load method methodend methodret on opts pfx
print private process_events protected psz public read read_resource release remove_callback
repeat restore return rev seterr setesc sqlchn sqlunt ssn start static swend switch sys then
tim unt until use void wend where while declare

----------------------------------------------------

Expand All @@ -20,27 +21,28 @@ sqlunt ssn start static static swend switch sys then tim unt until void void wen
["keyword", "ctl"],
["keyword", "day"],
["keyword", "delete"],
["keyword", "dim"],
["keyword", "dom"],

["keyword", "dread"],
["keyword", "dsz"],
["keyword", "else"],

["keyword", "end"],
["keyword", "endif"],
["keyword", "err"],
["keyword", "exitto"],
["keyword", "extends"],
["keyword", "fi"],
["keyword", "field"],
["keyword", "field"],
["keyword", "for"],
["keyword", "from"],
["keyword", "gosub"],
["keyword", "goto"],
["keyword", "if"],
["keyword", "implements"],

["keyword", "interface"],
["keyword", "interfaceend"],

["keyword", "iol"],
["keyword", "iolist"],
["keyword", "let"],
Expand All @@ -52,41 +54,43 @@ sqlunt ssn start static static swend switch sys then tim unt until void void wen
["keyword", "on"],
["keyword", "opts"],
["keyword", "pfx"],
["keyword", "private"],

["keyword", "print"],
["keyword", "private"],
["keyword", "process_events"],

["keyword", "protected"],
["keyword", "protected"],
["keyword", "psz"],
["keyword", "public"],
["keyword", "public"],
["keyword", "read"],
["keyword", "read_resource"],
["keyword", "release"],
["keyword", "remove_callback"],

["keyword", "repeat"],
["keyword", "restore"],
["keyword", "return"],
["keyword", "rev"],
["keyword", "seterr"],
["keyword", "setesc"],
["keyword", "sqlchn"],

["keyword", "sqlunt"],
["keyword", "ssn"],
["keyword", "start"],
["keyword", "static"],
["keyword", "static"],
["keyword", "swend"],
["keyword", "switch"],
["keyword", "sys"],
["keyword", "then"],

["keyword", "tim"],
["keyword", "unt"],
["keyword", "until"],
["keyword", "void"],
["keyword", "use"],
["keyword", "void"],
["keyword", "wend"],
["keyword", "where"],
["keyword", "while"],
["keyword", "use"]
["keyword", "declare"]
]

----------------------------------------------------
Expand Down
20 changes: 17 additions & 3 deletions tests/languages/bbj/string_feature.test
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
""
"fo""obar"
''
"f\"oo"
'b\'ar'

"foo rem comment bar"
"foo ""rem"" comment bar"
"foo rem /* *rem comment bar"

----------------------------------------------------

[
["string", "\"\""],
["string", "\"fo\"\"obar\""]
["string", "''"],
["string", "\"f\\\"oo\""],
["string", "'b\\'ar'"],

["string", "\"foo rem comment bar\""],
["string", "\"foo \""],
["string", "\"rem\""],
["string", "\" comment bar\""],
["string", "\"foo rem /* *rem comment bar\""]
]

----------------------------------------------------

Checks for strings.
Checks for strings.

0 comments on commit 0cad9ae

Please sign in to comment.