Subparser feature
See original GitHub issueA 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:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@znakeeye I 've just push a prerelease nuget version 2.7.0-alpha . you can use it to test token channels if you want
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.