You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constnearley=require('nearley')constgrammar=require('./grammar.js')constparser=newnearley.Parser(nearley.Grammar.fromCompiled(grammar));parser.feed("int x = 5;")console.log(parser.results)
This is by design. Each character is being treated as its own "token," so you basically have an array of matching tokens in sequence. To concat these tokens into a string, you can use embedded javascript. For example:
# This will match an identifier such as `fn_foo2bar`
IDENTIFIER -> [a-zA-Z_] [a-zA-Z0-9_]:* {%
d => ({
type: 'identifier',
value: d[0] + d[1].join('')
})
%}
I'm not the sharpest tool in the shed, and I just picked up Nearley.
Here's what my
grammar.ne
is:Here's my
index.js
:And, for some reason, here's my output:
What's the issue? This is just a quick test by the way, I haven't decided what I want to start working on
Edit: I made a typo in the Issue.
The text was updated successfully, but these errors were encountered: