Snippets

Carlos Rueda ast_construction.md

Created by Carlos Rueda last modified

BTW, consider using tupled (see e.g., this) to simplify the AST construction a bit:

So, for example, used like this:

val assign = P("assign" ~ "(" ~ identifier ~ "=" ~ expression ~ ")") map Assign.tupled

Instead of:

    val assign = P("assign" ~ "(" ~ identifier ~ "=" ~ expression ~ ")") map { source =>
      val (id, expression) = source
      Assign(id, expression)
    }

The order of the case class parameters should of course be the same as that of the elements defined in the parser rule.

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.