@@ -237,13 +237,13 @@ pub IDENT: String = {
237
237
//✅ | extends IDENT [ class-modification ] description-string composition end IDENT
238
238
pub LongClassSpecifier: ast::ClassSpecifier = {
239
239
<name: IDENT>
240
- <description: DescriptionString? >
240
+ <description: DescriptionString>
241
241
<composition: Composition>
242
242
"end"
243
243
<name_end: IDENT> => {
244
244
ast::ClassSpecifier::Long {
245
245
name,
246
- description: description.unwrap_or(Vec::new()) ,
246
+ description,
247
247
composition,
248
248
name_end,
249
249
}
@@ -433,9 +433,7 @@ pub ImportClause : ast::Element = {
433
433
pub ExtendsClause: ast::Element = {
434
434
"extends"
435
435
<type_specifier: TypeSpecifier> => {
436
- ast::Element::ExtendsClause {
437
- type_specifier,
438
- }
436
+ ast::Element::ExtendsClause(type_specifier)
439
437
}
440
438
}
441
439
@@ -552,18 +550,14 @@ pub Modification: ast::Modification = {
552
550
args,
553
551
expr,
554
552
},
555
- "=" <expr: ModExpr> => ast::Modification::Expression {
556
- expr,
557
- },
553
+ "=" <expr: ModExpr> => ast::Modification::Expression(expr),
558
554
}
559
555
560
556
//✅ modification-expression :
561
557
//✅ expression
562
558
//✅ | break
563
559
pub ModExpr: ast::ModExpr = {
564
- <expr: Expression> => ast::ModExpr::Expression {
565
- expr
566
- },
560
+ <expr: Expression> => ast::ModExpr::Expression(expr),
567
561
"break" => ast::ModExpr::Break {}
568
562
}
569
563
@@ -713,8 +707,8 @@ pub Statement: ast::Statement = {
713
707
<stmt: IfStatement> => stmt,
714
708
<stmt: ForStatement> => stmt,
715
709
<stmt: WhileStatement> => stmt,
716
- "break" <description: Description> => ast::Statement::Break { description } ,
717
- "return" <description: Description> => ast::Statement::Return { description } ,
710
+ "break" <description: Description> => ast::Statement::Break( description) ,
711
+ "return" <description: Description> => ast::Statement::Return( description) ,
718
712
}
719
713
720
714
//✅ if-equation :
@@ -1002,6 +996,12 @@ MulOperator : ast::BinaryOp = {
1002
996
"./" => ast::BinaryOp::ElemDiv,
1003
997
}
1004
998
999
+ FuncKeyword: String = {
1000
+ <"der"> => String::from("der"),
1001
+ // <"initial"> => String::from("initial"),
1002
+ // <"pure"> => String::from("pure"),
1003
+ };
1004
+
1005
1005
SimpleExpression: ast::Expression = {
1006
1006
//✅ simple-expression :
1007
1007
//✅ logical-expression [ ":" logical-expression [ ":" logical-expression ] ]
@@ -1072,30 +1072,9 @@ SimpleExpression: ast::Expression = {
1072
1072
//✅ term :
1073
1073
//✅ factor { mul-operator factor }
1074
1074
#[precedence(level="4")] #[assoc(side="left")]
1075
- <lhs:SimpleExpression> "*" <rhs:SimpleExpression> => {
1076
- ast::Expression::Binary {
1077
- op: ast::BinaryOp::Mul,
1078
- lhs: Box::new(lhs),
1079
- rhs: Box::new(rhs),
1080
- }
1081
- },
1082
- <lhs:SimpleExpression> ".*" <rhs:SimpleExpression> => {
1083
- ast::Expression::Binary {
1084
- op: ast::BinaryOp::ElemMul,
1085
- lhs: Box::new(lhs),
1086
- rhs: Box::new(rhs),
1087
- }
1088
- },
1089
- <lhs:SimpleExpression> "/" <rhs:SimpleExpression> => {
1075
+ <lhs:SimpleExpression> <op: MulOperator> <rhs:SimpleExpression> => {
1090
1076
ast::Expression::Binary {
1091
- op: ast::BinaryOp::Div,
1092
- lhs: Box::new(lhs),
1093
- rhs: Box::new(rhs),
1094
- }
1095
- },
1096
- <lhs:SimpleExpression> "./" <rhs:SimpleExpression> => {
1097
- ast::Expression::Binary {
1098
- op: ast::BinaryOp::ElemDiv,
1077
+ op,
1099
1078
lhs: Box::new(lhs),
1100
1079
rhs: Box::new(rhs),
1101
1080
}
@@ -1128,13 +1107,11 @@ SimpleExpression: ast::Expression = {
1128
1107
"(" <rhs:ParenthesisExpression> ")" => {
1129
1108
ast::Expression::Unary {
1130
1109
op: ast::UnaryOp::Paren,
1131
- rhs: Box::new(rhs)
1110
+ rhs: Box::new(rhs),
1132
1111
}
1133
1112
},
1134
1113
"{" <args:SeparatedList<Expression, ",">> "}" => {
1135
- ast::Expression::ArrayArguments {
1136
- args
1137
- }
1114
+ ast::Expression::ArrayArguments (args)
1138
1115
},
1139
1116
<val:"UNSIGNED-INTEGER"> => {
1140
1117
ast::Expression::UnsignedInteger(val)
@@ -1148,15 +1125,23 @@ SimpleExpression: ast::Expression = {
1148
1125
<comp:ComponentReference> => {
1149
1126
ast::Expression::Ref(comp)
1150
1127
},
1128
+ #[precedence(level="1")]
1151
1129
<comp:ComponentReference> <args:FunctionCallArguments> => {
1152
1130
ast::Expression::FunctionCall {
1153
1131
comp,
1154
- args
1132
+ args,
1155
1133
}
1156
1134
},
1157
- "der" <args:FunctionCallArguments> => {
1158
- ast::Expression::Der {
1159
- args
1135
+ <func: FuncKeyword> <args:FunctionCallArguments> => {
1136
+ ast::Expression::FunctionCall {
1137
+ comp: ast::ComponentReference{
1138
+ local: false,
1139
+ parts: vec![ast::RefPart{
1140
+ name: func,
1141
+ array_subscripts: Vec::new()
1142
+ }]
1143
+ },
1144
+ args,
1160
1145
}
1161
1146
},
1162
1147
}
@@ -1168,26 +1153,24 @@ SimpleExpression: ast::Expression = {
1168
1153
//✅ type-specifier :
1169
1154
//✅ ["."] name
1170
1155
pub TypeSpecifier: ast::TypeSpecifier = {
1171
- <leading_period : "."?> <name: Name> => {
1156
+ <local : "."?> <name: Name> => {
1172
1157
ast::TypeSpecifier{
1173
- leading_period: leading_period .is_some(),
1158
+ local: local .is_some(),
1174
1159
name,
1175
1160
}
1176
1161
},
1177
1162
}
1163
+
1178
1164
//✅ name :
1179
1165
//✅ IDENT { "." IDENT }
1180
1166
pub Name: ast::Name = {
1181
1167
<first:IDENT> <remaining: ("." <IDENT>)*> => {
1182
1168
let mut v = vec![first];
1183
1169
v.extend(remaining);
1184
- ast::Name {
1185
- ident: v
1186
- }
1170
+ v
1187
1171
}
1188
1172
}
1189
1173
1190
-
1191
1174
//✅ component-reference :
1192
1175
//✅ [ "." ] IDENT [ array-subscripts ] { "." IDENT [ array-subscripts ] }
1193
1176
pub ComponentReference: ast::ComponentReference = {
@@ -1263,22 +1246,26 @@ pub Subscript: ast::Subscript = {
1263
1246
//✅ description :
1264
1247
//✅ description-string [ annotation-clause ]
1265
1248
pub Description: ast::Description = {
1266
- <strings: DescriptionString? >
1249
+ <strings: DescriptionString>
1267
1250
<annotation: AnnotationClause?>
1268
1251
=> {
1269
1252
ast::Description {
1270
- strings: strings.unwrap_or(Vec::new()) ,
1253
+ strings,
1271
1254
annotation: annotation.unwrap_or(Vec::new()),
1272
1255
}
1273
1256
},
1274
1257
}
1275
1258
1276
1259
//✅ description-string :
1277
1260
//✅ [ STRING { "+" STRING } ]
1278
- // Note: LALRPOP doesn't like empty expressions, so effectively
1279
- // removing outer [ ], and at least one string is required.
1280
- // Other expressions will need to treat as option.
1281
1261
pub DescriptionString: Vec<String> = {
1262
+ <s:DescriptionStringPart?> => {
1263
+ s.unwrap_or(Vec::new())
1264
+ }
1265
+ }
1266
+ // Note: LALRPOP doesn't like empty expressions here, so
1267
+ // adding level of indirection with DescriptionStringPart
1268
+ DescriptionStringPart: Vec<String> = {
1282
1269
<first:"STRING"> <remaining: ("+" <"STRING">)*> => {
1283
1270
let mut v = vec![first];
1284
1271
v.extend(remaining);
0 commit comments