question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion about PostLexer API

See original GitHub issue

This is a greatly simplified version of what I want to do:

from lark import Lark, Token

class SimplePostLex:
    def process(self, stream):
        for t in stream:
            return Token.new_borrow_position('B', t.value, t)
    @property
    def always_accept(self):
        return 'A',
p = Lark("""
start: B
A: "A"
%declare B
""", parser='lalr', postlex=SimplePostLex())
p.parse('A')

This does not work since the lexer does not accept A-Tokens, even though I told him to do so. It works if I include an A Token somewhere in the grammar.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MegaIngcommented, Dec 22, 2019

I don’t like always_accept as a feature of the PostLexer either. That is simply not the place it belongs. (It changes the behavior of the Lexer even though it is supposed to happen afterwards). It would be better inside the grammar.

I am not sure if I like the idea of being able to edit the ignore list:

  • First of all, it doesn’t actually fix this problem.
  • Secondly, it forces the ‘user’ to micromanage the lexer and introduces a lot of potentially bugs for the ‘user’ to watch out for. (adding unnecessary things to ignore, forgetting to remove them, adding them to early/late…)
0reactions
MegaIngcommented, Nov 24, 2020

Fixed in #708

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parser or postlex causing an error in Lark - Stack Overflow
Providing a PostLexer changes the default parser/lexer combo from earley/dynamic to earley/basic , since the dynamic parser can't handle the ...
Read more >
Topics API: developer guide
The design of the Topics API is currently under discussion as an explainer, which is only the first step in the standardization process....
Read more >
lex - When an error happens, how can I display all tokens matched ...
It's possible to collect all the tokens by writing a postlexer. Another way is to parse using the interactive parser. Mind if I...
Read more >
Notepad++ / Discussion / [READ ONLY] Open Discussion: Notepad ...
Have had no problem with it post lexer removal. Might be the interaction between the external lexer & the main program munged something...
Read more >
Guppy: trying to make parsing simple, fun, and powerful
To start discussion, I'll introduce the biggest fundamental problem ... guppy might provide an API for traversing the tree with selectors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found