nearley: Unexpected token with moo lexer
I would like to use the moo lexer together with nearley, but I keep getting the error Unexpected column token for various reasons for very simple strings, such as "description contains abc".
Iβm trying to implement some kind of searching language where you can do things like username = xyz and ("full name" contains " A. " or "full name" contains " B. ").
Before moving to the moo lexer everything was working kind of nicely. Perhaps by having a look at the grammar someone knows what I am doing wrong? That would really help me π
@preprocessor typescript
@{%
const moo = require('moo');
const lexer = moo.compile({
ws: {match: /\s+/, lineBreaks: true},
connector: /and|or/, // Any difference with `connector: ['and', 'or']`?
leftParen: '(',
rightParen: ')',
field: /(?:[A-Za-z][A-Za-z0-9_]*)|(?:"[A-Za-z][A-Za-z0-9_ ]*?")/,
operator: /contains|not contains|=|<|>/,
value: /(?:[^\s()"]+)|(?:"[^\s()"]*?")/
});
%}
@lexer lexer
bexp -> bexp %ws %connector %ws bexp
bexp -> %leftParen _ bexp _ %rightParen
bexp -> pred
pred -> %field %ws %operator %ws %value
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16
Hooray! π
Iβm glad we got it sorted π
I agree there are a few things we could improve in the documentation; feel free to raise issues or PR these if you have time π
Itβs not a big deal to actually have keywords and forbid them as values. Iβm more concern about just making it work! π