Skip to content

Simplified punctuated rules #187

@kant2002

Description

@kant2002

Is your feature request related to a problem? Please describe.

When working with punctuated list, I usually don't interested in the separator. Most of the time, simple list would be enough. Also capturing separator require memory allocation for their storage, which usually unnecessary.

Describe the solution you'd like
I propose that punctuated rules, can match with two types.

[Rule("name_list : Lparen (Identifier (',' Identifier)*)? Rparen")]
private static List<string> NameList(
    IToken<TokenType> _lp,
    Punctuated<IToken<TokenType>, IToken<TokenType>> elements,
    IToken<TokenType> _rp) => elements.Values.Select(t => t.Text).ToList();

and to list types.

[Rule("name_list : Lparen (Identifier (',' Identifier)*)? Rparen")]
private static List<string> NameList(
    IToken<TokenType> _lp,
    IReadOnlyList<IToken<TokenType>> elements,
    IToken<TokenType> _rp) => elements.Values.Select(t => t.Text).ToList();

Describe alternatives you've considered

I think maybe #77 can work as well, but I believe this is much simpler to implement without too much generalizations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions