2

Is there a way to create an LPeg pattern that always fails to match anything? I'm not talking about matching the empty string, I'm talking about a pattern that always fails so if you put it in an ordered choice it always will fall back to the second option.

The reason for this is that I am writing a small parser with LPEG and I wish I could write

 operators = empty_pattern + "==" + "~=" + "<=" + ">=" + "<" + ">"

instead of

 operators = lpeg.P("==") + "~=" + "<=" + ">=" + "<" + ">"
hugomg
  • 68,213
  • 24
  • 160
  • 246
  • On lpeg.re you can also try `(&. !.)`, which means there is a next char and there is no next char, which is always false since these two scenarios are mutually exclusive. – greatwolf Feb 14 '17 at 00:15

1 Answers1

2

lpeg.P( false ) is the simplest way.

If the argument is a boolean, the result is a pattern that always succeeds or always fails (according to the boolean value), without consuming any input.

nobody
  • 4,074
  • 1
  • 23
  • 33