Correct grammar

This commit is contained in:
Jeff 2023-08-24 10:12:08 -04:00
parent f8c1c3d9b4
commit 7a80c89dc7
5 changed files with 1014 additions and 661 deletions

View File

@ -52,14 +52,14 @@ x = y + y;
(source_file (source_file
(expression (expression
(identifier)) (identifier)
(operator) (operator)
(expression (expression
(identifier)) (identifier)
(operator) (operator)
(expression (expression
(identifier)) (identifier))))
(operator)) (chain))
================== ==================
String String
@ -70,7 +70,7 @@ String
--- ---
(source_file (source_file
(expression (value
(string))) (string)))
================== ==================
@ -82,7 +82,7 @@ Integer
--- ---
(source_file (source_file
(expression (value
(integer))) (integer)))
================== ==================
@ -94,7 +94,7 @@ Float
--- ---
(source_file (source_file
(expression (value
(float))) (float)))
@ -107,12 +107,12 @@ List
--- ---
(source_file (source_file
(expression (value
(list (list
(expression (value
(integer)) (integer)))
(expression (value
(integer))))) (integer))))
================== ==================
Empty Empty
@ -123,7 +123,7 @@ Empty
--- ---
(source_file (source_file
(expression (value
(empty))) (empty)))
================== ==================
@ -137,8 +137,8 @@ random_boolean();
(source_file (source_file
(expression (expression
(tool)) (tool))
(expression (value
(empty)) (empty))
(operator)) (chain))

View File

@ -1,28 +1,42 @@
module.exports = grammar({ module.exports = grammar({
name: 'dust', name: 'Dust',
rules: { rules: {
source_file: $ => repeat(choice($.comment, $.expression, $.operator)), source_file: $ => repeat(choice(
$.comment,
$.expression,
$.value,
$.yield,
$.chain
)),
comment: $ => /(#)(.+?)([\n\r])/, comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice( expression: $ => choice(
$.identifier, $.identifier,
$.tool,
seq($.identifier, $.operator, $.expression),
seq($.value, $.operator, $.value)
),
value: $ => choice(
$.integer, $.integer,
$.float, $.float,
$.string, $.string,
$.list, $.list,
$.tool,
$.empty, $.empty,
), ),
yield: $ => "->",
chain: $ => ";",
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/, identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
operator: $ => choice( operator: $ => choice(
'=', '=',
'-', '-',
'+', '+',
';',
'/', '/',
'|', '|',
'&' '&'

View File

@ -1,5 +1,5 @@
{ {
"name": "dust", "name": "Dust",
"rules": { "rules": {
"source_file": { "source_file": {
"type": "REPEAT", "type": "REPEAT",
@ -16,7 +16,15 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "operator" "name": "value"
},
{
"type": "SYMBOL",
"name": "yield"
},
{
"type": "SYMBOL",
"name": "chain"
} }
] ]
} }
@ -32,6 +40,49 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
}, },
{
"type": "SYMBOL",
"name": "tool"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "operator"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "operator"
},
{
"type": "SYMBOL",
"name": "value"
}
]
}
]
},
"value": {
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "integer" "name": "integer"
@ -48,16 +99,20 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "list" "name": "list"
}, },
{
"type": "SYMBOL",
"name": "tool"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "empty" "name": "empty"
} }
] ]
}, },
"yield": {
"type": "STRING",
"value": "->"
},
"chain": {
"type": "STRING",
"value": ";"
},
"identifier": { "identifier": {
"type": "PATTERN", "type": "PATTERN",
"value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*" "value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*"
@ -77,10 +132,6 @@
"type": "STRING", "type": "STRING",
"value": "+" "value": "+"
}, },
{
"type": "STRING",
"value": ";"
},
{ {
"type": "STRING", "type": "STRING",
"value": "/" "value": "/"

View File

@ -4,15 +4,11 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": false, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "empty", "type": "expression",
"named": true
},
{
"type": "float",
"named": true "named": true
}, },
{ {
@ -20,20 +16,16 @@
"named": true "named": true
}, },
{ {
"type": "integer", "type": "operator",
"named": true
},
{
"type": "list",
"named": true
},
{
"type": "string",
"named": true "named": true
}, },
{ {
"type": "tool", "type": "tool",
"named": true "named": true
},
{
"type": "value",
"named": true
} }
] ]
} }
@ -66,6 +58,10 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "chain",
"named": true
},
{ {
"type": "comment", "type": "comment",
"named": true "named": true
@ -75,7 +71,11 @@
"named": true "named": true
}, },
{ {
"type": "operator", "type": "value",
"named": true
},
{
"type": "yield",
"named": true "named": true
} }
] ]
@ -86,6 +86,37 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "value",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "empty",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "list",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{ {
"type": "&", "type": "&",
"named": false "named": false
@ -115,12 +146,12 @@
"named": false "named": false
}, },
{ {
"type": ";", "type": "=",
"named": false "named": false
}, },
{ {
"type": "=", "type": "chain",
"named": false "named": true
}, },
{ {
"type": "comment", "type": "comment",
@ -166,6 +197,10 @@
"type": "string", "type": "string",
"named": true "named": true
}, },
{
"type": "yield",
"named": true
},
{ {
"type": "|", "type": "|",
"named": false "named": false

File diff suppressed because it is too large Load Diff