aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/modelica_ast.rs14
-rw-r--r--src/modelica_parser.lalrpop6
-rw-r--r--src/modelica_parser.rs72
3 files changed, 48 insertions, 44 deletions
diff --git a/src/modelica_ast.rs b/src/modelica_ast.rs
index ceca11d..68eafaf 100644
--- a/src/modelica_ast.rs
+++ b/src/modelica_ast.rs
@@ -1,7 +1,8 @@
use std::fmt::{Debug, Formatter, Error};
-pub struct Model {
+#[derive(PartialEq)]
+pub struct ModelicaModel {
pub name: String,
pub components: Vec<Component>,
pub equations: Vec<SimpleEquation>,
@@ -9,7 +10,7 @@ pub struct Model {
pub extends: Vec<String>,
}
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, PartialEq)]
pub enum ComponentPrefix {
// incomplete: eg, can be parameter and input
Flow,
@@ -21,23 +22,26 @@ pub enum ComponentPrefix {
Constant,
}
+#[derive(PartialEq)]
pub struct Component {
pub prefix: Option<ComponentPrefix>,
pub specifier: String,
pub name: String,
}
-#[derive(Clone)]
+#[derive(Clone, PartialEq)]
pub struct Connection {
pub a: String,
pub b: String,
}
+#[derive(PartialEq)]
pub struct SimpleEquation {
pub lhs: Expr,
pub rhs: Expr,
}
+#[derive(PartialEq)]
pub enum Expr {
Integer(i64),
Float(f64),
@@ -47,7 +51,7 @@ pub enum Expr {
BinExpr(BinOperator, Box<Expr>, Box<Expr>),
}
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, PartialEq)]
pub enum BinOperator {
Multiply,
Divide,
@@ -57,7 +61,7 @@ pub enum BinOperator {
//// Debug Implementations
-impl Debug for Model {
+impl Debug for ModelicaModel {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
try!(write!(fmt, "model {}\n", self.name));
for e in self.extends.iter() {
diff --git a/src/modelica_parser.lalrpop b/src/modelica_parser.lalrpop
index 52fd5eb..1b7861b 100644
--- a/src/modelica_parser.lalrpop
+++ b/src/modelica_parser.lalrpop
@@ -1,5 +1,5 @@
use std::str::FromStr;
-// XXX: use modelica_ast::{Model, Component, ComponentPrefix, Connection, SimpleEquation, Bin};
+// XXX: use modelica_ast::{ModelicaModel, Component, ComponentPrefix, Connection, SimpleEquation, Bin};
use modelica_ast::*;
// This is an incomplete, non-standards-compliant, minimum-viable parser
@@ -28,9 +28,9 @@ pub float: f64 = {
// Grammar
-pub model: Model = {
+pub model: ModelicaModel = {
"model" <n:identifier> <cd:component_declaration*> "equation" <cc:connect_clause*> <se:simple_equation*> "end" identifier ";" =>
- Model { name:n, components: cd, connections: cc, equations: se, extends: vec![] },
+ ModelicaModel { name:n, components: cd, connections: cc, equations: se, extends: vec![] },
};
component_declaration: Component = {
diff --git a/src/modelica_parser.rs b/src/modelica_parser.rs
index cc61597..6e34bc1 100644
--- a/src/modelica_parser.rs
+++ b/src/modelica_parser.rs
@@ -40,7 +40,7 @@ mod __parse__float {
Nt____float(f64),
Nt____identifier(String),
Nt____integer(i64),
- Nt____model(Model),
+ Nt____model(ModelicaModel),
Ntcomponent__declaration(Component),
Ntcomponent__declaration_2a(::std::vec::Vec<Component>),
Ntcomponent__declaration_2b(::std::vec::Vec<Component>),
@@ -54,7 +54,7 @@ mod __parse__float {
Ntfloat(f64),
Ntidentifier(String),
Ntinteger(i64),
- Ntmodel(Model),
+ Ntmodel(ModelicaModel),
Ntsimple__equation(SimpleEquation),
Ntsimple__equation_2a(::std::vec::Vec<SimpleEquation>),
Ntsimple__equation_2b(::std::vec::Vec<SimpleEquation>),
@@ -1547,7 +1547,7 @@ mod __parse__float {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Nt____model(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -1687,7 +1687,7 @@ mod __parse__float {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Ntmodel(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -1794,7 +1794,7 @@ mod __parse__identifier {
Nt____float(f64),
Nt____identifier(String),
Nt____integer(i64),
- Nt____model(Model),
+ Nt____model(ModelicaModel),
Ntcomponent__declaration(Component),
Ntcomponent__declaration_2a(::std::vec::Vec<Component>),
Ntcomponent__declaration_2b(::std::vec::Vec<Component>),
@@ -1808,7 +1808,7 @@ mod __parse__identifier {
Ntfloat(f64),
Ntidentifier(String),
Ntinteger(i64),
- Ntmodel(Model),
+ Ntmodel(ModelicaModel),
Ntsimple__equation(SimpleEquation),
Ntsimple__equation_2a(::std::vec::Vec<SimpleEquation>),
Ntsimple__equation_2b(::std::vec::Vec<SimpleEquation>),
@@ -3301,7 +3301,7 @@ mod __parse__identifier {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Nt____model(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -3441,7 +3441,7 @@ mod __parse__identifier {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Ntmodel(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -3548,7 +3548,7 @@ mod __parse__integer {
Nt____float(f64),
Nt____identifier(String),
Nt____integer(i64),
- Nt____model(Model),
+ Nt____model(ModelicaModel),
Ntcomponent__declaration(Component),
Ntcomponent__declaration_2a(::std::vec::Vec<Component>),
Ntcomponent__declaration_2b(::std::vec::Vec<Component>),
@@ -3562,7 +3562,7 @@ mod __parse__integer {
Ntfloat(f64),
Ntidentifier(String),
Ntinteger(i64),
- Ntmodel(Model),
+ Ntmodel(ModelicaModel),
Ntsimple__equation(SimpleEquation),
Ntsimple__equation_2a(::std::vec::Vec<SimpleEquation>),
Ntsimple__equation_2b(::std::vec::Vec<SimpleEquation>),
@@ -5055,7 +5055,7 @@ mod __parse__integer {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Nt____model(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -5195,7 +5195,7 @@ mod __parse__integer {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Ntmodel(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -5302,7 +5302,7 @@ mod __parse__model {
Nt____float(f64),
Nt____identifier(String),
Nt____integer(i64),
- Nt____model(Model),
+ Nt____model(ModelicaModel),
Ntcomponent__declaration(Component),
Ntcomponent__declaration_2a(::std::vec::Vec<Component>),
Ntcomponent__declaration_2b(::std::vec::Vec<Component>),
@@ -5316,7 +5316,7 @@ mod __parse__model {
Ntfloat(f64),
Ntidentifier(String),
Ntinteger(i64),
- Ntmodel(Model),
+ Ntmodel(ModelicaModel),
Ntsimple__equation(SimpleEquation),
Ntsimple__equation_2a(::std::vec::Vec<SimpleEquation>),
Ntsimple__equation_2b(::std::vec::Vec<SimpleEquation>),
@@ -16836,7 +16836,7 @@ mod __parse__model {
'input,
>(
input: &'input str,
- ) -> Result<Model, __lalrpop_util::ParseError<usize,(usize, &'input str),()>>
+ ) -> Result<ModelicaModel, __lalrpop_util::ParseError<usize,(usize, &'input str),()>>
{
let mut __tokens = super::__intern_token::__Matcher::new(input);
let mut __states = vec![0_i32];
@@ -17035,7 +17035,7 @@ mod __parse__model {
__lookahead_start: Option<&usize>,
__states: &mut ::std::vec::Vec<i32>,
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>,
- ) -> Option<Result<Model,__lalrpop_util::ParseError<usize,(usize, &'input str),()>>>
+ ) -> Option<Result<ModelicaModel,__lalrpop_util::ParseError<usize,(usize, &'input str),()>>>
{
let __nonterminal = match -__action {
1 => {
@@ -18149,7 +18149,7 @@ mod __parse__model {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Nt____model(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -18289,7 +18289,7 @@ mod __parse__model {
'input,
>(
__symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>
- ) -> (usize, Model, usize) {
+ ) -> (usize, ModelicaModel, usize) {
match __symbols.pop().unwrap() {
(__l, __Symbol::Ntmodel(__v), __r) => (__l, __v, __r),
_ => panic!("symbol type mismatch")
@@ -23439,8 +23439,8 @@ pub fn __action3<
'input,
>(
input: &'input str,
- (_, __0, _): (usize, Model, usize),
-) -> Model
+ (_, __0, _): (usize, ModelicaModel, usize),
+) -> ModelicaModel
{
(__0)
}
@@ -23503,9 +23503,9 @@ pub fn __action8<
(_, _, _): (usize, &'input str, usize),
(_, _, _): (usize, String, usize),
(_, _, _): (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
- Model { name:n, components: cd, connections: cc, equations: se, extends: vec![] }
+ ModelicaModel { name:n, components: cd, connections: cc, equations: se, extends: vec![] }
}
#[allow(unused_variables)]
@@ -24018,7 +24018,7 @@ pub fn __action50<
__5: (usize, &'input str, usize),
__6: (usize, String, usize),
__7: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __1.2.clone();
let __end0 = __2.0.clone();
@@ -24056,7 +24056,7 @@ pub fn __action51<
__6: (usize, &'input str, usize),
__7: (usize, String, usize),
__8: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __2.0.clone();
let __end0 = __2.2.clone();
@@ -24215,7 +24215,7 @@ pub fn __action56<
__4: (usize, &'input str, usize),
__5: (usize, String, usize),
__6: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __2.2.clone();
let __end0 = __3.0.clone();
@@ -24251,7 +24251,7 @@ pub fn __action57<
__5: (usize, &'input str, usize),
__6: (usize, String, usize),
__7: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __3.0.clone();
let __end0 = __3.2.clone();
@@ -24286,7 +24286,7 @@ pub fn __action58<
__5: (usize, &'input str, usize),
__6: (usize, String, usize),
__7: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __3.2.clone();
let __end0 = __4.0.clone();
@@ -24324,7 +24324,7 @@ pub fn __action59<
__6: (usize, &'input str, usize),
__7: (usize, String, usize),
__8: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __4.0.clone();
let __end0 = __4.2.clone();
@@ -24358,7 +24358,7 @@ pub fn __action60<
__3: (usize, &'input str, usize),
__4: (usize, String, usize),
__5: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __2.2.clone();
let __end0 = __3.0.clone();
@@ -24392,7 +24392,7 @@ pub fn __action61<
__4: (usize, &'input str, usize),
__5: (usize, String, usize),
__6: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __3.0.clone();
let __end0 = __3.2.clone();
@@ -24425,7 +24425,7 @@ pub fn __action62<
__4: (usize, &'input str, usize),
__5: (usize, String, usize),
__6: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __3.2.clone();
let __end0 = __4.0.clone();
@@ -24461,7 +24461,7 @@ pub fn __action63<
__5: (usize, &'input str, usize),
__6: (usize, String, usize),
__7: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __4.0.clone();
let __end0 = __4.2.clone();
@@ -24495,7 +24495,7 @@ pub fn __action64<
__4: (usize, &'input str, usize),
__5: (usize, String, usize),
__6: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __3.2.clone();
let __end0 = __4.0.clone();
@@ -24531,7 +24531,7 @@ pub fn __action65<
__5: (usize, &'input str, usize),
__6: (usize, String, usize),
__7: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __4.0.clone();
let __end0 = __4.2.clone();
@@ -24566,7 +24566,7 @@ pub fn __action66<
__5: (usize, &'input str, usize),
__6: (usize, String, usize),
__7: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __4.2.clone();
let __end0 = __5.0.clone();
@@ -24604,7 +24604,7 @@ pub fn __action67<
__6: (usize, &'input str, usize),
__7: (usize, String, usize),
__8: (usize, &'input str, usize),
-) -> Model
+) -> ModelicaModel
{
let __start0 = __5.0.clone();
let __end0 = __5.2.clone();