Package cn.nukkit.nbt.snbt
Class SNBTLexer
java.lang.Object
cn.nukkit.nbt.snbt.SNBTLexer
- All Implemented Interfaces:
SNBTConstants
-
Nested Class Summary
Nested classes/interfaces inherited from interface cn.nukkit.nbt.snbt.SNBTConstants
SNBTConstants.LexicalState, SNBTConstants.TokenType
-
Constructor Summary
ConstructorDescriptionSNBTLexer
(CharSequence input) SNBTLexer
(String inputSource, Reader reader, SNBTConstants.LexicalState lexState, int line, int column) SNBTLexer
(String inputSource, CharSequence input) SNBTLexer
(String inputSource, CharSequence input, SNBTConstants.LexicalState lexState, int startingLine, int startingColumn) -
Method Summary
Modifier and TypeMethodDescriptionint
getCodePointColumnFromOffset
(int pos) int
getLineFromOffset
(int pos) getNextToken
(int offset) A lower level method to tokenize, that takes the absolute offset into the content buffer as a parametergetNextToken
(Token tok) The public method for getting the next token.getText
(int startOffset, int endOffset) void
setInputSource
(String inputSource) void
setParsedLines
(BitSet parsedLines) This is used in conjunction with having a preprocessor.void
setTabSize
(int tabSize) set the tab size used for location reportingvoid
setUnparsedLines
(BitSet unparsedLines) static String
stringFromBytes
(byte[] bytes) static String
stringFromBytes
(byte[] bytes, Charset charset) boolean
switchTo
(SNBTConstants.LexicalState lexState) Switch to specified lexical state.
-
Constructor Details
-
SNBTLexer
-
SNBTLexer
- Parameters:
inputSource
- just the naem of the input source (typically the filename) that will be used in error messages and so on.input
- the input
-
SNBTLexer
public SNBTLexer(String inputSource, CharSequence input, SNBTConstants.LexicalState lexState, int startingLine, int startingColumn) - Parameters:
inputSource
- just the name of the input source (typically the filename) that will be used in error messages and so on.input
- the inputline
- The line number at which we are starting for the purposes of location/error messages. In most normal usage, this is 1.column
- number at which we are starting for the purposes of location/error messages. In most normal usages this is 1.
-
SNBTLexer
-
SNBTLexer
-
SNBTLexer
public SNBTLexer(String inputSource, Reader reader, SNBTConstants.LexicalState lexState, int line, int column)
-
-
Method Details
-
setTabSize
public void setTabSize(int tabSize) set the tab size used for location reporting -
getInputSource
-
setInputSource
-
getNextToken
The public method for getting the next token. If the tok parameter is null, it just tokenizes starting at the internal bufferPosition Otherwise, it checks whether we have already cached the token after this one. If not, it finally goes to the NFA machinery -
getNextToken
A lower level method to tokenize, that takes the absolute offset into the content buffer as a parameter- Parameters:
offset
- where to start- Returns:
- the token that results from scanning from the given starting point
-
switchTo
Switch to specified lexical state.- Parameters:
lexState
- the lexical state to switch to- Returns:
- whether we switched (i.e. we weren't already in the desired lexical state)
-
setParsedLines
This is used in conjunction with having a preprocessor. We set which lines are actually parsed lines and the unset ones are ignored.- Parameters:
parsedLines
- a #java.util.BitSet that holds which lines are parsed (i.e. not ignored)
-
setUnparsedLines
-
getLineFromOffset
public int getLineFromOffset(int pos) - Returns:
- the line number from the absolute offset passed in as a parameter
-
getCodePointColumnFromOffset
public int getCodePointColumnFromOffset(int pos) - Returns:
- the column (1-based and in code points) from the absolute offset passed in as a parameter
-
getText
- Returns:
- the text between startOffset (inclusive) and endOffset(exclusive)
-
stringFromBytes
- Parameters:
bytes
- the raw byte arraycharset
- The encoding to use to decode the bytes. If this is null, we check for the initial byte order mark (used by Microsoft a lot seemingly) See: https://docs.microsoft.com/es-es/globalization/encoding/byte-order-markc- Returns:
- A String taking into account the encoding passed in or in the byte order mark (if it was present). And if no encoding was passed in and no byte-order mark was present, we assume the raw input is in UTF-8.
- Throws:
CharacterCodingException
-
stringFromBytes
- Throws:
CharacterCodingException
-