1
0

Modify struct, enum and match syntax

This commit is contained in:
Jeff 2024-02-18 10:34:59 -05:00
parent ef12d97895
commit 979335f497
8 changed files with 32776 additions and 28711 deletions

View File

@ -90,7 +90,7 @@ impl AbstractTree for ValueNode {
ValueNode::Enum { name, variant , expression } ValueNode::Enum { name, variant , expression }
} }
"struct_instance" => { "struct_instance" => {
let name_node = child.child(1).unwrap(); let name_node = child.child(0).unwrap();
let name = Identifier::from_syntax(name_node, source, context)?; let name = Identifier::from_syntax(name_node, source, context)?;
let properties_node = child.child(2).unwrap(); let properties_node = child.child(2).unwrap();

View File

@ -9,7 +9,7 @@ fn simple_struct() {
baz <str> baz <str>
} }
new Foo { Foo::{
baz = 'hiya' baz = 'hiya'
} }
", ",
@ -37,8 +37,8 @@ fn nested_struct() {
} }
struct Bar {} struct Bar {}
new Foo { Foo::{
bar = new Bar {} bar = Bar::{}
} }
", ",
); );

View File

@ -2,12 +2,12 @@
Match Values Match Values
================================================================================ ================================================================================
match x { match x
1 => { 1 -> {
true true
} }
2 => false 2 -> false
}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -41,10 +41,10 @@ match x {
Match Enum Match Enum
================================================================================ ================================================================================
match foobar { match foobar
FooBar::Foo => true FooBar::Foo -> true
FooBar::Bar => false FooBar::Bar -> false
}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -30,7 +30,7 @@ struct Foo {
x <int> x <int>
y <float> = 0.0 y <float> = 0.0
bar <Bar> = new Bar { bar <Bar> = Bar::{
baz = 42 baz = 42
} }
} }

View File

@ -294,16 +294,14 @@ module.exports = grammar({
seq( seq(
'match', 'match',
$.expression, $.expression,
'{',
repeat1( repeat1(
seq( seq(
$.match_pattern, $.match_pattern,
'=>', '->',
$.statement, $.statement,
optional(','), optional(','),
), ),
), ),
'}',
), ),
), ),
@ -517,6 +515,6 @@ module.exports = grammar({
), ),
struct_instance: $ => struct_instance: $ =>
seq('new', $.identifier, $.map), seq($.identifier, '::', $.map),
}, },
}); });

View File

@ -872,10 +872,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}, },
{
"type": "STRING",
"value": "{"
},
{ {
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
@ -887,7 +883,7 @@
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "=>" "value": "->"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -907,10 +903,6 @@
} }
] ]
} }
},
{
"type": "STRING",
"value": "}"
} }
] ]
} }
@ -1606,14 +1598,14 @@
"struct_instance": { "struct_instance": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "STRING",
"value": "new"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
}, },
{
"type": "STRING",
"value": "::"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "map" "name": "map"

View File

@ -922,10 +922,6 @@
"type": "==", "type": "==",
"named": false "named": false
}, },
{
"type": "=>",
"named": false
},
{ {
"type": ">", "type": ">",
"named": false "named": false
@ -1046,10 +1042,6 @@
"type": "nan", "type": "nan",
"named": false "named": false
}, },
{
"type": "new",
"named": false
},
{ {
"type": "none", "type": "none",
"named": false "named": false

File diff suppressed because it is too large Load Diff