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
I just started using nearley for a React side project. I would like to input text into an input field, and log the parse results:
constparser=newnearley.Parser(nearley.Grammar.fromCompiled(grammar));
...
const[value,setValue]=useState('');constonChange=({target: { value }})=>{setValue(value);try{parser.feed(value);console.log(parser.results);}catch(e){// error handling}};return<inputvalue={value}onChange={onChange}/>
Obviously it won't work - I understand nearley is a streaming parser - an input 'abc' from the user input will equivalently feeding 'aababc' to parser.
There is a hack that always creating new instance of the parser inside the onChange function but its not I wanted.
FYI, parser.finish() does not work.
Is there a way to reset parser or any other workaround for this case?
Thank you very much!
The text was updated successfully, but these errors were encountered:
constparser=newnearley.Parser(nearley.Grammar.fromCompiled(grammar))constinitialState=parser.save()...parser.feed(value)// do something with the parsed resultparser.restore(initialState)// restore (or reset) parser to its initial state
Hello,
I just started using nearley for a React side project. I would like to input text into an input field, and log the parse results:
Obviously it won't work - I understand nearley is a streaming parser - an input
'abc'
from the user input will equivalently feeding'aababc'
to parser.There is a hack that always creating new instance of the parser inside the onChange function but its not I wanted.
FYI,
parser.finish()
does not work.Is there a way to reset parser or any other workaround for this case?
Thank you very much!
The text was updated successfully, but these errors were encountered: