1
0

Refine implementation

This commit is contained in:
Jeff 2024-01-23 15:46:20 -05:00
parent bdef5db051
commit 42ec57bf82
6 changed files with 13428 additions and 13848 deletions

View File

@ -19,7 +19,7 @@ pub enum ValueNode {
Option(Option<Box<Expression>>), Option(Option<Box<Expression>>),
Map(BTreeMap<String, (Statement, Option<Type>)>), Map(BTreeMap<String, (Statement, Option<Type>)>),
BuiltInValue(BuiltInValue), BuiltInValue(BuiltInValue),
StructureDefinition(BTreeMap<String, (Option<Statement>, Type)>), Structure(BTreeMap<String, (Option<Statement>, Type)>),
} }
impl AbstractTree for ValueNode { impl AbstractTree for ValueNode {
@ -160,7 +160,7 @@ impl AbstractTree for ValueNode {
} }
} }
ValueNode::StructureDefinition(btree_map) ValueNode::Structure(btree_map)
} }
_ => { _ => {
return Err(Error::UnexpectedSyntaxNode { return Err(Error::UnexpectedSyntaxNode {
@ -230,7 +230,7 @@ impl AbstractTree for ValueNode {
Value::Map(map) Value::Map(map)
} }
ValueNode::BuiltInValue(built_in_value) => built_in_value.run(source, context)?, ValueNode::BuiltInValue(built_in_value) => built_in_value.run(source, context)?,
ValueNode::StructureDefinition(node_map) => { ValueNode::Structure(node_map) => {
let mut value_map = BTreeMap::new(); let mut value_map = BTreeMap::new();
for (key, (statement_option, r#type)) in node_map { for (key, (statement_option, r#type)) in node_map {
@ -287,7 +287,7 @@ impl AbstractTree for ValueNode {
} }
ValueNode::Map(_) => Type::Map(None), ValueNode::Map(_) => Type::Map(None),
ValueNode::BuiltInValue(built_in_value) => built_in_value.expected_type(context)?, ValueNode::BuiltInValue(built_in_value) => built_in_value.expected_type(context)?,
ValueNode::StructureDefinition(node_map) => { ValueNode::Structure(node_map) => {
let mut value_map = BTreeMap::new(); let mut value_map = BTreeMap::new();
for (key, (_statement_option, r#type)) in node_map { for (key, (_statement_option, r#type)) in node_map {
@ -357,7 +357,7 @@ impl Format for ValueNode {
output.push('}'); output.push('}');
} }
ValueNode::BuiltInValue(built_in_value) => built_in_value.format(output, indent_level), ValueNode::BuiltInValue(built_in_value) => built_in_value.format(output, indent_level),
ValueNode::StructureDefinition(nodes) => { ValueNode::Structure(nodes) => {
output.push('{'); output.push('{');
for (key, (value_option, r#type)) in nodes { for (key, (value_option, r#type)) in nodes {

View File

@ -13,14 +13,13 @@ struct {
(statement (statement
(expression (expression
(value (value
(type_definition (structure
(structure (identifier)
(identifier) (type_specification
(type_specification (type))
(type)) (identifier)
(identifier) (type_specification
(type_specification (type)))))))
(type))))))))
================================================================================ ================================================================================
Complex Structure Complex Structure
@ -45,28 +44,27 @@ Foo = struct {
(statement (statement
(expression (expression
(value (value
(type_definition (structure
(structure (identifier)
(identifier) (type_specification
(type_specification (type))
(type)) (identifier)
(identifier) (type_specification
(type_specification (type))
(type)) (statement
(statement (expression
(expression (value
(value (float))))
(float)))) (identifier)
(identifier) (type_specification
(type_specification (type
(type (identifier)))
(identifier))) (statement
(statement (expression
(expression (new
(new (identifier)
(identifier) (identifier)
(identifier) (statement
(statement (expression
(expression (value
(value (integer))))))))))))))
(integer)))))))))))))))

View File

@ -85,11 +85,6 @@ module.exports = grammar({
$.map, $.map,
$.option, $.option,
$.built_in_value, $.built_in_value,
$.type_definition,
),
type_definition: $ =>
choice(
$.structure, $.structure,
), ),

View File

@ -249,15 +249,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "built_in_value" "name": "built_in_value"
}, },
{
"type": "SYMBOL",
"name": "type_definition"
}
]
},
"type_definition": {
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "structure" "name": "structure"

View File

@ -602,21 +602,6 @@
] ]
} }
}, },
{
"type": "type_definition",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "structure",
"named": true
}
]
}
},
{ {
"type": "type_specification", "type": "type_specification",
"named": true, "named": true,
@ -677,7 +662,7 @@
"named": true "named": true
}, },
{ {
"type": "type_definition", "type": "structure",
"named": true "named": true
} }
] ]

File diff suppressed because it is too large Load Diff