Replies: 1 comment
-
Oh, it seems to be working now. So sharing the knowledge. Ultimately you need to change the order of definition of rules. module.exports = grammar({
name: 'lang',
rules: {
program: $ => choice(
$.literal,
$.identifier,
),
literal: $ => choice(kw('false'), kw('true')),
identifier: $ => token(prec('identifier', /[a-zA-Z_][0-9a-zA-Z_]*/)),
},
conflicts: $ => [],
precedences: _ => [
[
'keyword',
'identifier'
]
],
word: $ => $.identifier,
extras: $ => [/\s\n/, /\s/],
});
function kw(word) {
str = '';
for (var i = 0; i < word.length; i++) {
str += '[' + word.charAt(i).toLowerCase() + word.charAt(i).toUpperCase() + ']';
}
return token(prec('keyword', new RegExp(str)));
} It's weird, because even |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So here's my grammar:
And while parsing this simple one-word program:
true
it shows the following output:While it should show
I tried playing with
prec
and withtoken(prec(...))
- nothing helped.Beta Was this translation helpful? Give feedback.
All reactions