Skip to content

Commit da22c94

Browse files
committed
Accessing create value
1 parent 17b74a3 commit da22c94

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

src/main/scala/com/github/tomerghelber/mathematica/parser/MathematicaParser.scala

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
3333
private def lower: Parser[ASTNode] = terminal | ROUND_BRACKET_OPEN ~> root <~ ROUND_BRACKET_CLOSE
3434

3535
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}
3838
)
3939

4040
private val subscript: Parser[ASTNode] = rep1sep(overAndUnderscript, SUBSCRIPT) ^^
41-
(subscripts => subscripts.reduceRight((e1, e2)=>SubscriptNode(e1, e2)))
41+
(subscripts => subscripts.reduceRight(SubscriptNode.apply))
4242

4343
private val part: Parser[ASTNode] = {
4444
((underparts: Parser[ASTNode]) => underparts ~ rep1(
@@ -57,20 +57,20 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
5757
}
5858

5959
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 }
6262
)
6363

6464
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}
6767
,
6868
incrementAndDecrement
6969
)
7070

7171
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}
7474
)
7575

7676
// private def mapAndApply: Parser[ASTNode] = composition ~ ("/@" | "//@" | "@@" | "@@@") ~ composition ^^ {
@@ -81,15 +81,15 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
8181
// } | composition
8282

8383
private val factorial: Parser[ASTNode] = lastFolderRight(composition,
84-
(EXCLAMATION_MARK ~ EXCLAMATION_MARK) ^^ {_=>(e: ASTNode) => Factorial2Node(e)}
84+
(EXCLAMATION_MARK ~ EXCLAMATION_MARK) ^^ {_=>Factorial2Node.create}
8585
) ~ opt(EXCLAMATION_MARK) ^^ {
8686
case expr ~ factorialOpt => factorialOpt.map(_=>ast.FactorialNode(expr)).getOrElse(expr)
8787
}
8888

8989
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}
9393
)
9494

9595
private val derivative: Parser[ASTNode] = conjugateAndTranspose ~ rep("'") ^^ {
@@ -103,17 +103,16 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
103103

104104
private val power: Parser[ASTNode] = rep1sep(derivative, CARET) ^^ (values => values.reduceRight(PowerNode.apply))
105105

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
109108

110109
private val sqrt: Parser[ASTNode] = firstFolderRight(
111-
SQRT ^^ {_=>(e:ASTNode)=>SqrtNode(e)},
110+
SQRT ^^ {_=>SqrtNode.create},
112111
verticalArrowAndVectorOperators
113112
)
114113

115114
private val differentialD: Parser[ASTNode] = firstFolderRight(
116-
"d" ^^ {_=>(e:ASTNode)=>DifferentialDNode(e)},
115+
"d" ^^ {_=>DifferentialDNode.create},
117116
sqrt
118117
)
119118

@@ -161,10 +160,10 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
161160
// // } | integrate
162161

163162
private val plusAndMinus: Parser[ASTNode] = chainr1(times,
164-
PLUS ^^ {_=> (e1: ASTNode, e2: ASTNode) => PlusNode(e1, e2)}
163+
PLUS ^^ {_=> PlusNode.create}
165164
| 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}
168167
)
169168

170169
private val intersection: Parser[ASTNode] = rep1sep(plusAndMinus, INTERSECTION) ^^ (_.reduce(IntersectionNode.apply))
@@ -176,27 +175,27 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
176175
} | union
177176

178177
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 }
185184
)
186185

187186
// private val horizontalArrowAndVectorOperators: Parser[ASTNode] = equalities
188187
// private val diagonalArrowOperators: Parser[ASTNode] = horizontalArrowAndVectorOperators
189188

190189
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}
193192
)
194193

195194
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}
200199
)
201200

202201
// private def forallAndExists: Parser[ASTNode] = setRelationOperators ~ ("∀" | "∃" | "∄") ~ setRelationOperators ^^ {
@@ -205,7 +204,7 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
205204
// case expr1 ~ "∄" ~ expr2 => NotExistsNode(expr1, expr2)
206205
// } | setRelationOperators
207206
//
208-
private val not: Parser[ASTNode] = firstFolderRight(("!" | "¬")^^{_=>(e:ASTNode)=>NotNode(e)},
207+
private val not: Parser[ASTNode] = firstFolderRight(("!" | "¬")^^{_=>NotNode.create},
209208
setRelationOperators
210209
)
211210

@@ -242,8 +241,8 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
242241
// } | implies
243242

244243
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}
247246
)
248247

249248
private def root = rules

0 commit comments

Comments
 (0)