InlineLexer
extends AbstractLexer
in package
Base class for writing simple lexers, i.e. for creating small DSLs.
Tags
Table of Contents
Constants
- ANNOTATION_END = 17
- ANNOTATION_START = 16
- ANONYMOUS_END = 3
- ANONYMOUSE_REFERENCE = 12
- BACKTICK = 6
- COLON = 13
- DOUBLE_BACKTICK = 18
- EMAIL = 20
- EMPHASIS_DELIMITER = 21
- ESCAPED_SIGN = 25
- HYPERLINK = 19
- LITERAL = 5
- NAMED_REFERENCE = 11
- NBSP = 23
- OCTOTHORPE = 14
- STRONG_DELIMITER = 22
- UNDERSCORE = 2
- VARIABLE_DELIMITER = 24
- WHITESPACE = 15
- WORD = 1
Properties
- $lookahead : Token<T, V>|null
- The next token in the input.
- $token : Token<T, V>|null
- The last matched/seen token.
- $tokenPositions : array<int, int>
- Map between string position and position in token list.
Methods
- getInputUntilPosition() : string
- Retrieve the original lexer's input until a given position.
- getLiteral() : int|string
- Gets the literal for a given token.
- glimpse() : Token<T, V>|null
- Peeks at the next token, returns it and immediately resets the peek.
- isA() : bool
- Checks if given value is identical to the given token.
- isNextToken() : bool
- Checks whether a given token matches the current lookahead.
- isNextTokenAny() : bool
- Checks whether any of the given tokens matches the current lookahead.
- moveNext() : bool
- Moves to the next token in the input string.
- peek() : Token<T, V>|null
- Moves the lookahead token forward.
- reset() : void
- Resets the lexer.
- resetPeek() : void
- Resets the peek pointer to 0.
- resetPosition() : void
- Resets the lexer position on the input to the given position.
- setInput() : void
- Sets the input data to be tokenized.
- skipUntil() : void
- Tells the lexer to skip input tokens until it sees a token with the given value.
- getCatchablePatterns() : array<string|int, string>
- Lexical catchable patterns.
- getModifiers() : string
- Regex modifiers
- getNonCatchablePatterns() : array<string|int, string>
- Lexical non-catchable patterns.
- getType() : T|null
- Retrieve token type. Also processes the token value if necessary.
- scan() : void
- Scans the input string for tokens.
Constants
ANNOTATION_END
public
mixed
ANNOTATION_END
= 17
ANNOTATION_START
public
mixed
ANNOTATION_START
= 16
ANONYMOUS_END
public
mixed
ANONYMOUS_END
= 3
ANONYMOUSE_REFERENCE
public
mixed
ANONYMOUSE_REFERENCE
= 12
BACKTICK
public
mixed
BACKTICK
= 6
COLON
public
mixed
COLON
= 13
DOUBLE_BACKTICK
public
mixed
DOUBLE_BACKTICK
= 18
public
mixed
EMAIL
= 20
EMPHASIS_DELIMITER
public
mixed
EMPHASIS_DELIMITER
= 21
ESCAPED_SIGN
public
mixed
ESCAPED_SIGN
= 25
HYPERLINK
public
mixed
HYPERLINK
= 19
LITERAL
public
mixed
LITERAL
= 5
NAMED_REFERENCE
public
mixed
NAMED_REFERENCE
= 11
NBSP
public
mixed
NBSP
= 23
OCTOTHORPE
public
mixed
OCTOTHORPE
= 14
STRONG_DELIMITER
public
mixed
STRONG_DELIMITER
= 22
UNDERSCORE
public
mixed
UNDERSCORE
= 2
VARIABLE_DELIMITER
public
mixed
VARIABLE_DELIMITER
= 24
WHITESPACE
public
mixed
WHITESPACE
= 15
WORD
public
mixed
WORD
= 1
Properties
$lookahead
The next token in the input.
public
Token<T, V>|null
$lookahead
$token
The last matched/seen token.
public
Token<T, V>|null
$token
$tokenPositions
Map between string position and position in token list.
private
array<int, int>
$tokenPositions
= []
Tags
Methods
getInputUntilPosition()
Retrieve the original lexer's input until a given position.
public
getInputUntilPosition(int $position) : string
Parameters
- $position : int
Return values
stringgetLiteral()
Gets the literal for a given token.
public
getLiteral(T $token) : int|string
Parameters
- $token : T
Return values
int|stringglimpse()
Peeks at the next token, returns it and immediately resets the peek.
public
glimpse() : Token<T, V>|null
Return values
Token<T, V>|null —The next token or NULL if there are no more tokens ahead.
isA()
Checks if given value is identical to the given token.
public
isA(string $value, int|string|UnitEnum $token) : bool
Parameters
- $value : string
- $token : int|string|UnitEnum
Return values
boolisNextToken()
Checks whether a given token matches the current lookahead.
public
isNextToken(T $type) : bool
Parameters
- $type : T
Tags
Return values
boolisNextTokenAny()
Checks whether any of the given tokens matches the current lookahead.
public
isNextTokenAny(array<int, T> $types) : bool
Parameters
- $types : array<int, T>
Tags
Return values
boolmoveNext()
Moves to the next token in the input string.
public
moveNext() : bool
Tags
Return values
boolpeek()
Moves the lookahead token forward.
public
peek() : Token<T, V>|null
Return values
Token<T, V>|null —The next token or NULL if there are no more tokens ahead.
reset()
Resets the lexer.
public
reset() : void
resetPeek()
Resets the peek pointer to 0.
public
resetPeek() : void
resetPosition()
Resets the lexer position on the input to the given position.
public
resetPosition([int $position = 0 ]) : void
Parameters
- $position : int = 0
setInput()
Sets the input data to be tokenized.
public
setInput(string $input) : void
The Lexer is immediately reset and the new input tokenized. Any unprocessed tokens from any previous input are lost.
Parameters
- $input : string
-
The input to be tokenized.
skipUntil()
Tells the lexer to skip input tokens until it sees a token with the given value.
public
skipUntil(T $type) : void
Parameters
- $type : T
-
The token type to skip until.
getCatchablePatterns()
Lexical catchable patterns.
protected
getCatchablePatterns() : array<string|int, string>
Return values
array<string|int, string>getModifiers()
Regex modifiers
protected
getModifiers() : string
Return values
stringgetNonCatchablePatterns()
Lexical non-catchable patterns.
protected
getNonCatchablePatterns() : array<string|int, string>
Return values
array<string|int, string>getType()
Retrieve token type. Also processes the token value if necessary.
protected
getType(string &$value) : T|null
Parameters
- $value : string
Tags
Return values
T|nullscan()
Scans the input string for tokens.
protected
scan(string $input) : void
Parameters
- $input : string