aboutsummaryrefslogtreecommitdiffstats
path: root/src/modelica_parser.lalrpop.full
diff options
context:
space:
mode:
Diffstat (limited to 'src/modelica_parser.lalrpop.full')
-rw-r--r--src/modelica_parser.lalrpop.full171
1 files changed, 171 insertions, 0 deletions
diff --git a/src/modelica_parser.lalrpop.full b/src/modelica_parser.lalrpop.full
new file mode 100644
index 0000000..d453bc7
--- /dev/null
+++ b/src/modelica_parser.lalrpop.full
@@ -0,0 +1,171 @@
+use std::str::FromStr;
+
+// Based on the Modelica 3.3r1 Spec
+
+grammar;
+
+//// B.1 Lexical Convetions
+
+//digit: = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+//q_ident = "’" ( q_char | s_escape ) { q_char | s_escape } "’"
+//nondigit = "_" | letters "a" to "z" | letters "A" to "Z"
+//s_char = any member of the Unicode character set (http://www.unicode.org; see Section 13.2.2 for storing as UTF-8 on files) except double-quote """, and backslash "\"
+//q_char = nondigit | digit | "!" | "#" | "$" | "%" | "&" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | ">" | "=" | "?" | "@" | "[" | "]" | "^" | "{" | "}" | "|" | "~" | " "
+//s_escape = "\’" | "\"" | "\?" | "\\" | "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
+//
+//ident = nondigit { digit | nondigit } | q_ident
+//string = """ { s_char | s_escape } """
+//unsigned_integer = digit { digit }
+//unsigned_number = unsigned_integer [ "." [ unsigned_integer ] ] [ ( "e" | "E" ) [ "+" | "-" ] unsigned_integer ]
+
+IDENT: () = {
+ r"[a-zA-Z_][a-zA-Z_0-9]*",
+ // TODO: quoted identifier: "’" ... "’"
+};
+
+STRING: () = {
+ //"\"" r"[^\"^\\]*" "\"",
+ "\"" r"[^\\]*" "\"", // XXX: not \ and not "
+};
+
+UNSIGNED_INTEGER: () = {
+ r"\d+",
+};
+
+UNSIGNED_NUMBER: () = {
+ UNSIGNED_INTEGER,
+ r"\d+\.?\d*([eE][-+]?\d+)?",
+};
+
+
+//// B.2 Grammar
+
+//// B.2.1
+
+//stored_definition:
+// [ within [ name ] ";" ]
+// { [ final ] class_definition ";" }
+
+//// B.2.2 Class Definition
+
+
+//// B.2.7 Expressions
+
+expression: () = {
+ simple_expression,
+ if expression then expression { elseif expression then expression } else expression
+};
+
+simple_expression: () = {
+ logical_expression [ ":" logical_expression [ ":" logical_expression ] ]
+};
+
+logical_expression: () = {
+ logical_term { or logical_term }
+};
+
+logical_term: () = {
+ logical_factor { and logical_factor }
+};
+
+logical_factor: () = {
+ [ not ] relation
+};
+
+relation: () = {
+ arithmetic_expression [ rel_op arithmetic_expression ]
+};
+
+rel_op: () = {
+ "<", "<=", ">", ">=", "==", "<>"
+};
+
+arithmetic_expression: () = {
+ [ add_op ] term { add_op term }
+};
+
+add_op: () = {
+ "+", "-", ".+", ".-"
+};
+
+term: () = {
+ factor { mul_op factor }
+};
+
+mul_op: () = {
+ "*", "/", ".*", "./"
+};
+
+factor: () = {
+ primary [ ("^" | ".^") primary ]
+};
+
+primary: () = {
+ UNSIGNED_NUMBER,
+ STRING,
+ false,
+ true,
+ ( name | der | initial ) function_call_args,
+ component_reference,
+ "(" output_expression_list ")",
+ "[" expression_list { ";" expression_list } "]",
+ "{" function_arguments "}",
+ end,
+};
+
+name: () = {
+ [ "." ] IDENT { "." IDENT }
+};
+
+component_reference: () = {
+ [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] }
+};
+
+function_call_args: () = {
+ "(" [ function_arguments ] ")",
+ function_arguments,
+ function_argument [ "," function_arguments | for for_indices ],
+ named_arguments,
+};
+
+named_arguments: () = {
+ named_argument [ "," named_arguments ]
+};
+
+named_argument:
+ IDENT "=" function_argument
+};
+
+function_argument: () = {
+ function name "(" [ named_arguments ] ")" | expression
+};
+
+
+output_expression_list:
+ [ expression ] { "," [ expression ] }
+
+expression_list: () = {
+ expression { "," expression }
+};
+
+array_subscripts: () = {
+ "[" subscript { "," subscript } "]"
+
+};
+
+subscript: () = {
+ ":" | expression
+
+};
+
+comment: () = {
+ string_comment [ annotation ]
+};
+
+string_comment: () = {
+ [ STRING { "+" STRING } ]
+};
+
+annotation: () = {
+ annotation class_modification
+};