I have a grammar where I want to have some whitespace (including newlines) in between two terms. There should be some whitespace, i.e. it should fail if the two terms are touching, however there can be as much whitespace as desired. The issue I'm coming across is that whitespace and newlines are different tokens. I can't work out how to generally make "at least one" in nearley.
If you are using moo.js
, than you can predefine whitespace with regular expressions.
@{%
const moo = require('moo')
let lexer = moo.compile({
space: {match: /\s+/, lineBreaks: true}
// other rules
});
%}
@lexer lexer
_ -> null | %space {% d => null %} // any amount of white space or none
__ -> %space {% d => " " %} // at least one white space token