Skip to content
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

Rule Syntax overhaul #48

Open
keddelzz opened this issue Mar 29, 2017 · 0 comments
Open

Rule Syntax overhaul #48

keddelzz opened this issue Mar 29, 2017 · 0 comments
Milestone

Comments

@keddelzz
Copy link
Contributor

keddelzz commented Mar 29, 2017

  • Allow ^^ in Rule1[_] on token (see here) so that I can write NUMBER ^^ (_.toInt).
  • Allow a single token as right hand side of a rule (see here), so that I don't have to explicitly call singletonRule.
  • Infer better type for regular operations on Rule1[_]
    • optional (?) (see here), so that I get the type def Optional: Rule[Option[String] :: HNil] = NUMBER ?.
    • positive closure (+) (see here), so that I get the type def Optional: Rule[(String :: HNil) :: Option[String :: HNil] :: HNil] = NUMBER +.
    • kleene (see here), so that I get the type def Optional: Rule[List[String :: HNil] :: HNil] = NUMBER *.
  • Infer scanner- and parser-rule-types to make the definition of a grammar easier
    @grammar
    class TestParser {
      import scala.language.postfixOps
    
      val digit : RegExp = regex("[0-9]")
      val number: RegExp = digit *
    
      val NUMBER: Token = token(number)
    
      @start def S = NUMBER
    
    }

The example above triggers the error: 'TestParser.this.NUMBER' is not a token!, because the implicit conversion from Token -> Rule1[String] doesn't trigger and thus the macro doesn't accept the parse-rule definition. Explicitly annotating the rule S with the type Rule1[String] will get rid of the error. A smarter grammar analysis could trigger the implicit conversion manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant