Skip to content

Commit

Permalink
Use Optional if LHS of the colon operator is Pattern. Passes all but …
Browse files Browse the repository at this point in the history
…4 tests!
  • Loading branch information
corywalker committed Aug 17, 2017
1 parent be84c2a commit b4cb348
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions expreduce/interp.go
Expand Up @@ -186,8 +186,6 @@ var binaryOps = map[int]string{
36: "Condition",
52: "Apply",
38: "Map",

123: "Pattern", // TODO(corywalker): Needs work
}

var fullyAssocOps = map[int]string{
Expand Down Expand Up @@ -242,6 +240,19 @@ func ParserExprConv(expr *wl.Expression) Ex {
ParserExprConv(expr.Expression),
&Symbol{"System`Null"},
)
case 123:
// TODO(corywalker): Fix parsing of "a + a_:5 + a". It should contain
// the expression Optional[a_, 5].
e := ParserExprConv(expr.Expression)
head := "System`Pattern"
if _, isPat := HeadAssertion(e, "System`Pattern"); isPat {
head = "System`Optional"
}
return NewExpression([]Ex{
&Symbol{head},
e,
ParserExprConv(expr.Expression2),
})
case 140:
return NewExpression([]Ex{
&Symbol{"System`MessageName"},
Expand Down

0 comments on commit b4cb348

Please sign in to comment.