add collections; improve identifier
This commit is contained in:
47
grammar.js
47
grammar.js
@@ -1,12 +1,15 @@
|
|||||||
const
|
const
|
||||||
space = ' ',
|
//TODO figure out how to subtact regex sets
|
||||||
decimal = /[0-9]/
|
unicodeLetter = /\p{L}/
|
||||||
|
unicodePunctuation = /\p{Pc}/
|
||||||
|
unicodeDigit = /[0-9]/
|
||||||
|
|
||||||
module.exports = grammar({
|
module.exports = grammar({
|
||||||
name: 'hcl',
|
name: 'hcl',
|
||||||
|
|
||||||
conflicts: $ => [
|
conflicts: $ => [
|
||||||
[$.body],
|
[$.body],
|
||||||
|
[$.object_elem, $.variable_expr],
|
||||||
],
|
],
|
||||||
|
|
||||||
extras: $ => [
|
extras: $ => [
|
||||||
@@ -46,7 +49,7 @@ module.exports = grammar({
|
|||||||
|
|
||||||
expr_term: $ => choice(
|
expr_term: $ => choice(
|
||||||
$.literal_value,
|
$.literal_value,
|
||||||
// $.collection_value,
|
$.collection_value,
|
||||||
// $.template_expr,
|
// $.template_expr,
|
||||||
$.variable_expr,
|
$.variable_expr,
|
||||||
// $.function_call,
|
// $.function_call,
|
||||||
@@ -68,6 +71,35 @@ module.exports = grammar({
|
|||||||
|
|
||||||
numeric_lit: $ => /[0-9]+(\.[0-9]+([eE][-+]?[0-9]+)?)?/,
|
numeric_lit: $ => /[0-9]+(\.[0-9]+([eE][-+]?[0-9]+)?)?/,
|
||||||
|
|
||||||
|
collection_value: $ => choice(
|
||||||
|
$.tuple,
|
||||||
|
$.object,
|
||||||
|
),
|
||||||
|
|
||||||
|
tuple: $ => seq(
|
||||||
|
'[',
|
||||||
|
optional(seq(
|
||||||
|
$.expression,
|
||||||
|
repeat(seq(',', $.expression)),
|
||||||
|
)),
|
||||||
|
']',
|
||||||
|
),
|
||||||
|
|
||||||
|
object: $ => seq(
|
||||||
|
'{',
|
||||||
|
optional(seq(
|
||||||
|
$.object_elem,
|
||||||
|
repeat(seq(',', $.object_elem)),
|
||||||
|
)),
|
||||||
|
'}',
|
||||||
|
),
|
||||||
|
|
||||||
|
object_elem: $ => seq(
|
||||||
|
choice($.identifier, $.expression),
|
||||||
|
choice('=', ':'),
|
||||||
|
$.expression,
|
||||||
|
),
|
||||||
|
|
||||||
variable_expr: $ => $.identifier,
|
variable_expr: $ => $.identifier,
|
||||||
|
|
||||||
// TODO: template expressions
|
// TODO: template expressions
|
||||||
@@ -81,8 +113,11 @@ module.exports = grammar({
|
|||||||
// TODO: string_literals are special template literals
|
// TODO: string_literals are special template literals
|
||||||
string_lit: $ => seq('"', /\w+/, '"'),
|
string_lit: $ => seq('"', /\w+/, '"'),
|
||||||
|
|
||||||
// TODO: unicode identifier
|
// TODO: not to spec, but maybe good enough
|
||||||
identifier: $ => /\w+/,
|
identifier: $ => token(seq(
|
||||||
|
unicodeLetter,
|
||||||
|
repeat(choice(unicodeLetter, unicodeDigit, unicodePunctuation))
|
||||||
|
)),
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
||||||
comment: $ => token(choice(
|
comment: $ => token(choice(
|
||||||
@@ -93,6 +128,6 @@ module.exports = grammar({
|
|||||||
/[^*]*\*+([^/*][^*]*\*+)*/,
|
/[^*]*\*+([^/*][^*]*\*+)*/,
|
||||||
'/'
|
'/'
|
||||||
)
|
)
|
||||||
))
|
)),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
180
src/grammar.json
180
src/grammar.json
@@ -104,6 +104,10 @@
|
|||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "literal_value"
|
"name": "literal_value"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "collection_value"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "variable_expr"
|
"name": "variable_expr"
|
||||||
@@ -156,6 +160,146 @@
|
|||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "[0-9]+(\\.[0-9]+([eE][-+]?[0-9]+)?)?"
|
"value": "[0-9]+(\\.[0-9]+([eE][-+]?[0-9]+)?)?"
|
||||||
},
|
},
|
||||||
|
"collection_value": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "tuple"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "object"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"tuple": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "["
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ","
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "]"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"object": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "{"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "object_elem"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ","
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "object_elem"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"object_elem": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "="
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ":"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"variable_expr": {
|
"variable_expr": {
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "identifier"
|
"name": "identifier"
|
||||||
@@ -178,8 +322,36 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"identifier": {
|
"identifier": {
|
||||||
"type": "PATTERN",
|
"type": "TOKEN",
|
||||||
"value": "\\w+"
|
"content": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "\\p{L}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "\\p{L}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[0-9]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "\\p{Pc}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"comment": {
|
"comment": {
|
||||||
"type": "TOKEN",
|
"type": "TOKEN",
|
||||||
@@ -246,6 +418,10 @@
|
|||||||
"conflicts": [
|
"conflicts": [
|
||||||
[
|
[
|
||||||
"body"
|
"body"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"object_elem",
|
||||||
|
"variable_expr"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"precedences": [],
|
"precedences": [],
|
||||||
|
|||||||
@@ -60,6 +60,25 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "collection_value",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tuple",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "config_file",
|
"type": "config_file",
|
||||||
"named": true,
|
"named": true,
|
||||||
@@ -83,6 +102,10 @@
|
|||||||
"multiple": false,
|
"multiple": false,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "collection_value",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "expression",
|
"type": "expression",
|
||||||
"named": true
|
"named": true
|
||||||
@@ -113,11 +136,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "identifier",
|
|
||||||
"named": true,
|
|
||||||
"fields": {}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "literal_value",
|
"type": "literal_value",
|
||||||
"named": true,
|
"named": true,
|
||||||
@@ -137,11 +155,60 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "object_elem",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object_elem",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "expression",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "identifier",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "string_lit",
|
"type": "string_lit",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {}
|
"fields": {}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "tuple",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "expression",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "variable_expr",
|
"type": "variable_expr",
|
||||||
"named": true,
|
"named": true,
|
||||||
@@ -169,10 +236,26 @@
|
|||||||
"type": ")",
|
"type": ")",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": ",",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": ":",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "=",
|
"type": "=",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "[",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "]",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "comment",
|
"type": "comment",
|
||||||
"named": true
|
"named": true
|
||||||
@@ -181,6 +264,10 @@
|
|||||||
"type": "false",
|
"type": "false",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "identifier",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "null",
|
"type": "null",
|
||||||
"named": false
|
"named": false
|
||||||
|
|||||||
2909
src/parser.c
2909
src/parser.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user