aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/src/parser.lalrpop
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-12-26 00:03:07 -0800
committerbnewbold <bnewbold@robocracy.org>2016-12-26 00:03:09 -0800
commit957c2f75ceccfab3d8a8e546961db5f053876689 (patch)
tree5eae47044a720fa29b1f9396f54b7db9a482de4d /modelica-parser-lalrpop/src/parser.lalrpop
parent1e04c8274e473039d2b183c120ab7f3b1b981c3e (diff)
downloadmodelthing-957c2f75ceccfab3d8a8e546961db5f053876689.tar.gz
modelthing-957c2f75ceccfab3d8a8e546961db5f053876689.zip
radically simplify scope of parsing
Parsing arbitrary files, packages, blocks, connectors, etc caused the compilation time for this parser to explode exponentially, and resulted in huge parser.rs and executable files. This commit rips out all those features.
Diffstat (limited to 'modelica-parser-lalrpop/src/parser.lalrpop')
-rw-r--r--modelica-parser-lalrpop/src/parser.lalrpop86
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]),
};