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