Lexicon { @Private Object word(String name) { Object p = words.apply(name); Checks.checkArgument(p != null, "token %s unavailable", name); return p; } Lexicon(Function<String, Object> words, Parser<?> tokenizer); Parser<?> tokenizer(); Parser<?> phrase(String... tokenNames); Parser<Token> token(String... tokenNames); Parser<Token> token(String tokenName);  }
@Test public void testWord() { Parser<?> tokenizer = Terminals.CharLiteral.SINGLE_QUOTE_TOKENIZER; Lexicon lexicon = new Lexicon(__ -> "foo", tokenizer); assertSame(tokenizer, lexicon.tokenizer); assertEquals("foo", lexicon.word("whatever")); }
@Test public void testWord_throwsForNullValue() { Parser<?> tokenizer = Terminals.CharLiteral.SINGLE_QUOTE_TOKENIZER; Lexicon lexicon = new Lexicon(__ -> null, tokenizer); assertSame(tokenizer, lexicon.tokenizer); try { lexicon.word("whatever"); fail(); } catch (IllegalArgumentException e) {} }