Terminals extends Lexicon { static TokenMap<String> fromFragment(final Object... tags) { return new TokenMap<String>() { @Override public String map(final Token token) { final Object val = token.value(); if (val instanceof Fragment) { Fragment c = (Fragment) val; if (!Objects.in(c.tag(), tags)) return null; return c.text(); } else return null; } @Override public String toString() { if (tags.length == 0) return ""; if (tags.length == 1) return String.valueOf(tags[0]); return "[" + Strings.join(", ", tags) + "]"; } }; } private  Terminals(Lexicon lexicon); @Deprecated static Terminals caseInsensitive(String[] ops, String[] keywords); @Deprecated static Terminals caseSensitive(String[] ops, String[] keywords); @Deprecated static Terminals caseInsensitive(
      Parser<String> wordScanner, String[] ops, String[] keywords); @Deprecated static Terminals caseSensitive(
      Parser<String> wordScanner, String[] ops, String[] keywords); @Deprecated static Terminals caseInsensitive(
      Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap); @Deprecated static Terminals caseSensitive(
      Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap); static Terminals operators(String... ops); static Terminals operators(Collection<String> ops); Builder words(Parser<String> wordScanner); static Parser<String> identifier(); static Parser<String> fragment(final Object... tags); static final Parser<String> RESERVED; }
@Test public void testFromFragment() { assertEquals("", Terminals.fromFragment().toString()); assertEquals("1", Terminals.fromFragment(1).toString()); TokenMap<String> fromToken = Terminals.fromFragment("foo", 1); assertEquals("[foo, 1]", fromToken.toString()); assertEquals("test", fromToken.map(new Token(0, 3, Tokens.fragment("test", "foo")))); assertEquals("test", fromToken.map(new Token(0, 3, Tokens.fragment("test", 1)))); assertNull(fromToken.map(new Token(0, 3, Tokens.fragment("test", "bar")))); assertNull(fromToken.map(new Token(0, 3, Tokens.fragment("test", 2)))); }