This commit is contained in:
Jeff 2023-09-25 09:00:27 -04:00
commit 07bd2dbdfa
5 changed files with 1069 additions and 1067 deletions

View File

@ -4,15 +4,13 @@ Comments
# x = 1; # x = 1;
# unassigned_variable # unassigned_variable
x # xyz #xyz
--- ---
(source_file (source
(comment) (comment)
(comment) (comment)
(expression
(identifier))
(comment)) (comment))
================== ==================
@ -28,19 +26,13 @@ x.x
--- ---
(source_file (source
(expression (identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)) (identifier))
(expression
(identifier))
(expression
(identifier))
(expression
(identifier))
(expression
(identifier))
(expression
(identifier)))
================== ==================
Operators Operators
@ -50,56 +42,58 @@ x = y + y;
--- ---
(source_file (source
(expression
(identifier) (identifier)
(operator) (operator)
(expression
(identifier) (identifier)
(operator) (operator)
(expression (identifier)
(identifier)))) (operator))
(chain))
================== ==================
String String
================== ==================
"string" "string"
'string'
--- ---
(source_file (source
(expression
(value (value
(string)))) (string))
(value
(string)))
================== ==================
Integer Integer
================== ==================
1 1
123
--- ---
(source_file (source
(expression
(value (value
(integer)))) (integer))
(value
(integer)))
================== ==================
Float Float
================== ==================
1.0 1.0
123.123
--- ---
(source_file (source
(expression
(value (value
(float)))) (float))
(value
(float)))
================== ==================
List List
@ -109,16 +103,13 @@ List
--- ---
(source_file (source
(expression
(value (value
(list (list
(expression
(value (value
(integer))) (integer))
(expression
(value (value
(integer))))))) (integer)))))
================== ==================
Empty Empty
@ -128,10 +119,9 @@ Empty
--- ---
(source_file (source
(expression
(value (value
(empty)))) (empty)))
================== ==================
Tool Tool
@ -141,13 +131,11 @@ random_boolean();
--- ---
(source_file (source
(expression (tool)
(tool))
(expression
(value (value
(empty))) (empty))
(chain)) (operator))
================== ==================
Boolean Boolean
@ -157,26 +145,8 @@ true false
--- ---
(source_file (source
(expression (value
(boolean))
(value (value
(boolean))) (boolean)))
(expression
(value
(boolean))))
==================
Function
==================
{ output "hi" }
---
(source_file
(expression
(value
(boolean)))
(expression
(value
(boolean))))

View File

@ -2,19 +2,17 @@ module.exports = grammar({
name: 'dust', name: 'dust',
rules: { rules: {
source_file: $ => repeat(choice( source: $ => repeat(choice(
$.comment, $.comment,
$.expression, $.identifier,
$.yield, $.value,
$.chain $.tool,
$.operator,
)), )),
expression: $ => choice( comment: $ => seq('#', /.*/),
prec(2, $.value),
prec(1, $.identifier), identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
$.tool,
seq($.identifier, $.operator, $.expression),
),
value: $ => choice( value: $ => choice(
$.integer, $.integer,
@ -23,23 +21,7 @@ module.exports = grammar({
$.list, $.list,
$.empty, $.empty,
$.boolean, $.boolean,
), $.function,
comment: $ => /(#)(.+?)([\n\r])/,
yield: $ => "->",
chain: $ => ";",
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
operator: $ => choice(
'=',
'-',
'+',
'/',
'|',
'&'
), ),
tool: $ => choice( tool: $ => choice(
@ -47,20 +29,27 @@ module.exports = grammar({
"random_boolean", "random_boolean",
"random_integer", "random_integer",
"random_string", "random_string",
"random_float" "random_float",
),
operator: $ => choice(
'=',
'-',
'+',
'/',
'|',
'&',
';',
"->",
), ),
float: $ => /\d+\.\d*/, float: $ => /\d+\.\d*/,
integer: $ => /\d+/, integer: $ => /\d+/,
string: $ => seq( string: $ => /("|')(.*?)("|')/,
'"',
repeat(),
'"'
),
function: $ => /\{(.*?)\}/, function: $ => /{(.*?)}/,
empty: $ => "()", empty: $ => "()",
@ -71,7 +60,7 @@ module.exports = grammar({
list: $ => seq( list: $ => seq(
'(', '(',
repeat1(seq($.expression, optional(','))), repeat1(seq($.value, optional(','))),
')' ')'
), ),
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "dust", "name": "dust",
"rules": { "rules": {
"source_file": { "source": {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",
@ -12,60 +12,39 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "identifier"
}, },
{ {
"type": "SYMBOL",
"name": "yield"
},
{
"type": "SYMBOL",
"name": "chain"
}
]
}
},
"expression": {
"type": "CHOICE",
"members": [
{
"type": "PREC",
"value": 2,
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "value" "name": "value"
}
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "tool" "name": "tool"
}, },
{ {
"type": "SYMBOL",
"name": "operator"
}
]
}
},
"comment": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "STRING",
"name": "identifier" "value": "#"
}, },
{ {
"type": "SYMBOL", "type": "PATTERN",
"name": "operator" "value": ".*"
}
]
}, },
{ "identifier": {
"type": "SYMBOL", "type": "PATTERN",
"name": "expression" "value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*"
}
]
}
]
}, },
"value": { "value": {
"type": "CHOICE", "type": "CHOICE",
@ -93,51 +72,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "boolean" "name": "boolean"
}
]
},
"comment": {
"type": "PATTERN",
"value": "(#)(.+?)([\\n\\r])"
},
"yield": {
"type": "STRING",
"value": "->"
},
"chain": {
"type": "STRING",
"value": ";"
},
"identifier": {
"type": "PATTERN",
"value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*"
},
"operator": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
}, },
{ {
"type": "STRING", "type": "SYMBOL",
"value": "-" "name": "function"
},
{
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "|"
},
{
"type": "STRING",
"value": "&"
} }
] ]
}, },
@ -166,6 +104,43 @@
} }
] ]
}, },
"operator": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "|"
},
{
"type": "STRING",
"value": "&"
},
{
"type": "STRING",
"value": ";"
},
{
"type": "STRING",
"value": "->"
}
]
},
"float": { "float": {
"type": "PATTERN", "type": "PATTERN",
"value": "\\d+\\.\\d*" "value": "\\d+\\.\\d*"
@ -176,11 +151,11 @@
}, },
"string": { "string": {
"type": "PATTERN", "type": "PATTERN",
"value": "\"(.*?)\\\"" "value": "(\"|')(.*?)(\"|')"
}, },
"function": { "function": {
"type": "PATTERN", "type": "PATTERN",
"value": "'(.*?)\\'" "value": "{(.*?)}"
}, },
"empty": { "empty": {
"type": "STRING", "type": "STRING",
@ -213,7 +188,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "value"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",

View File

@ -5,7 +5,12 @@
"fields": {} "fields": {}
}, },
{ {
"type": "expression", "type": "comment",
"named": true,
"fields": {}
},
{
"type": "list",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
@ -13,7 +18,27 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "expression", "type": "value",
"named": true
}
]
}
},
{
"type": "operator",
"named": true,
"fields": {}
},
{
"type": "source",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "comment",
"named": true "named": true
}, },
{ {
@ -35,53 +60,6 @@
] ]
} }
}, },
{
"type": "list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
},
{
"type": "operator",
"named": true,
"fields": {}
},
{
"type": "source_file",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "chain",
"named": true
},
{
"type": "comment",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "yield",
"named": true
}
]
}
},
{ {
"type": "tool", "type": "tool",
"named": true, "named": true,
@ -107,6 +85,10 @@
"type": "float", "type": "float",
"named": true "named": true
}, },
{
"type": "function",
"named": true
},
{ {
"type": "integer", "type": "integer",
"named": true "named": true
@ -122,6 +104,10 @@
] ]
} }
}, },
{
"type": "#",
"named": false
},
{ {
"type": "&", "type": "&",
"named": false "named": false
@ -146,22 +132,22 @@
"type": "-", "type": "-",
"named": false "named": false
}, },
{
"type": "->",
"named": false
},
{ {
"type": "/", "type": "/",
"named": false "named": false
}, },
{
"type": ";",
"named": false
},
{ {
"type": "=", "type": "=",
"named": false "named": false
}, },
{
"type": "chain",
"named": true
},
{
"type": "comment",
"named": true
},
{ {
"type": "empty", "type": "empty",
"named": true "named": true
@ -174,6 +160,10 @@
"type": "float", "type": "float",
"named": true "named": true
}, },
{
"type": "function",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -210,10 +200,6 @@
"type": "true", "type": "true",
"named": false "named": false
}, },
{
"type": "yield",
"named": true
},
{ {
"type": "|", "type": "|",
"named": false "named": false

File diff suppressed because it is too large Load Diff