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.

line number on rule

See original GitHub issue

What is your question?

I have a grammar like this one, for JSON:

    ?start: value

    ?value: object
            | array
            | string
            | SIGNED_NUMBER      -> number
            | "true"             -> true
            | "false"            -> false
            | "null"             -> null

    array  : "[" [value ("," value)*] "]"
    object : "{" [pair ("," pair)*] "}"
    pair   : string ":" value

    string : ESCAPED_STRING

    %import common.ESCAPED_STRING
    %import common.SIGNED_NUMBER
    %import common.WS

    %ignore WS

if I do this on a transformer:

    @staticmethod
    @lark.v_args(inline=True)
    def string(token: lark.Token) -> frozendict:
        return frozendict({
            'column': token.column,
            'item': ast.literal_eval(token),
            'line': token.line
        })

I can get line and column numbers

however, in array, or object rules the tree.meta.line (or tree.line) attributes are empty (and raise an error)

    @staticmethod
    @lark.v_args(tree=True)
    def array(tree: lark.Tree) -> frozendict:

I would like to be able to get the line number of such properties

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
MegaIngcommented, Sep 17, 2020

@erezsh Slight correction: Just having an meta attribute actually doesn’t work, it needs to be an instance of either Token or Tree. It might be worth considering to change this though to support custom AST generation with meta information.

Maybe also move everything in Token into a meta attribute.

0reactions
erezshcommented, Sep 17, 2020

You’re right. It has to subclass one of them to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NUMBER LINE RULES Flashcards - Cram.com
ON A NUMBER LINE THE NEGATIVE NUMBER CLOSES TO THE ZERO IS THE LARGEST NUMBER WICH IS -1. COMPARISON SIGNS 5>3 FIVE IS...
Read more >
Line numbers - Typography for Lawyers
In the text box, type your line numbers. Use a hard line break between each number, not a carriage return, so the whole...
Read more >
Add rules (lines) to separate text in Numbers on Mac
Select the text where you want to add a rule. In the Format sidebar, click the Text tab, then click the Layout button...
Read more >
Create a Rule to Generate a Number Pattern
Videos, solutions, worksheets, and examples to help grade 5 students learn how to create a rule to generate a number pattern, and plot...
Read more >
Line Number Definition | Law Insider
Line Number means the alpha numeric digits We allocated to You upon Your subscription to Our Services. Sample 1Sample 2Sample 3.
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