aboutsummaryrefslogtreecommitdiffstats
path: root/src/modelica_parser.lalrpop.full
blob: d453bc7759743b62549c5cff006a2adff2e84ea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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
};