From 37dba2763441721456be50f709c38bee9f6e71f9 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 18 Dec 2016 11:02:38 -0800 Subject: parser: refactor components into clauses/decl --- modelica-parser-lalrpop/src/parser.lalrpop | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'modelica-parser-lalrpop/src/parser.lalrpop') diff --git a/modelica-parser-lalrpop/src/parser.lalrpop b/modelica-parser-lalrpop/src/parser.lalrpop index cdd15b4..8df904e 100644 --- a/modelica-parser-lalrpop/src/parser.lalrpop +++ b/modelica-parser-lalrpop/src/parser.lalrpop @@ -1,12 +1,14 @@ use std::str::FromStr; -use ast::{ModelicaModel,Component, ComponentPrefix, Connection, +use ast::{ModelicaModel, ComponentDeclaration, ComponentClause, ComponentPrefix, Connection, SimpleEquation, Expr, BinOperator}; // This is an incomplete, non-standards-compliant, minimum-viable parser +// Based on the Modelica 3.3r1 Spec grammar; -// Lexical Tokens +// === Lexical Tokens === +// Roughly (but possibly not exactly) follows B.1 pub identifier: String = { r"[a-zA-Z_][a-zA-Z_0-9]*" => <>.to_string(), @@ -25,12 +27,16 @@ pub float: f64 = { r"[+-]?\d+\.\d*([eE][-+]?\d+)?" => f64::from_str(<>).unwrap(), }; +pub boolean: bool = { + "true" => true, + "false" => false, +}; // Grammar pub model: ModelicaModel = { - "model" "equation" "end" identifier ";" => - ModelicaModel { name:n, components: cd, connections: cc, equations: se, extends: vec![] }, + "model" "equation" "end" identifier ";" => + ModelicaModel { name:n, description:desc, component_clauses:cpc, connections:cc, equations:se, extends:vec![] }, }; value_declaration: Expr = { @@ -41,9 +47,14 @@ units_declaration: String = { "(" "unit" "=" ")" => units }; -component_declaration: Component = { - ";" => - Component { prefix:prefix, specifier:specifier, name:name, description:desc, value:value, units:units }, +component_clause: ComponentClause = { + ";" => + ComponentClause { prefix:prefix, specifier:specifier, declarations:declarations }, +}; + +component_declaration: ComponentDeclaration = { + (",")? => + ComponentDeclaration { name:name, description:desc, value:value, units:units }, }; component_prefix: ComponentPrefix = { @@ -57,7 +68,8 @@ component_prefix: ComponentPrefix = { }; simple_equation: SimpleEquation = { - "=" ";" => SimpleEquation {lhs:lhs, rhs:rhs}, + ":=" ";" => SimpleEquation {lhs:lhs, rhs:rhs}, + "=" ";" => SimpleEquation {lhs:lhs, rhs:rhs}, }; connect_clause: Connection = { @@ -86,6 +98,8 @@ factor: Expr = { term, }; +// TODO: elementwise operators (".+", "./", ".*", ".-") + term: Expr = { integer => Expr::Integer(<>), float => Expr::Float(<>), -- cgit v1.2.3