Skip to content

Commit 5924cb8

Browse files
committed
Given different names for create values.
1 parent da22c94 commit 5924cb8

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/main/scala/com/github/tomerghelber/mathematica/ast/ASTNode.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ case class SpanNode(expr1: ASTNode, expr3: ASTNode, expr2: ASTNode) extends ASTN
5252

5353
trait ApplyUnaryFunctionNode {
5454
protected def name: String
55-
def apply(node: ASTNode): FunctionNode = create(node)
56-
val create: ASTNode => FunctionNode = first => FunctionNode(SymbolNode(name), Seq(first))
55+
def apply(node: ASTNode): FunctionNode = createUnary(node)
56+
val createUnary: ASTNode => FunctionNode = first => FunctionNode(SymbolNode(name), Seq(first))
5757
}
5858
trait ApplyBinaryFunctionNode {
5959
protected def name: String
60-
def apply(first: ASTNode, second: ASTNode): FunctionNode = create(first, second)
61-
val create: (ASTNode, ASTNode) => FunctionNode = (first, second) => FunctionNode(SymbolNode(name), Seq(first, second))
60+
def apply(first: ASTNode, second: ASTNode): FunctionNode = createBinary(first, second)
61+
val createBinary: (ASTNode, ASTNode) => FunctionNode = (first, second) => FunctionNode(SymbolNode(name), Seq(first, second))
6262
}
6363
trait ApplyManyFunctionNode {
6464
protected def name: String
65-
def apply(nodes: Seq[ASTNode]): FunctionNode = create(nodes)
66-
val create: Seq[ASTNode] => FunctionNode = nodes => FunctionNode(SymbolNode(name), nodes)
65+
def apply(nodes: Seq[ASTNode]): FunctionNode = createMany(nodes)
66+
val createMany: Seq[ASTNode] => FunctionNode = nodes => FunctionNode(SymbolNode(name), nodes)
6767
}
6868
trait UnapplyFunctionNode {
6969
protected def name: String

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ 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 ^^ {_=>UnderscriptNode.create}
37-
| OVERSCRIPT ^^ {_=>OverscriptNode.create}
36+
UNDERSCRIPT ^^ {_=>UnderscriptNode.createBinary}
37+
| OVERSCRIPT ^^ {_=>OverscriptNode.createBinary}
3838
)
3939

4040
private val subscript: Parser[ASTNode] = rep1sep(overAndUnderscript, SUBSCRIPT) ^^
@@ -57,20 +57,20 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
5757
}
5858

5959
private val incrementAndDecrement: Parser[ASTNode] = lastFolderRight(part,
60-
INCREASE ^^ { _=>IncrementNode.create }
61-
| DECREASE ^^ { _=>DecrementNode.create }
60+
INCREASE ^^ { _=>IncrementNode.createUnary }
61+
| DECREASE ^^ { _=>DecrementNode.createUnary }
6262
)
6363

6464
private val preincrementAndPredecrement: Parser[ASTNode] = firstFolderRight(
65-
INCREASE ^^ { _=>PreincrementNode.create}
66-
| DECREASE ^^ { _=>PredecrementNode.create}
65+
INCREASE ^^ { _=>PreincrementNode.createUnary}
66+
| DECREASE ^^ { _=>PredecrementNode.createUnary}
6767
,
6868
incrementAndDecrement
6969
)
7070

7171
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}
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) ^^ {_=>Factorial2Node.create}
84+
(EXCLAMATION_MARK ~ EXCLAMATION_MARK) ^^ {_=>Factorial2Node.createUnary}
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 ^^ {_=>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}
9393
)
9494

9595
private val derivative: Parser[ASTNode] = conjugateAndTranspose ~ rep("'") ^^ {
@@ -104,15 +104,15 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
104104
private val power: Parser[ASTNode] = rep1sep(derivative, CARET) ^^ (values => values.reduceRight(PowerNode.apply))
105105

106106
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
108108

109109
private val sqrt: Parser[ASTNode] = firstFolderRight(
110-
SQRT ^^ {_=>SqrtNode.create},
110+
SQRT ^^ {_=>SqrtNode.createUnary},
111111
verticalArrowAndVectorOperators
112112
)
113113

114114
private val differentialD: Parser[ASTNode] = firstFolderRight(
115-
"d" ^^ {_=>DifferentialDNode.create},
115+
"d" ^^ {_=>DifferentialDNode.createUnary},
116116
sqrt
117117
)
118118

@@ -160,10 +160,10 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
160160
// // } | integrate
161161

162162
private val plusAndMinus: Parser[ASTNode] = chainr1(times,
163-
PLUS ^^ {_=> PlusNode.create}
163+
PLUS ^^ {_=> PlusNode.createBinary}
164164
| 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}
167167
)
168168

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

177177
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 }
184184
)
185185

186186
// private val horizontalArrowAndVectorOperators: Parser[ASTNode] = equalities
187187
// private val diagonalArrowOperators: Parser[ASTNode] = horizontalArrowAndVectorOperators
188188

189189
private val sameQ: Parser[ASTNode] = chainl1(equalities,
190-
"===" ^^ {_ => SameQNode.create}
191-
| "=!=" ^^ {_ => UnSameQNode.create}
190+
"===" ^^ {_ => SameQNode.createBinary}
191+
| "=!=" ^^ {_ => UnSameQNode.createBinary}
192192
)
193193

194194
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}
199199
)
200200

201201
// private def forallAndExists: Parser[ASTNode] = setRelationOperators ~ ("∀" | "∃" | "∄") ~ setRelationOperators ^^ {
@@ -204,7 +204,7 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
204204
// case expr1 ~ "∄" ~ expr2 => NotExistsNode(expr1, expr2)
205205
// } | setRelationOperators
206206
//
207-
private val not: Parser[ASTNode] = firstFolderRight(("!" | "¬")^^{_=>NotNode.create},
207+
private val not: Parser[ASTNode] = firstFolderRight(("!" | "¬")^^{_=>NotNode.createUnary},
208208
setRelationOperators
209209
)
210210

@@ -241,8 +241,8 @@ class MathematicaParser extends StdTokenParsers with ParserUtil with LazyLogging
241241
// } | implies
242242

243243
private val rules = chainl1(not,
244-
("->" | "\uF522") ^^ {_=>RuleNode.create}
245-
| (":>" | "\uF51F") ^^ {_=>RuleDelayedNode.create}
244+
("->" | "\uF522") ^^ {_=>RuleNode.createBinary}
245+
| (":>" | "\uF51F") ^^ {_=>RuleDelayedNode.createBinary}
246246
)
247247

248248
private def root = rules

0 commit comments

Comments
 (0)