aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/src/parser.lalrpop
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-12-19 00:47:20 -0800
committerbnewbold <bnewbold@robocracy.org>2016-12-19 00:47:20 -0800
commitd60554fce09f8be1bb4d96a83db49577dfbf550d (patch)
treebc45dfb807e057f1fb4d092805771fd7298f001f /modelica-parser-lalrpop/src/parser.lalrpop
parentaefce10b8f05dc52017beb1d422ce7b2b97bd6a5 (diff)
downloadmodelthing-d60554fce09f8be1bb4d96a83db49577dfbf550d.tar.gz
modelthing-d60554fce09f8be1bb4d96a83db49577dfbf550d.zip
parser: more progress
Diffstat (limited to 'modelica-parser-lalrpop/src/parser.lalrpop')
-rw-r--r--modelica-parser-lalrpop/src/parser.lalrpop48
1 files changed, 35 insertions, 13 deletions
diff --git a/modelica-parser-lalrpop/src/parser.lalrpop b/modelica-parser-lalrpop/src/parser.lalrpop
index b05ad76..442baca 100644
--- a/modelica-parser-lalrpop/src/parser.lalrpop
+++ b/modelica-parser-lalrpop/src/parser.lalrpop
@@ -1,8 +1,9 @@
use std::str::FromStr;
use std::collections::HashMap;
-use ast::{ModelicaCode, ModelicaPackage, ModelicaBlock, ModelicaConnector, ModelicaType, ModelicaModel, ComponentDeclaration,
+use ast::{ModelicaCode, ModelicaPackage, ModelicaBlock, ModelicaConnector,
+ ModelicaType, ModelicaModel, ComponentDeclaration, ModelicaRecord,
ComponentClause, ComponentPrefix, Connection, SimpleEquation, Expr,
- BinOperator, MathUnaryFunc};
+ BinOperator, MathUnaryFunc, collapse_components};
// This is an incomplete, non-standards-compliant, minimum-viable parser
// Based on the Modelica 3.3r1 Spec
@@ -16,7 +17,8 @@ grammar;
pub identifier: String = {
r"[a-zA-Z_][a-zA-Z_0-9]*" => <>.to_string(),
- r"[a-zA-Z_][a-zA-Z_0-9]*\.[a-zA-Z_0-9]*" => <>.to_string(),
+ r"[a-zA-Z_][a-zA-Z_0-9]*\.[a-zA-Z_0-9]+" => <>.to_string(),
+ r"[a-zA-Z_][a-zA-Z_0-9]*\.[a-zA-Z_0-9]+\.[a-zA-Z_0-9]" => <>.to_string(),
};
string_literal: String = {
@@ -39,13 +41,13 @@ pub boolean: bool = {
// Grammar
pub file: Vec<ModelicaCode> = {
- <chunks:modelica_code+> => chunks,
+ within_clause? <chunks:modelica_code+> => chunks,
};
pub modelica_code: ModelicaCode = {
model => ModelicaCode::Model(<>),
// TODO: class
- // TODO: record
+ record => ModelicaCode::Record(<>),
block => ModelicaCode::Block(<>),
connector => ModelicaCode::Connector(<>),
type_declaration => ModelicaCode::Type(<>),
@@ -55,6 +57,7 @@ pub modelica_code: ModelicaCode = {
pub package: ModelicaPackage = {
"package" <n:identifier> <desc:string_literal?>
+ extends_clause*
<children:modelica_code*>
"end" identifier ";" =>
ModelicaPackage {
@@ -71,7 +74,17 @@ pub connector: ModelicaConnector = {
ModelicaConnector {
name:n,
description:desc,
- component_clauses:cpc, },
+ 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 = {
@@ -85,6 +98,7 @@ type_declaration: ModelicaType = {
pub block: ModelicaBlock = {
"block" <n:identifier> <desc:string_literal?>
+ extends_clause*
<cpc:component_clause*>
<public:("public" <component_clause*>)?>
<protected:("protected" <component_clause*>)?>
@@ -95,16 +109,16 @@ pub block: ModelicaBlock = {
ModelicaBlock {
name:n,
description:desc,
- component_clauses:cpc,
- public_component_clauses: { public.unwrap_or(vec![]) },
- protected_component_clauses: { protected.unwrap_or(vec![]) },
+ components: { collapse_components(&cpc) },
+ public_components: { collapse_components(&public.unwrap_or(vec![])) },
+ protected_components: { collapse_components(&protected.unwrap_or(vec![])) },
connections:cc,
- equations:se,
- extends:vec![] },
+ equations:se },
};
pub model: ModelicaModel = {
"partial"? "model" <n:identifier> <desc:string_literal?>
+ extends_clause*
<cpc:component_clause*>
connector*
"equation"
@@ -114,10 +128,18 @@ pub model: ModelicaModel = {
ModelicaModel {
name:n,
description:desc,
- component_clauses:cpc,
+ components: { collapse_components(&cpc) },
connections:cc,
equations:se,
- extends:vec![] },
+ },
+};
+
+extends_clause: String = {
+ "extends" <identifier> ";" => <>,
+};
+
+within_clause: String = {
+ "within" <identifier> ";" => <>,
};
component_clause: ComponentClause = {