Code Monkey home page Code Monkey logo

Comments (4)

MegaIng avatar MegaIng commented on June 1, 2024 1

Yes, it parses successfully, but aliases then break or get ignored in the post processing. This has been on my radar for some time, but you are actually the first person I remember running into this issue so it's low priority.

from lark.

MegaIng avatar MegaIng commented on June 1, 2024

Nesting aliases inside of other constructs is not supported, and honestly should be throwing errors way earlier. Aliases should always be top level in a rule definition in an alternation (i.e. |). I am not even sure what you want do with all the [] pairs, but those are causing problems here.

from lark.

RossPatterson avatar RossPatterson commented on June 1, 2024

Nesting aliases inside of other constructs is not supported, and honestly should be throwing errors way earlier.

I can see why that would be (I've hand-coded parsers many times), but I should point out that the Lark documentation doesn't even imply that, and this grammar parses successfully with the grammars/lark.lark parser:

import lark

grammar = '''
start: pipesyn
pipesyn: ["any"i ("c"i ("a"i ("s"i ("e"i)? )? )? )? -> anycase]
 | [("mixed"i
 | "one"i ("s"i)?
 | "zero"i ("s"i)?) -> mask]
 | ["anyo"i ("f"i)? -> anyof]
'''

parser = lark.Lark(open("C:/Ross/Source/Pype/.venv/Lib/site-packages/lark/grammars/lark.lark"), parser="lalr")

parse_tree = parser.parse(grammar)

print(parse_tree.pretty())

yields:

start
  rule
    start
    rule_params	None
    alias
      expr
        name	pipesyn
        None
        None
      None
  rule
    pipesyn
    rule_params	None
    expansions
      alias
        expr
          maybe
            alias
              expansion
                expr
                  literal	"any"i
                  None
                  None
                expr
                  alias
                    expansion
                      expr
                        literal	"c"i
                        None
                        None
... much elided ...
      alias
        expr
          maybe
            alias
              expansion
                expr
                  literal	"anyo"i
                  None
                  None
                expr
                  alias
                    expr
                      literal	"f"i
                      None
                      None
                    None
                  ?
              anyof
          None
          None
        None

from lark.

RossPatterson avatar RossPatterson commented on June 1, 2024

Yes, it parses successfully, but aliases then break or get ignored in the post processing.

Got it.

so it's low priority.

Agreed. I'll change my use of Lark to not do this, and I'll probably work up a documentation PR to clarify the use of rule aliases.

from lark.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.