Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toAST incorrectly makes some nodes intermediate nodes #463

Open
rrthomas opened this issue Nov 6, 2023 · 0 comments
Open

toAST incorrectly makes some nodes intermediate nodes #463

rrthomas opened this issue Nov 6, 2023 · 0 comments

Comments

@rrthomas
Copy link

rrthomas commented Nov 6, 2023

Using Ohm 17.1.0, and the following grammar:

Demo {
  Sequence = ListOf<Exp, ";">

  PrimaryExp = number

  UnaryExp
    = "~" UnaryExp    -- bitwise_not
    | PrimaryExp

  Exp = UnaryExp

  number
    = digit* "." digit+  -- fract
    | digit+             -- whole
}

I run the following code:

import {toAST} from 'ohm-js/extras'

// eslint-disable-next-line import/extensions
import grammar from './demo.ohm-bundle.js'

const matchResult = grammar.match('2')
console.dir(toAST(matchResult))

const matchResult2 = grammar.match('~2')
console.dir(toAST(matchResult2))

and the output is:

[ '2' ]
[ '2' ]

In other words, there's no difference between the ASTs for ~2 and for 2.

It looks to me as though Ohm is first discarding the node for the literal string "~", and then incorrectly deciding that the rule UnaryExp_bitwise_not has only one node, and hence considering it an intermediate node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant