Add new tests and grammar

This commit is contained in:
Jeff 2023-08-24 09:31:26 -04:00
parent 10086fcf59
commit 3aa005530f
5 changed files with 948 additions and 523 deletions

View File

@ -46,40 +46,20 @@ x.x
Operators Operators
================== ==================
x = y x = y + y;
x + y
x | y
x - y
x / y
x ; y
--- ---
(source_file (source_file
(expression (expression
(identifier)
(operator)
(identifier)) (identifier))
(operator)
(expression (expression
(identifier)
(operator)
(identifier)) (identifier))
(operator)
(expression (expression
(identifier)
(operator)
(identifier)) (identifier))
(expression (operator))
(identifier)
(operator)
(identifier))
(expression
(identifier)
(operator)
(identifier))
(expression
(identifier)
(operator)
(identifier)))
================== ==================
String String
@ -105,6 +85,19 @@ Integer
(expression (expression
(integer))) (integer)))
==================
Float
==================
1.0
---
(source_file
(expression
(float)))
================== ==================
List List
================== ==================
@ -121,5 +114,31 @@ List
(expression (expression
(integer))))) (integer)))))
==================
Empty
==================
()
---
(source_file
(expression
(empty)))
==================
Tool
==================
random_boolean();
---
(source_file
(expression
(tool))
(expression
(empty))
(operator))

View File

@ -2,17 +2,18 @@ module.exports = grammar({
name: 'dust', name: 'dust',
rules: { rules: {
source_file: $ => repeat(choice($.comment, $.expression)), source_file: $ => repeat(choice($.comment, $.expression, $.operator)),
comment: $ => /(#)(.+?)([\n\r])/, comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice( expression: $ => choice(
$.identifier, $.identifier,
$.integer, $.integer,
$.float,
$.string, $.string,
$.list, $.list,
$.macro, $.tool,
seq($.identifier, $.operator, $.identifier) $.empty,
), ),
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/, identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
@ -27,21 +28,28 @@ module.exports = grammar({
'&' '&'
), ),
integer: $ => /\d/, tool: $ => choice(
"random",
"random_boolean",
"random_integer",
"random_string",
"random_float"
),
float: $ => /\d+\.\d*/,
integer: $ => /\d+/,
string: $ => /"(.*?)\"/, string: $ => /"(.*?)\"/,
function: $ => /'(.*?)\'/, function: $ => /'(.*?)\'/,
empty: $ => "()",
list: $ => seq( list: $ => seq(
'(', '(',
repeat1(seq($.expression, optional(','))), repeat1(seq($.expression, optional(','))),
')' ')'
), ),
macro: $ => choice(
"assert",
"assert_equal"
)
} }
}); });

View File

@ -13,6 +13,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
},
{
"type": "SYMBOL",
"name": "operator"
} }
] ]
} }
@ -32,6 +36,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "integer" "name": "integer"
}, },
{
"type": "SYMBOL",
"name": "float"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "string" "name": "string"
@ -42,24 +50,11 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "macro" "name": "tool"
}, },
{ {
"type": "SEQ", "type": "SYMBOL",
"members": [ "name": "empty"
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "operator"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
} }
] ]
}, },
@ -100,9 +95,38 @@
} }
] ]
}, },
"tool": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "random"
},
{
"type": "STRING",
"value": "random_boolean"
},
{
"type": "STRING",
"value": "random_integer"
},
{
"type": "STRING",
"value": "random_string"
},
{
"type": "STRING",
"value": "random_float"
}
]
},
"float": {
"type": "PATTERN",
"value": "\\d+\\.\\d*"
},
"integer": { "integer": {
"type": "PATTERN", "type": "PATTERN",
"value": "\\d" "value": "\\d+"
}, },
"string": { "string": {
"type": "PATTERN", "type": "PATTERN",
@ -112,6 +136,10 @@
"type": "PATTERN", "type": "PATTERN",
"value": "'(.*?)\\'" "value": "'(.*?)\\'"
}, },
"empty": {
"type": "STRING",
"value": "()"
},
"list": { "list": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -148,19 +176,6 @@
"value": ")" "value": ")"
} }
] ]
},
"macro": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "assert"
},
{
"type": "STRING",
"value": "assert_equal"
}
]
} }
}, },
"extras": [ "extras": [

View File

@ -4,9 +4,17 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "empty",
"named": true
},
{
"type": "float",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -19,17 +27,13 @@
"type": "list", "type": "list",
"named": true "named": true
}, },
{
"type": "macro",
"named": true
},
{
"type": "operator",
"named": true
},
{ {
"type": "string", "type": "string",
"named": true "named": true
},
{
"type": "tool",
"named": true
} }
] ]
} }
@ -49,11 +53,6 @@
] ]
} }
}, },
{
"type": "macro",
"named": true,
"fields": {}
},
{ {
"type": "operator", "type": "operator",
"named": true, "named": true,
@ -74,10 +73,19 @@
{ {
"type": "expression", "type": "expression",
"named": true "named": true
},
{
"type": "operator",
"named": true
} }
] ]
} }
}, },
{
"type": "tool",
"named": true,
"fields": {}
},
{ {
"type": "&", "type": "&",
"named": false "named": false
@ -114,18 +122,18 @@
"type": "=", "type": "=",
"named": false "named": false
}, },
{
"type": "assert",
"named": false
},
{
"type": "assert_equal",
"named": false
},
{ {
"type": "comment", "type": "comment",
"named": true "named": true
}, },
{
"type": "empty",
"named": true
},
{
"type": "float",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -134,6 +142,26 @@
"type": "integer", "type": "integer",
"named": true "named": true
}, },
{
"type": "random",
"named": false
},
{
"type": "random_boolean",
"named": false
},
{
"type": "random_float",
"named": false
},
{
"type": "random_integer",
"named": false
},
{
"type": "random_string",
"named": false
},
{ {
"type": "string", "type": "string",
"named": true "named": true

File diff suppressed because it is too large Load Diff