Skip to content

Commit

Permalink
Add Sentinel Grammar (#10)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jpogran authored Mar 9, 2022
1 parent d6ee9b7 commit 214c4ee
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
108 changes: 108 additions & 0 deletions syntaxes/sentinel.tmGrammar.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
9 changes: 9 additions & 0 deletions tests/snapshot/sentinel/basic.sentinel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
hour = 4

past_midnight = rule { hour >= 0 }
before_noon = rule { hour < 12 }

main = rule {
past_midnight and
before_noon
}
42 changes: 42 additions & 0 deletions tests/snapshot/sentinel/basic.sentinel.snap
Original file line number Diff line number Diff line change
@@ -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
>

0 comments on commit 214c4ee

Please sign in to comment.