From 214c4ee8a66dccc056d09996d65a5691c97dc2b4 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Wed, 9 Mar 2022 09:01:33 -0500 Subject: [PATCH] Add Sentinel Grammar (#10) Add https://github.com/hashicorp/vscode-sentinel/blob/81b8073d4ddb3b670c2a0742b682ef9343b06254/syntaxes/sentinel.tmlanguage.json to project. - Format file to conform to existing structure in hcl.tmGrammar.json. - Rename file to sentinel.tmGrammar.json --- package.json | 3 +- syntaxes/sentinel.tmGrammar.json | 108 ++++++++++++++++++++ tests/snapshot/sentinel/basic.sentinel | 9 ++ tests/snapshot/sentinel/basic.sentinel.snap | 42 ++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 syntaxes/sentinel.tmGrammar.json create mode 100644 tests/snapshot/sentinel/basic.sentinel create mode 100644 tests/snapshot/sentinel/basic.sentinel.snap diff --git a/package.json b/package.json index f5f841a..21c1888 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,10 @@ "check": "prettier --check syntaxes/*.json", "format": "prettier --write syntaxes/*.json", "test": "npm run test:snap", - "test:snap": "npm run test:snap:hcl && npm run test:snap:terraform", + "test:snap": "npm run test:snap:hcl && npm run test:snap:sentinel && npm run test:snap:terraform", "test:snap:update": "npm run test:snap:hcl -- -u && npm run test:snap:terraform -- -u", "test:snap:hcl": "npx vscode-tmgrammar-snap -s source.hcl -g syntaxes/hcl.tmGrammar.json -t \"tests/snapshot/hcl/*.hcl\"", + "test:snap:sentinel": "npx vscode-tmgrammar-snap -s source.sentinel -g syntaxes/sentinel.tmGrammar.json -t \"tests/snapshot/sentinel/*.sentinel\"", "test:snap:terraform": "npx vscode-tmgrammar-snap -s source.hcl.terraform -g syntaxes/terraform.tmGrammar.json -g syntaxes/hcl.tmGrammar.json -t \"tests/snapshot/terraform/*.tf\"" }, "devDependencies": { diff --git a/syntaxes/sentinel.tmGrammar.json b/syntaxes/sentinel.tmGrammar.json new file mode 100644 index 0000000..4e1fb80 --- /dev/null +++ b/syntaxes/sentinel.tmGrammar.json @@ -0,0 +1,108 @@ +{ + "scopeName": "source.sentinel", + "name": "HashiCorp Sentinel", + "uuid": "B6448CA1-0D29-4C4F-B1F3-5A0B0E875453", + "fileTypes": ["sentinel"], + "patterns": [ + { + "name": "comment.line.double-slash.sentinel", + "match": "\\/\\/.*$" + }, + { + "name": "comment.line.number-sign.sentinel", + "match": "#.*$" + }, + { + "begin": "/\\*", + "end": "\\*/", + "name": "comment.line.block.sentinel" + }, + { + "name": "constant.numeric.hex.sentinel", + "match": "\\b0[xX][a-fA-F0-9]+\\b" + }, + { + "name": "constant.numeric.oct.sentinel", + "match": "\\b0[0-7]+\\b" + }, + { + "name": "constant.numeric.number.sentinel", + "match": "\\b(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))([eE][-+]?[0-9]+)?\\b" + }, + { + "name": "constant.language.sentinel", + "match": "\\b(true|false|null|undefined)\\b" + }, + { + "captures": { + "1": { + "name": "keyword.control.when.sentinel" + } + }, + "match": "\\b(when)\\b\\s+.*:" + }, + { + "captures": { + "1": { + "name": "keyword.control.else.sentinel" + } + }, + "match": "\\b(else)\\b:" + }, + { + "name": "keyword.control.declaration.sentinel", + "match": "\\b(import|param)\\b" + }, + { + "name": "keyword.control.sentinel", + "match": "\\b(if|case|for|any|all|filter|break|continue|return)\\b" + }, + { + "name": "keyword.operator.symbol.sentinel", + "match": "[-+*/%=<>!]" + }, + { + "name": "keyword.control.sentinel", + "match": "\\b(and|or|contains|in|is|matches|not|xor|else)\\b" + }, + { + "name": "keyword.other.sentinel", + "match": "\\b(func|rule)\\b" + }, + { + "name": "keyword.other.sentinel", + "match": "\\b(as|default|when)\\b" + }, + { + "patterns": [ + { + "name": "constant.character.escape.single.sentinel", + "match": "\\\\[abfnrtv\\\\\"]" + }, + { + "name": "constant.character.escape.hex.sentinel", + "match": "\\\\x[a-fA-F0-9]+" + }, + { + "name": "constant.character.escape.oct.sentinel", + "match": "\\\\[0-7]{3}" + }, + { + "name": "constant.character.escape.unicode32.sentinel", + "match": "\\\\u[a-fA-F0-9]{4}" + }, + { + "name": "constant.character.escape.unicode64.sentinel", + "match": "\\\\U[a-fA-F0-9]{8}" + } + ], + "begin": "\"", + "end": "\"", + "name": "string.quoted.double.untitled" + }, + { + "name": "support.function.builtin.sentinel", + "match": "\\b(append|delete|error|keys|length|print|range|values|int|float|string|bool)\\b" + } + ] +} diff --git a/tests/snapshot/sentinel/basic.sentinel b/tests/snapshot/sentinel/basic.sentinel new file mode 100644 index 0000000..92f056b --- /dev/null +++ b/tests/snapshot/sentinel/basic.sentinel @@ -0,0 +1,9 @@ +hour = 4 + +past_midnight = rule { hour >= 0 } +before_noon = rule { hour < 12 } + +main = rule { + past_midnight and + before_noon +} diff --git a/tests/snapshot/sentinel/basic.sentinel.snap b/tests/snapshot/sentinel/basic.sentinel.snap new file mode 100644 index 0000000..fc40a73 --- /dev/null +++ b/tests/snapshot/sentinel/basic.sentinel.snap @@ -0,0 +1,42 @@ +>hour = 4 +#^^^^^ source.sentinel +# ^ source.sentinel keyword.operator.symbol.sentinel +# ^ source.sentinel +# ^ source.sentinel constant.numeric.number.sentinel +> +>past_midnight = rule { hour >= 0 } +#^^^^^^^^^^^^^^ source.sentinel +# ^ source.sentinel keyword.operator.symbol.sentinel +# ^ source.sentinel +# ^^^^ source.sentinel keyword.other.sentinel +# ^^^^^^^^ source.sentinel +# ^ source.sentinel keyword.operator.symbol.sentinel +# ^ source.sentinel keyword.operator.symbol.sentinel +# ^ source.sentinel +# ^ source.sentinel constant.numeric.number.sentinel +# ^^^ source.sentinel +>before_noon = rule { hour < 12 } +#^^^^^^^^^^^^^^ source.sentinel +# ^ source.sentinel keyword.operator.symbol.sentinel +# ^ source.sentinel +# ^^^^ source.sentinel keyword.other.sentinel +# ^^^^^^^^ source.sentinel +# ^ source.sentinel keyword.operator.symbol.sentinel +# ^ source.sentinel +# ^^ source.sentinel constant.numeric.number.sentinel +# ^^^ source.sentinel +> +>main = rule { +#^^^^^ source.sentinel +# ^ source.sentinel keyword.operator.symbol.sentinel +# ^ source.sentinel +# ^^^^ source.sentinel keyword.other.sentinel +# ^^^ source.sentinel +> past_midnight and +#^^^^^^^^^^^^^^^^^^ source.sentinel +# ^^^ source.sentinel keyword.control.sentinel +> before_noon +#^^^^^^^^^^^^^^^^ source.sentinel +>} +#^^ source.sentinel +> \ No newline at end of file