Class Tokenizer
java.lang.Object
com.codename1.ui.editor.Tokenizer
A small, allocation light, stateful lexer for the pure code editor. It tokenizes a single line at a time given the lexer state carried over from the previous line, and returns the state to carry into the next line. This makes rehighlighting incremental: after an edit only the changed line and any following lines whose entry state changed need to be retokenized.
Only the spans that carry color (keyword, string, comment, number) are emitted; the gaps between them are drawn in the default text color.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA colored span within a line:[start, start + length)has the given kind.static final classThe result of tokenizing one line: the colored spans and the lexer state to carry to the next line. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intToken kind: a comment.static final intToken kind: a language keyword.static final intToken kind: a numeric literal.static final intLexer state: inside a block comment that opened on a previous line.static final intLexer state: normal code.static final intLexer state: inside a backtick template string that opened on a previous line.static final intToken kind: a string or character literal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTokenizes one line.
-
Field Details
-
KEYWORD
public static final int KEYWORDToken kind: a language keyword.- See Also:
-
STRING
public static final int STRINGToken kind: a string or character literal.- See Also:
-
COMMENT
public static final int COMMENTToken kind: a comment.- See Also:
-
NUMBER
public static final int NUMBERToken kind: a numeric literal.- See Also:
-
STATE_NORMAL
public static final int STATE_NORMALLexer state: normal code.- See Also:
-
STATE_BLOCK_COMMENT
public static final int STATE_BLOCK_COMMENTLexer state: inside a block comment that opened on a previous line.- See Also:
-
STATE_TEMPLATE
public static final int STATE_TEMPLATELexer state: inside a backtick template string that opened on a previous line.- See Also:
-
-
Constructor Details
-
Tokenizer
Creates a tokenizer for the given language.
-
-
Method Details
-
tokenize
Tokenizes one line.
Parameters
-
line: the line text (without its trailing newline) -
startState: the lexer state carried from the previous line
Returns
the colored spans and exit state
-
-