Skip to content

Flattened operator node #1429

Answered by ahlinc
oovm asked this question in Q&A
Oct 7, 2021 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

To flatten you need to use a combination of visible and hidden rules like on a bellow example that does what you need:

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

    word: $ => $.id,

    rules: {
        program: $ => repeat(seq($.expression, $._eos)),

        expression: $ => choice(
            seq("(", $._expression, ")"),
            $.id,
            $.num,
            $.arith_expr,
            alias($._cmp_expr, $.cmp_expr),               // Unhide only top level $.cmp_expr
        ),

        _expression: $ => choice(                         // Hide recursive rule
            seq("(", $._expression, ")"),
            $.id,
            $.num,
            $.arith_expr,  // 20

Replies: 2 comments 2 replies

Comment options

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

Comment options

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

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