Add assignment
This commit is contained in:
parent
fc9f1467df
commit
38bf9532ad
36
grammar.js
36
grammar.js
|
@ -1,9 +1,41 @@
|
|||
module.exports = grammar({
|
||||
name: "blueprint",
|
||||
|
||||
extras: ($) => [
|
||||
/\s+/,
|
||||
],
|
||||
|
||||
rules: {
|
||||
// TODO: add the actual grammar rules
|
||||
source_file: $ => 'hello',
|
||||
source_file: ($) => repeat($._definition),
|
||||
|
||||
_definition: ($) => choice(
|
||||
$.assignment,
|
||||
),
|
||||
|
||||
// Definitions {{{
|
||||
|
||||
assignment: ($) => seq(
|
||||
field("left", $.identifier),
|
||||
field("operator", "="),
|
||||
field("right", $._expr),
|
||||
),
|
||||
|
||||
// }}}
|
||||
|
||||
// Expressions {{{
|
||||
|
||||
_expr: ($) => choice(
|
||||
// Literals
|
||||
$.identifier,
|
||||
$.integer_literal,
|
||||
),
|
||||
|
||||
// The Blueprint scanner makes use of Go's lexer, so copy their rule
|
||||
identifier: (_) => /[_\p{XID_Start}][_\p{XID_Continue}]*/,
|
||||
|
||||
integer_literal: (_) => /[0-9]+/,
|
||||
|
||||
// }}}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
66
src/grammar.json
generated
66
src/grammar.json
generated
|
@ -2,14 +2,76 @@
|
|||
"name": "blueprint",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_definition"
|
||||
}
|
||||
},
|
||||
"_definition": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "assignment"
|
||||
}
|
||||
]
|
||||
},
|
||||
"assignment": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "hello"
|
||||
"value": "="
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expr"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"_expr": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "integer_literal"
|
||||
}
|
||||
]
|
||||
},
|
||||
"identifier": {
|
||||
"type": "PATTERN",
|
||||
"value": "[_\\p{XID_Start}][_\\p{XID_Continue}]*"
|
||||
},
|
||||
"integer_literal": {
|
||||
"type": "PATTERN",
|
||||
"value": "[0-9]+"
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s"
|
||||
"value": "\\s+"
|
||||
}
|
||||
],
|
||||
"conflicts": [],
|
||||
|
|
62
src/node-types.json
generated
62
src/node-types.json
generated
|
@ -1,11 +1,69 @@
|
|||
[
|
||||
{
|
||||
"type": "assignment",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"left": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"operator": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "=",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"right": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "source_file",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "assignment",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "hello",
|
||||
"type": "=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
}
|
||||
]
|
2015
src/parser.c
generated
2015
src/parser.c
generated
File diff suppressed because it is too large
Load diff
50
test/corpus/definitions.txt
Normal file
50
test/corpus/definitions.txt
Normal file
|
@ -0,0 +1,50 @@
|
|||
================================================================================
|
||||
Empty file
|
||||
================================================================================
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file)
|
||||
|
||||
================================================================================
|
||||
Integer assignment
|
||||
================================================================================
|
||||
|
||||
foo = 42
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(integer_literal)))
|
||||
|
||||
================================================================================
|
||||
Variable assignment
|
||||
================================================================================
|
||||
|
||||
foo = bar
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
Multiple assignments
|
||||
================================================================================
|
||||
|
||||
foo = 12
|
||||
bar = 27
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(integer_literal))
|
||||
(assignment
|
||||
(identifier)
|
||||
(integer_literal)))
|
Loading…
Reference in a new issue