Skip to content

extract Keyword break my grammar #2711

Closed Answered by WillLillis
Tudyx asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! I spent some a little time working on this and I think I figured it out :). I think the issue was your use of \S for word, as that seems to grab the parentheses in (apple). I used a regex for word below to match any non-whitespace character besides '(' and ')', but you could also potentially use something like word: $ => /[a-zA-Z0-9_]+/.

module.exports = grammar({
    name: 'apple',

    word: $ => $.word,

    rules: {
        log_file: $ => repeat(
            choice(
                $.apple,
                $.apple_parens,
                $.word
            )
        ),

        apple: $ => "apple",
        apple_parens: $ => seq('(', $.apple, `)`),
        word: $ => /[^\s()]+/
    

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Tudyx
Comment options

You must be logged in to vote
1 reply
@WillLillis
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants