@@ -33,12 +33,12 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
33
33
private def lower : Parser [ASTNode ] = terminal | ROUND_BRACKET_OPEN ~> root <~ ROUND_BRACKET_CLOSE
34
34
35
35
private val overAndUnderscript : Parser [ASTNode ] = chainr1(lower,
36
- UNDERSCRIPT ^^ {_=> ( e1 : ASTNode , e2 : ASTNode ) => UnderscriptNode (e1, e2) }
37
- | OVERSCRIPT ^^ {_=> ( e1 : ASTNode , e2 : ASTNode ) => OverscriptNode (e1, e2) }
36
+ UNDERSCRIPT ^^ {_=> UnderscriptNode .create }
37
+ | OVERSCRIPT ^^ {_=> OverscriptNode .create }
38
38
)
39
39
40
40
private val subscript : Parser [ASTNode ] = rep1sep(overAndUnderscript, SUBSCRIPT ) ^^
41
- (subscripts => subscripts.reduceRight((e1, e2) => SubscriptNode (e1, e2) ))
41
+ (subscripts => subscripts.reduceRight(SubscriptNode .apply ))
42
42
43
43
private val part : Parser [ASTNode ] = {
44
44
((underparts : Parser [ASTNode ]) => underparts ~ rep1(
@@ -57,20 +57,20 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
57
57
}
58
58
59
59
private val incrementAndDecrement : Parser [ASTNode ] = lastFolderRight(part,
60
- INCREASE ^^ { _=> ( e1 : ASTNode ) => IncrementNode .apply(e1) }
61
- | DECREASE ^^ { _=> ( e1 : ASTNode ) => DecrementNode .apply(e1) }
60
+ INCREASE ^^ { _=> IncrementNode .create }
61
+ | DECREASE ^^ { _=> DecrementNode .create }
62
62
)
63
63
64
64
private val preincrementAndPredecrement : Parser [ASTNode ] = firstFolderRight(
65
- INCREASE ^^ { _=> ( e1 : ASTNode ) => PreincrementNode .apply(e1) }
66
- | DECREASE ^^ { _=> ( e1 : ASTNode ) => PredecrementNode .apply(e1) }
65
+ INCREASE ^^ { _=> PreincrementNode .create }
66
+ | DECREASE ^^ { _=> PredecrementNode .create }
67
67
,
68
68
incrementAndDecrement
69
69
)
70
70
71
71
private val composition : Parser [ASTNode ] = chainl1(preincrementAndPredecrement,
72
- COMPOSITION ^^ {_=> ( e1 : ASTNode , e2 : ASTNode ) => CompositionNode (e1,e2) }
73
- | RIGHT_COMPOSITION ^^ {_=> ( e1 : ASTNode , e2 : ASTNode ) => RightCompositionNode (e1,e2) }
72
+ COMPOSITION ^^ {_=> CompositionNode .create }
73
+ | RIGHT_COMPOSITION ^^ {_=> RightCompositionNode .create }
74
74
)
75
75
76
76
// private def mapAndApply: Parser[ASTNode] = composition ~ ("/@" | "//@" | "@@" | "@@@") ~ composition ^^ {
@@ -81,15 +81,15 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
81
81
// } | composition
82
82
83
83
private val factorial : Parser [ASTNode ] = lastFolderRight(composition,
84
- (EXCLAMATION_MARK ~ EXCLAMATION_MARK ) ^^ {_=> ( e : ASTNode ) => Factorial2Node (e) }
84
+ (EXCLAMATION_MARK ~ EXCLAMATION_MARK ) ^^ {_=> Factorial2Node .create }
85
85
) ~ opt(EXCLAMATION_MARK ) ^^ {
86
86
case expr ~ factorialOpt => factorialOpt.map(_=> ast.FactorialNode (expr)).getOrElse(expr)
87
87
}
88
88
89
89
private val conjugateAndTranspose : Parser [ASTNode ] = lastFolderRight(factorial,
90
- CONJUGATE ^^ {_=> (e : ASTNode ) => ConjugateNode (e) }
91
- | TRANSPOSE ^^ {_=> (e : ASTNode ) => TransposeNode (e) }
92
- | (CONJUGATE_TRANSPOSE | CONJUGATE_TRANSPOSE2 ) ^^ {_=> (e : ASTNode ) => ConjugateTransposeNode (e) }
90
+ CONJUGATE ^^ {_=> ConjugateNode .create }
91
+ | TRANSPOSE ^^ {_=> TransposeNode .create }
92
+ | (CONJUGATE_TRANSPOSE | CONJUGATE_TRANSPOSE2 ) ^^ {_=> ConjugateTransposeNode .create }
93
93
)
94
94
95
95
private val derivative : Parser [ASTNode ] = conjugateAndTranspose ~ rep(" '" ) ^^ {
@@ -103,17 +103,16 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
103
103
104
104
private val power : Parser [ASTNode ] = rep1sep(derivative, CARET ) ^^ (values => values.reduceRight(PowerNode .apply))
105
105
106
- private val verticalArrowAndVectorOperators : Parser [ASTNode ] = CURLY_BRACKET_OPEN ~> rep1sep(power, COMMA ) <~ CURLY_BRACKET_CLOSE ^^ {
107
- elements => ListNode (elements)
108
- } | power
106
+ private val verticalArrowAndVectorOperators : Parser [ASTNode ] =
107
+ CURLY_BRACKET_OPEN ~> rep1sep(power, COMMA ) <~ CURLY_BRACKET_CLOSE ^^ ListNode .create | power
109
108
110
109
private val sqrt : Parser [ASTNode ] = firstFolderRight(
111
- SQRT ^^ {_=> (e : ASTNode ) => SqrtNode (e) },
110
+ SQRT ^^ {_=> SqrtNode .create },
112
111
verticalArrowAndVectorOperators
113
112
)
114
113
115
114
private val differentialD : Parser [ASTNode ] = firstFolderRight(
116
- " d" ^^ {_=> (e : ASTNode ) => DifferentialDNode (e) },
115
+ " d" ^^ {_=> DifferentialDNode .create },
117
116
sqrt
118
117
)
119
118
@@ -161,10 +160,10 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
161
160
// // } | integrate
162
161
163
162
private val plusAndMinus : Parser [ASTNode ] = chainr1(times,
164
- PLUS ^^ {_=> ( e1 : ASTNode , e2 : ASTNode ) => PlusNode (e1, e2) }
163
+ PLUS ^^ {_=> PlusNode .create }
165
164
| MINUS ^^ {_=> (expr1 : ASTNode , expr2 : ASTNode ) => PlusNode (expr1, TimesNode (NumberNode (" -1" ), expr2))}
166
- | PLUS_MINUS ^^ {_=> ( expr1 : ASTNode , expr2 : ASTNode ) => PlusMinusNode (expr1, expr2) }
167
- | MINUS_PLUS ^^ {_=> ( expr1 : ASTNode , expr2 : ASTNode ) => MinusPlusNode (expr1, expr2) }
165
+ | PLUS_MINUS ^^ {_=> PlusMinusNode .create }
166
+ | MINUS_PLUS ^^ {_=> MinusPlusNode .create }
168
167
)
169
168
170
169
private val intersection : Parser [ASTNode ] = rep1sep(plusAndMinus, INTERSECTION ) ^^ (_.reduce(IntersectionNode .apply))
@@ -176,27 +175,27 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
176
175
} | union
177
176
178
177
private val equalities : Parser [ASTNode ] = chainl1(span,
179
- (" ==" | " \uF7D9 " ) ^^ { _ => ( e1 : ASTNode , e2 : ASTNode ) => EqualNode (e1, e2) }
180
- | " !=" ^^ { _ => ( e1 : ASTNode , e2 : ASTNode ) => UnequalNode (e1, e2) }
181
- | " >" ^^ { _ => ( e1 : ASTNode , e2 : ASTNode ) => GreaterNode (e1, e2) }
182
- | (" >=" | " ≥" | " ⩾" ) ^^ { _ => ( e1 : ASTNode , e2 : ASTNode ) => GreaterEqualNode (e1, e2) }
183
- | " <" ^^ { _ => ( e1 : ASTNode , e2 : ASTNode ) => LessNode (e1, e2) }
184
- | (" <=" | " ≤" | " ⩽" ) ^^ { _ => ( e1 : ASTNode , e2 : ASTNode ) => LessEqualNode (e1, e2) }
178
+ (" ==" | " \uF7D9 " ) ^^ { _ => EqualNode .create }
179
+ | " !=" ^^ { _ => UnequalNode .create }
180
+ | " >" ^^ { _ => GreaterNode .create }
181
+ | (" >=" | " ≥" | " ⩾" ) ^^ { _ => GreaterEqualNode .create }
182
+ | " <" ^^ { _ => LessNode .create }
183
+ | (" <=" | " ≤" | " ⩽" ) ^^ { _ => LessEqualNode .create }
185
184
)
186
185
187
186
// private val horizontalArrowAndVectorOperators: Parser[ASTNode] = equalities
188
187
// private val diagonalArrowOperators: Parser[ASTNode] = horizontalArrowAndVectorOperators
189
188
190
189
private val sameQ : Parser [ASTNode ] = chainl1(equalities,
191
- " ===" ^^ {_ => ( e1 : ASTNode , e2 : ASTNode ) => SameQNode (e1,e2) }
192
- | " =!=" ^^ {_ => ( e1 : ASTNode , e2 : ASTNode ) => UnSameQNode (e1,e2) }
190
+ " ===" ^^ {_ => SameQNode .create }
191
+ | " =!=" ^^ {_ => UnSameQNode .create }
193
192
)
194
193
195
194
private val setRelationOperators : Parser [ASTNode ] = chainl1(sameQ,
196
- " ∈" ^^ {_ => ( e1 : ASTNode , e2 : ASTNode ) => ElementNode (e1, e2) }
197
- | " ∉" ^^ {_ => ( e1 : ASTNode , e2 : ASTNode ) => NotElementNode (e1, e2) }
198
- | " ⊂" ^^ {_ => ( e1 : ASTNode , e2 : ASTNode ) => SubsetNode (e1, e2) }
199
- | " ⊃" ^^ {_ => ( e1 : ASTNode , e2 : ASTNode ) => SupersetNode (e1, e2) }
195
+ " ∈" ^^ {_ => ElementNode .create }
196
+ | " ∉" ^^ {_ => NotElementNode .create }
197
+ | " ⊂" ^^ {_ => SubsetNode .create }
198
+ | " ⊃" ^^ {_ => SupersetNode .create }
200
199
)
201
200
202
201
// private def forallAndExists: Parser[ASTNode] = setRelationOperators ~ ("∀" | "∃" | "∄") ~ setRelationOperators ^^ {
@@ -205,7 +204,7 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
205
204
// case expr1 ~ "∄" ~ expr2 => NotExistsNode(expr1, expr2)
206
205
// } | setRelationOperators
207
206
//
208
- private val not : Parser [ASTNode ] = firstFolderRight((" !" | " ¬" )^^ {_=> (e : ASTNode ) => NotNode (e) },
207
+ private val not : Parser [ASTNode ] = firstFolderRight((" !" | " ¬" )^^ {_=> NotNode .create },
209
208
setRelationOperators
210
209
)
211
210
@@ -242,8 +241,8 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
242
241
// } | implies
243
242
244
243
private val rules = chainl1(not,
245
- (" ->" | " \uF522 " ) ^^ {_=> ( e1 : ASTNode , e2 : ASTNode ) => RuleNode (e1, e2) }
246
- | (" :>" | " \uF51F " ) ^^ {_=> ( e1 : ASTNode , e2 : ASTNode ) => RuleDelayedNode (e1, e2) }
244
+ (" ->" | " \uF522 " ) ^^ {_=> RuleNode .create }
245
+ | (" :>" | " \uF51F " ) ^^ {_=> RuleDelayedNode .create }
247
246
)
248
247
249
248
private def root = rules
0 commit comments