Class Tokenizer
java.lang.Object
com.codename1.ui.editor.Tokenizer
- All Implemented Interfaces:
SyntaxHighlighter
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.
-
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 intToken kind: an attribute name or object property.static final intLexer state: inside a block comment that opened on a previous line.static final intLexer state: inside a CSS comment opened from a declaration block.static final intLexer state: inside a CSS declaration block.static final intLexer state: normal code.static final intLexer state: inside a backtick template string that opened on a previous line.static final intLexer state: inside a Python triple-double-quoted string.static final intLexer state: inside a Python triple-single-quoted string.static final intLexer state: inside an XML/HTML comment.static final intToken kind: a string or character literal.static final intToken kind: an XML/HTML tag or a declared type. -
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:
-
TYPE
public static final int TYPEToken kind: an XML/HTML tag or a declared type.- See Also:
-
PROPERTY
public static final int PROPERTYToken kind: an attribute name or object property.- 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:
-
STATE_XML_COMMENT
public static final int STATE_XML_COMMENTLexer state: inside an XML/HTML comment.- See Also:
-
STATE_TRIPLE_SINGLE
public static final int STATE_TRIPLE_SINGLELexer state: inside a Python triple-single-quoted string.- See Also:
-
STATE_TRIPLE_DOUBLE
public static final int STATE_TRIPLE_DOUBLELexer state: inside a Python triple-double-quoted string.- See Also:
-
STATE_CSS_DECLARATION
public static final int STATE_CSS_DECLARATIONLexer state: inside a CSS declaration block.- See Also:
-
STATE_CSS_COMMENT_DECLARATION
public static final int STATE_CSS_COMMENT_DECLARATIONLexer state: inside a CSS comment opened from a declaration block.- 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
- Specified by:
tokenizein interfaceSyntaxHighlighter
-
-