aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop
diff options
context:
space:
mode:
Diffstat (limited to 'modelica-parser-lalrpop')
-rw-r--r--modelica-parser-lalrpop/src/lib.rs14
-rw-r--r--modelica-parser-lalrpop/tests/ast.rs6
-rw-r--r--modelica-parser-lalrpop/tests/examples.rs.WIP29
-rw-r--r--modelica-parser-lalrpop/tests/parser.rs2
4 files changed, 45 insertions, 6 deletions
diff --git a/modelica-parser-lalrpop/src/lib.rs b/modelica-parser-lalrpop/src/lib.rs
index 0b94c35..26fca79 100644
--- a/modelica-parser-lalrpop/src/lib.rs
+++ b/modelica-parser-lalrpop/src/lib.rs
@@ -3,13 +3,23 @@ extern crate lalrpop_util;
extern crate colored;
extern crate regex;
-pub mod parser;
-pub mod ast;
+mod parser;
+mod ast;
use colored::*;
use lalrpop_util::ParseError;
use regex::Regex;
+pub use ast::*;
+pub use parser::{
+ parse_file,
+ parse_model,
+ parse_package,
+ parse_block,
+ parse_connector,
+ parse_record,
+};
+
pub fn strip_comments(raw: &str) -> String {
// TODO: shouldn't recompile regex on every function call
diff --git a/modelica-parser-lalrpop/tests/ast.rs b/modelica-parser-lalrpop/tests/ast.rs
index 24407b8..51c1014 100644
--- a/modelica-parser-lalrpop/tests/ast.rs
+++ b/modelica-parser-lalrpop/tests/ast.rs
@@ -3,7 +3,7 @@ extern crate modelica_parser;
use std::collections::HashSet;
use std::iter::FromIterator;
-use modelica_parser::ast::*;
+use modelica_parser::*;
fn set_eq(a: Vec<String>, b: Vec<String>) -> bool {
let set_a: HashSet<String> = HashSet::from_iter(a);
@@ -13,7 +13,7 @@ fn set_eq(a: Vec<String>, b: Vec<String>) -> bool {
#[test]
fn test_expr_identifiers() {
- use modelica_parser::ast::Expr::*;
+ use modelica_parser::Expr::*;
assert!(set_eq(
vec![],
@@ -37,7 +37,7 @@ fn test_expr_identifiers() {
#[test]
fn test_eqn_identifiers() {
- use modelica_parser::ast::Expr::*;
+ use modelica_parser::Expr::*;
assert!(set_eq(
vec![],
diff --git a/modelica-parser-lalrpop/tests/examples.rs.WIP b/modelica-parser-lalrpop/tests/examples.rs.WIP
new file mode 100644
index 0000000..a206ac6
--- /dev/null
+++ b/modelica-parser-lalrpop/tests/examples.rs.WIP
@@ -0,0 +1,29 @@
+
+extern crate modelica_parser;
+
+use std::io::Read;
+use std::fs::{File, read_dir};
+use std::path::Path;
+use modelica_parser::parser::parse_model;
+
+fn do_file(p: &Path) {
+ let mut s = String::new();
+ File::open(p).and_then(|mut f| f.read_to_string(&mut s)).unwrap();
+ modelica_parser::parser::parse_model(&s).unwrap();
+}
+
+#[test]
+fn test_example_files() {
+
+ let files: Vec<&Path> = read_dir(Path::new("./examples/modelica_models/"))
+ .unwrap()
+ .map(|x| x.unwrap())
+ .filter(|x| x.metadata().unwrap().is_file())
+ .filter(|x| x.path().suffix().equals(".mo"))
+ .map(|x| x.path())
+ .collect();
+
+ for p in &files {
+ do_file(p);
+ }
+}
diff --git a/modelica-parser-lalrpop/tests/parser.rs b/modelica-parser-lalrpop/tests/parser.rs
index 1a0f46f..b390e85 100644
--- a/modelica-parser-lalrpop/tests/parser.rs
+++ b/modelica-parser-lalrpop/tests/parser.rs
@@ -1,7 +1,7 @@
extern crate modelica_parser;
-use modelica_parser::parser::{parse_integer, parse_float, parse_model};
+use modelica_parser::{parse_integer, parse_float, parse_model};
#[test]
fn test_lexical() {