-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ben's code #1
base: master
Are you sure you want to change the base?
Ben's code #1
Conversation
…al-lab # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
|
||
// factors | ||
lazy val fact: PackratParser[Expr] = | ||
number | ||
( number | ||
| "("~>expr<~")" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this go about actually parsing the parenthetical expression? Why can you exclude something like ^^ {case "("~e~")" ⇒ (e)}
? Does your use of expr
direct the parser back up to the expression parser when a parenthetical expression is detected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things:
fact
should give back anExpr
(as specified in its result type:PackratParser[Expr]
)- The
~>
and<~
combinators throw away their left and right arguments, respectively.
So, the second rule will parse a left-paren, then parse an Expr
, then parse a right-paren. It'll result in whatever expr
results in, so we don't need a separate action to store it.
But, if we wanted to represent the fact that this expression was parenthetical, then we would add to the intermediate representation a case class for parenthetical expressions; and we would add an action to this rule to create an instance of that case class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks a bunch!
No description provided.