-
Notifications
You must be signed in to change notification settings - Fork 67
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
Handle parsing errors in moo.states() #91
Comments
The following works fine for me: moo.states({
main: {
// throws the error instead of tokenizing it
myError: moo.error
},
}); I don't think it would make sense to allow configuring an error at the toplevel? Tokens must always be defined inside a state. |
That only works for me if I have another token type in the list; otherwise it generates the regex
I think it might. Usually lexer states are opaque to the parser and it just sees a stream of tokens, so you very rarely want a) only certain states to have error tokens or b) different states to have different names for the error token. But I don't think the syntax @moranje provided makes sense—if we go this route, we should probably have a more general notion of state inheritance and/or a special state from which other states automatically inherit; then a global error token would be as simple as a |
I agree on both accounts. Since a parsing error a 'global' failure it would make more sense to handle that in a single location rather than redoing it over and over again. Preferably there would a way itself to having access to the |
The const moo = require('moo')
const lexer = moo.states({
main: {
id: /\w+/,
err: moo.error,
},
})
lexer.reset('hello!')
lexer.next() // { type: 'id', value: 'hello', text: 'hello', offset: 0, lineBreaks: 0, line: 1, col: 1 }
lexer.next() // { type: 'err', value: '!', text: '!', offset: 5, lineBreaks: 0, line: 1, col: 6 } |
Thanks! Here's an update to the README to represent that #95. |
Nathan added support for including states in other states, and support for It still needs documentation and some tests 🙂 |
@moranje If you're interested in trying out the latest |
Great! I have limited time to spare at the moment, but am excited to try out these additions. I'll try to implement the changes somewhere this week. I'll get back to you on this, great work! |
Hi,
I'm looking for a way to get the offending in a moo states object. The following doesn't seem to work and a regular error is still thrown:
What would be the correct way to get the error or offending token in a stateful lexer?
The text was updated successfully, but these errors were encountered: