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.

Subparser feature

See original GitHub issue

A interresting feature would be to be able to compose parsers using special attributes in production rules:

 public enum EToken
    {
        [Lexeme(GenericToken.Identifier, IdentifierType.AlphaNumeric)]
        ID = 1,
        
        [Lexeme(GenericToken.Int)]
        INT = 2
    }

    public class Parser
    {
        [Production("main : ID subRuleParser INT")]
        public object Main(Token<EToken> id, object subParsed, Token<EToken> integer)
        {
            // do something here
            return null;
        }
        
        // declare use of SubParserType class as a subParser
        [Production("subRuleParser : SubParser(SubParserType) ")]
        public object subParsed(object value)
        {
            return value;
        }
    }

    public class SubParserType
    {
        [Production("submain : ID ")] // root rule
        public object SubMain(Token<EToken> id)
        {
            return id.Value;
        }        
    }

All the parsers constituing the global parser mus have the exact same type (Parser<ETOken,object> in above exemple) Instead of defining a dedicated rule for subparser it could be defined inside the production rule

[Production("main : ID subRuleParser[SubParser(SubParserType) INT")]
        public object Main(Token<EToken> id, object subParsed, Token<EToken> integer)
        {
            // do something here
            return null;
        }

this notation is terser but first one allow reuse if necessary (bot could exist at the same time)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
b3b00commented, Nov 30, 2020

@znakeeye I 've just push a prerelease nuget version 2.7.0-alpha . you can use it to test token channels if you want

0reactions
b3b00commented, Jan 25, 2021

hello @znakeeye , No I did not merge it to dev branch. I am still thinking of the real value of the feature compared to the added complexity.

you still can give it a try cloning my repo and using branch experiment/islands

I am quiet affraid by the documentation work needed to clearly explain channels and islands. these are not classic parsing concept but more antlr specifics.

i would greatly appreciate help for it if your still interested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

argparse — Parser for command-line options, arguments ...
The integers attribute will be a list of one or more integers, and the accumulate attribute will be either the sum() function, if...
Read more >
python - argparse subparsers with functions
1 Answer 1 · This throws the error AttributeError: 'Namespace' object has no attribute 'func' at the line args.func(args) if the program is...
Read more >
How To Use Python Argparse Subparser?
The Python argparse subparsers allows us to create command-line interfaces with multiple subcommands in a convenient way.
Read more >
Example of argparse with subparsers for python
Question though - command_line is defined in the function arguments? I'm unsure how this actually works so I'm going to write as I...
Read more >
argparse: how to get command name for subparsers
Dest argument. I found that add_subparsers function accepts ' dest ' argument, and that argument contains the selected subparser: subparsers = parser ...
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