diff options
Diffstat (limited to 'modelica-parser-lalrpop/src/parser.lalrpop')
-rw-r--r-- | modelica-parser-lalrpop/src/parser.lalrpop | 86 |
1 files changed, 1 insertions, 85 deletions
diff --git a/modelica-parser-lalrpop/src/parser.lalrpop b/modelica-parser-lalrpop/src/parser.lalrpop index 442baca..94795c6 100644 --- a/modelica-parser-lalrpop/src/parser.lalrpop +++ b/modelica-parser-lalrpop/src/parser.lalrpop @@ -1,7 +1,6 @@ use std::str::FromStr; use std::collections::HashMap; -use ast::{ModelicaCode, ModelicaPackage, ModelicaBlock, ModelicaConnector, - ModelicaType, ModelicaModel, ComponentDeclaration, ModelicaRecord, +use ast::{ModelicaModel, ComponentDeclaration, ComponentClause, ComponentPrefix, Connection, SimpleEquation, Expr, BinOperator, MathUnaryFunc, collapse_components}; @@ -40,87 +39,10 @@ pub boolean: bool = { // Grammar -pub file: Vec<ModelicaCode> = { - within_clause? <chunks:modelica_code+> => chunks, -}; - -pub modelica_code: ModelicaCode = { - model => ModelicaCode::Model(<>), - // TODO: class - record => ModelicaCode::Record(<>), - block => ModelicaCode::Block(<>), - connector => ModelicaCode::Connector(<>), - type_declaration => ModelicaCode::Type(<>), - package => ModelicaCode::Package(<>), - // TODO: function -}; - -pub package: ModelicaPackage = { - "package" <n:identifier> <desc:string_literal?> - extends_clause* - <children:modelica_code*> - "end" identifier ";" => - ModelicaPackage { - name:n, - description:desc, - children:children, - }, -}; - -pub connector: ModelicaConnector = { - "connector" <n:identifier> <desc:string_literal?> - <cpc:component_clause*> - "end" identifier ";" => - ModelicaConnector { - name:n, - description:desc, - components: { collapse_components(&cpc) } }, -}; - -pub record: ModelicaRecord = { - "record" <n:identifier> <desc:string_literal?> - <cpc:component_clause*> - "end" identifier ";" => - ModelicaRecord { - name:n, - description:desc, - components: { collapse_components(&cpc) } }, -}; - -type_declaration: ModelicaType = { - "type" <n:identifier> <desc:string_literal?> - "=" <cpd:component_declaration> ";" => - ModelicaType { - name:n, - description:desc, - component:cpd, }, -}; - -pub block: ModelicaBlock = { - "block" <n:identifier> <desc:string_literal?> - extends_clause* - <cpc:component_clause*> - <public:("public" <component_clause*>)?> - <protected:("protected" <component_clause*>)?> - "equation" - <cc:connect_clause*> - <se:simple_equation*> - "end" identifier ";" => - ModelicaBlock { - name:n, - description:desc, - components: { collapse_components(&cpc) }, - public_components: { collapse_components(&public.unwrap_or(vec![])) }, - protected_components: { collapse_components(&protected.unwrap_or(vec![])) }, - connections:cc, - equations:se }, -}; - pub model: ModelicaModel = { "partial"? "model" <n:identifier> <desc:string_literal?> extends_clause* <cpc:component_clause*> - connector* "equation" <cc:connect_clause*> <se:simple_equation*> @@ -268,11 +190,5 @@ term: Expr = { "log" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Log, Box::new(e)), "log10" "(" <e:expr> ")" => Expr::MathUnaryExpr(MathUnaryFunc::Log10, Box::new(e)), "(" <e:expr> ")" => e, - // Obviously a hack here, only supporting up to 4 elements in an array - "[" <e:expr> "]" => Expr::Array(vec![e]), - "[" <e1:expr> ";" <e2:expr> "]" => Expr::Array(vec![e1, e2]), - "[" <e1:expr> "," <e2:expr> "]" => Expr::Array(vec![e1, e2]), - "[" <e1:expr> "," <e2:expr> "," <e3:expr> "]" => Expr::Array(vec![e1, e2, e3]), - "[" <e1:expr> "," <e2:expr> "," <e3:expr> "," <e4:expr> "]" => Expr::Array(vec![e1, e2, e3, e4]), }; |