Class Tokens
java.lang.Object
org.libxmq.imp.ixml.earley.Tokens
The tokens of the Earley parser, like the terminals of yaep in the C version, see
doc/parse_ixml_fast.md.
A charset can name a huge number of code points, [L] about 130 000 and ~['a'] more than
a million, but a parse only sees the code points of its input. So only the code points
that are used get a token: a dense number 0..size()-1.
- The single character literals of the grammar, eg 'a' or #a, get their tokens first,
in grammar order, when the Grammar is built.
- A code point of the input that has no token gets the next one when the input is
scanned (Chart), in input order.
Every terminal of the grammar (Grammar.Chars) has a BitSet of the tokens it matches,
with one bit per token, not one per code point. A charset gets the tokens of the input
code points it contains (Grammar.addUsed), like the charset rules that
scan_content_fixup_charsets adds in C. The token sets are small, a few hundred bits for a
normal text, and will be used to prune the predictions of the parser: a rule need not be
predicted if none of the tokens that can start it is the next token.
The tokens are kept by the grammar between parses, like used_unicodes in C: with --lines
only the code points that are new on a line are added.
A code point is found by a two level table: the page (code point / 256), then the offset in
the page. Only the pages of used code points are allocated, so any input is fast and small,
also when the code points are far apart, eg 'a' and a tag character #e0001.
-
Method Summary
-
Method Details
-
token
public int token(int codepoint) The token of the code point.- Parameters:
codepoint- the code point, 0 to 0x10ffff- Returns:
- the token, or -1 if the code point has no token
-
code
public int code(int token) The code point of a token.- Parameters:
token- the token, 0 to size()-1- Returns:
- the code point
-
size
public int size()The number of tokens.- Returns:
- the number of tokens
-
used
The tokens whose code points have been seen in the inputs parsed so far.- Returns:
- a copy of the used tokens
-