add splat expressions
This commit is contained in:
22
grammar.js
22
grammar.js
@@ -9,12 +9,11 @@ module.exports = grammar({
|
||||
conflicts: $ => [
|
||||
[$.body],
|
||||
[$.object_elem, $.variable_expr],
|
||||
[$.attr_splat],
|
||||
[$.full_splat],
|
||||
],
|
||||
|
||||
extras: $ => [
|
||||
$.comment,
|
||||
/\s/,
|
||||
],
|
||||
extras: $ => [$.comment, /\s/],
|
||||
|
||||
rules: {
|
||||
config_file: $ => $.body,
|
||||
@@ -58,9 +57,9 @@ module.exports = grammar({
|
||||
$.variable_expr,
|
||||
// $.function_call,
|
||||
// $.for_expr,
|
||||
// seq($.expr_term, $.index),
|
||||
// seq($.expr_term, $.get_attr),
|
||||
// seq($.expr_term, $.splat),
|
||||
seq($.expr_term, $.index),
|
||||
seq($.expr_term, $.get_attr),
|
||||
seq($.expr_term, $.splat),
|
||||
seq('(', $.expression, ')'),
|
||||
),
|
||||
|
||||
@@ -108,6 +107,15 @@ module.exports = grammar({
|
||||
$.expression,
|
||||
),
|
||||
|
||||
index: $ => seq('[', $.expression, ']'),
|
||||
|
||||
get_attr: $ => seq('.', $.identifier),
|
||||
|
||||
splat: $ => choice($.attr_splat, $.full_splat),
|
||||
|
||||
attr_splat: $ => seq('.', '*', repeat($.get_attr)),
|
||||
full_splat: $ => seq('[', '*', ']', repeat(choice($.get_attr, $.index))),
|
||||
|
||||
variable_expr: $ => $.identifier,
|
||||
|
||||
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
||||
|
||||
141
src/grammar.json
141
src/grammar.json
@@ -152,6 +152,45 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "variable_expr"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expr_term"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "index"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expr_term"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "get_attr"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expr_term"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "splat"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
@@ -382,6 +421,102 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"index": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
},
|
||||
"get_attr": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
"splat": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "attr_splat"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "full_splat"
|
||||
}
|
||||
]
|
||||
},
|
||||
"attr_splat": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "*"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "get_attr"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"full_splat": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "get_attr"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "index"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"variable_expr": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
@@ -455,6 +590,12 @@
|
||||
[
|
||||
"object_elem",
|
||||
"variable_expr"
|
||||
],
|
||||
[
|
||||
"attr_splat"
|
||||
],
|
||||
[
|
||||
"full_splat"
|
||||
]
|
||||
],
|
||||
"precedences": [],
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
[
|
||||
{
|
||||
"type": "attr_splat",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "get_attr",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "attribute",
|
||||
"named": true,
|
||||
@@ -122,21 +137,37 @@
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "collection_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expr_term",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "get_attr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "index",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "literal_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "splat",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable_expr",
|
||||
"named": true
|
||||
@@ -159,6 +190,55 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "full_splat",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "get_attr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "index",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "get_attr",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "index",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "literal_value",
|
||||
"named": true,
|
||||
@@ -220,6 +300,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "splat",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "attr_splat",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "full_splat",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string_lit",
|
||||
"named": true,
|
||||
@@ -267,10 +366,18 @@
|
||||
"type": ")",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "*",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ".",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ":",
|
||||
"named": false
|
||||
|
||||
1672
src/parser.c
1672
src/parser.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user