I've just discovered the root cause of some very confusing behavior I was observing. Here is a test:
@Test
public void test2() {
Terminals terminals = Terminals.caseInsensitive(new String[] {}, new String[] { "true", "false" });
Object result = terminals.tokenizer().parse("d");
System.out.println("Result: " + result);
}
This outputs:
Result: d
I was expecting the parser returned by terminals.tokenizer() not to return anything because "d" is not a valid keyword or operator.
The reason I care is because I wanted my own parser at a lower priority than that returned by terminals.tokenizer():
public static final Parser<?> INSTANCE =
Parsers.or(
STRING_TOKENIZER,
NUMBER_TOKENIZER,
WHITESPACE_TOKENIZER,
(Parser<Token>)TERMINALS.tokenizer(),
IDENTIFIER_TOKENIZER);
The IDENTIFIER_TOKENIZER above is never used because TERMINALS.tokenizer() always matches.
Why does Terminals.tokenizer() tokenize unregistered operators/keywords? And how might I get around this?
From the documentation of
Tokenizer#caseInsensitive:Actually, the
resultreturned by your parser is aFragmentobject which is tagged according to its type. In your case,dis tagged asIDENTIFIERwhich is expected.It is not clear to me what you want to achieve though. Could you please provide a test case ?