add for expressions
This commit is contained in:
44
grammar.js
44
grammar.js
@@ -13,7 +13,10 @@ module.exports = grammar({
|
||||
[$.full_splat],
|
||||
],
|
||||
|
||||
extras: $ => [$.comment, /\s/],
|
||||
extras: $ => [
|
||||
$.comment,
|
||||
/\s/,
|
||||
],
|
||||
|
||||
rules: {
|
||||
config_file: $ => $.body,
|
||||
@@ -28,7 +31,7 @@ module.exports = grammar({
|
||||
attribute: $ => seq(
|
||||
field('name', $.identifier),
|
||||
'=',
|
||||
$.expression
|
||||
$.expression,
|
||||
),
|
||||
|
||||
block: $ => seq(
|
||||
@@ -42,7 +45,7 @@ module.exports = grammar({
|
||||
// TODO: not to spec but good enough for now
|
||||
identifier: $ => token(seq(
|
||||
unicodeLetter,
|
||||
repeat(choice(unicodeLetter, unicodeDigit, unicodePunctuation))
|
||||
repeat(choice(unicodeLetter, unicodeDigit, unicodePunctuation)),
|
||||
)),
|
||||
|
||||
expression: $ => choice(
|
||||
@@ -56,7 +59,7 @@ module.exports = grammar({
|
||||
$.collection_value,
|
||||
$.variable_expr,
|
||||
// $.function_call,
|
||||
// $.for_expr,
|
||||
$.for_expr,
|
||||
seq($.expr_term, $.index),
|
||||
seq($.expr_term, $.get_attr),
|
||||
seq($.expr_term, $.splat),
|
||||
@@ -114,8 +117,41 @@ module.exports = grammar({
|
||||
splat: $ => choice($.attr_splat, $.full_splat),
|
||||
|
||||
attr_splat: $ => seq('.', '*', repeat($.get_attr)),
|
||||
|
||||
full_splat: $ => seq('[', '*', ']', repeat(choice($.get_attr, $.index))),
|
||||
|
||||
for_expr: $ => choice($.for_tuple_expr, $.for_object_expr),
|
||||
|
||||
for_tuple_expr: $ => seq(
|
||||
'[',
|
||||
$.for_intro,
|
||||
$.expression,
|
||||
optional($.for_cond),
|
||||
']',
|
||||
),
|
||||
|
||||
for_object_expr: $ => seq(
|
||||
'{',
|
||||
$.for_intro,
|
||||
$.expression,
|
||||
'=>',
|
||||
$.expression,
|
||||
optional('...'),
|
||||
optional($.for_cond),
|
||||
'}',
|
||||
),
|
||||
|
||||
for_intro: $ => seq(
|
||||
'for',
|
||||
$.identifier,
|
||||
optional(seq(',', $.identifier)),
|
||||
'in',
|
||||
$.expression,
|
||||
':',
|
||||
),
|
||||
|
||||
for_cond: $ => seq('if', $.expression),
|
||||
|
||||
variable_expr: $ => $.identifier,
|
||||
|
||||
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
||||
|
||||
@@ -8,4 +8,5 @@
|
||||
(bool_lit) @boolean
|
||||
(null_lit) @null
|
||||
(comment) @comment
|
||||
(for_intro) @keyword
|
||||
|
||||
|
||||
162
src/grammar.json
162
src/grammar.json
@@ -152,6 +152,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "variable_expr"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_expr"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
@@ -517,6 +521,164 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"for_expr": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_tuple_expr"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_object_expr"
|
||||
}
|
||||
]
|
||||
},
|
||||
"for_tuple_expr": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_intro"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_cond"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
},
|
||||
"for_object_expr": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_intro"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "=>"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "..."
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_cond"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"for_intro": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "for"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "in"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
}
|
||||
]
|
||||
},
|
||||
"for_cond": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "if"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
"variable_expr": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
|
||||
@@ -152,6 +152,10 @@
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "for_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "get_attr",
|
||||
"named": true
|
||||
@@ -190,6 +194,105 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "for_cond",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "for_expr",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "for_object_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "for_tuple_expr",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "for_intro",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "for_object_expr",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "for_cond",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "for_intro",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "for_tuple_expr",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "for_cond",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "for_intro",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "full_splat",
|
||||
"named": true,
|
||||
@@ -378,6 +481,10 @@
|
||||
"type": ".",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "...",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ":",
|
||||
"named": false
|
||||
@@ -386,6 +493,10 @@
|
||||
"type": "=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "=>",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "[",
|
||||
"named": false
|
||||
@@ -402,10 +513,22 @@
|
||||
"type": "false",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "for",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "in",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "null_lit",
|
||||
"named": true
|
||||
|
||||
4241
src/parser.c
4241
src/parser.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user