micro/runtime/syntax/javascript.yaml
Jöran Karl 0859f4aa36
Fix: Syntax highlighting for various issues (#2810)
* highlighter: Fix region & pattern detection

* syntax/sh: Highlight upper case options too

* syntax/c(pp): Try to synchronize the rules to lower the maintenance effort

* syntax/ruby: Fix explicit filename detection in directories

* highlighter: Respect skip rules in regions

* syntax/sh: Fix parameter expansion, cond. flags and generalize filename via ""

* syntax/php|vi: Correct strings in comments to comments only

Additionally improve vimscript comment handling.

* highlighter: Remove problematic start|end check in find(all)Index()

...and additionally remove recursive region end detection
2023-06-05 17:39:12 -07:00

77 lines
2.8 KiB
YAML

filetype: javascript
detect:
filename: "(\\.js$|\\.es[5678]?$|\\.mjs$)"
header: "^#!.*/(env +)?node( |$)"
rules:
- constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b"
- constant.number: "\\b[-+]?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?"
- constant.number: "\\b[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?"
#- identifier: "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[(]"
# ^ this is not correct usage of the identifier color
- symbol.brackets: "[(){}]|\\[|\\]"
- symbol.operator: "([-+/*=<>!~%?:&|]|[.]{3})"
- statement: "\\b(async|await|break|case|catch|const|continue|debugger|default)\\b"
- statement: "\\b(delete|do|else|export|finally|for|function\\*?|class|extends)\\b"
- statement: "\\b(get|if|import|from|in|of|instanceof|let|new|reject|resolve|return)\\b"
- statement: "\\b(set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\\b"
# reserved but unassigned
- error: "\\b(enum|implements|interface|package|private|protected|public)\\b"
- constant: "\\b(globalThis|Infinity|null|undefined|NaN)\\b"
- constant: "\\b(null|undefined|NaN)\\b"
- constant: "\\b(true|false)\\b"
- type: "\\b(Array|Boolean|Date|Enumerator|Error|Function|Generator|Map|Math)\\b"
- type: "\\b(Number|Object|Promise|Proxy|Reflect|RegExp|Set|String|Symbol|WeakMap|WeakSet)\\b"
- type: "\\b(BigInt64Array|BigUint64Array|Float32Array|Float64Array|Int16Array)\\b"
# - constant: "/[^*]([^/]|(\\\\/))*[^\\\\]/[gim]*"
- constant: "\\\\[0-7][0-7]?[0-7]?|\\\\x[0-9a-fA-F]+|\\\\[bfnrt'\"\\?\\\\]"
- comment: "^#!.*/(env +)?node( |$)"
- identifier: "\\b(alert|decodeURI|decodeURIComponent|document|encodeURI|encodeURIComponent|escape|eval|isFinite|isNaN|parseFloat|parseInt|unescape|uneval|window)\\b"
- identifier: "\\b(Intl|WebAssembly)\\b"
- identifier: "\\b(Arguments)\\b"
- constant.string:
start: "\""
end: "\""
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."
- constant.string:
start: "'"
end: "'"
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."
- constant.string:
start: "`"
end: "`"
rules:
- constant.specialChar: "\\\\."
- identifier: "\\x24\\{.*?\\}"
- constant.bool: "\\b(true|false)\\b"
- constant.bool.false: "\\b(false)\\b"
- constant.bool.true: "\\b(true)\\b"
- comment:
start: "//"
end: "$"
rules:
- todo: "(TODO|XXX|FIXME)"
- comment:
start: "/\\*"
end: "\\*/"
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."
# function documentation
- identifier: "\\s\\*\\s.*"
- todo: "(TODO|XXX|FIXME)"