no-context / moo

Optimised tokenizer/lexer generator! 🐄 Uses /y for performance. Moo.
BSD 3-Clause "New" or "Revised" License
821 stars 65 forks source link

What do I do if I have two competing matchers #54

Closed juliankrispel closed 7 years ago

juliankrispel commented 7 years ago

In my case I have two competing matchers:

{
  ID: /[\w]+/,
  TEXT: /[\w][.]|[^#\n\r]+/,
}

If I have a text like this Something Hello World

For the first word ID will always win. How would I go about letting the other one win? :D

tjvr commented 7 years ago

Hello! Have you tried switching the order of the rules? Moo will try the rules in order.

juliankrispel commented 7 years ago

@tjvr yes I have. The problem is I want to mostly keep the order as it is.

Except for this case.

juliankrispel commented 7 years ago

also @tjvr thanks for getting back to me so quick :+1:

juliankrispel commented 7 years ago

I guess I'm just wondering if there's any other thing I can do besides using states and rule order for this problem...

tjvr commented 7 years ago

@juliankrispel You're welcome :-)

tjvr commented 7 years ago

You could always try using negative lookahead—see #52.

juliankrispel commented 7 years ago

VERY GOOD POINT thx <3

tjvr commented 7 years ago

Glad I could help! :-)