add conditionals
This commit is contained in:
@@ -9,3 +9,9 @@ It is recommended to use `nix` to fulfill all development dependencies. To activ
|
||||
## running tests
|
||||
|
||||
To run tests simply run `nix-shell --run 'tree-sitter test'`.
|
||||
|
||||
## todo
|
||||
|
||||
* use [Unicode® Standard Annex #31](https://www.unicode.org/reports/tr31/) (augmented with '-')for identifiers
|
||||
* add [operations](https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#operations)
|
||||
* add [template expressions](https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#template-expressions) and express string literals using them
|
||||
|
||||
11
grammar.js
11
grammar.js
@@ -11,6 +11,7 @@ module.exports = grammar({
|
||||
[$.object_elem, $.variable_expr],
|
||||
[$.attr_splat],
|
||||
[$.full_splat],
|
||||
[$.conditional],
|
||||
],
|
||||
|
||||
extras: $ => [
|
||||
@@ -51,7 +52,7 @@ module.exports = grammar({
|
||||
expression: $ => choice(
|
||||
$.expr_term,
|
||||
//$.operation,
|
||||
//$.conditional,
|
||||
$.conditional,
|
||||
),
|
||||
|
||||
expr_term: $ => choice(
|
||||
@@ -172,6 +173,14 @@ module.exports = grammar({
|
||||
|
||||
ellipsis: $ => token('...'),
|
||||
|
||||
conditional: $ => seq(
|
||||
$.expression,
|
||||
'?',
|
||||
$.expression,
|
||||
':',
|
||||
$.expression,
|
||||
),
|
||||
|
||||
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
||||
comment: $ => token(choice(
|
||||
seq('#', /.*/),
|
||||
|
||||
@@ -134,6 +134,10 @@
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expr_term"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "conditional"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -776,6 +780,31 @@
|
||||
"value": "..."
|
||||
}
|
||||
},
|
||||
"conditional": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "?"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
"comment": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
@@ -816,7 +845,7 @@
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^*]*\\*+([^\\/*][^*]*\\*+)*"
|
||||
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
@@ -851,6 +880,9 @@
|
||||
],
|
||||
[
|
||||
"full_splat"
|
||||
],
|
||||
[
|
||||
"conditional"
|
||||
]
|
||||
],
|
||||
"precedences": [],
|
||||
|
||||
@@ -117,6 +117,21 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "conditional",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "config_file",
|
||||
"named": true,
|
||||
@@ -191,6 +206,10 @@
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "conditional",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expr_term",
|
||||
"named": true
|
||||
@@ -546,6 +565,10 @@
|
||||
"type": "=>",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "?",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "[",
|
||||
"named": false
|
||||
|
||||
5232
src/parser.c
5232
src/parser.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user