Janet 1.38.0-73334f3 Documentation
(Other Versions:
1.37.1
1.36.0
1.35.0
1.34.0
1.31.0
1.29.1
1.28.0
1.27.0
1.26.0
1.25.1
1.24.0
1.23.0
1.22.0
1.21.0
1.20.0
1.19.0
1.18.1
1.17.1
1.16.1
1.15.0
1.13.1
1.12.2
1.11.1
1.10.1
1.9.1
1.8.1
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.1
)
Parser Module
Index
parser/byte parser/clone parser/consume parser/eof parser/error parser/flush parser/has-more parser/insert parser/new parser/produce parser/state parser/status parser/where
(parser/byte parser b)
Input a single byte b
into the parser byte stream. Returns the parser.
(parser/clone p)
Creates a deep clone of a parser that is identical to the input parser. This cloned parser can be used to continue parsing from a good checkpoint if parsing later fails. Returns a new parser.
(parser/consume parser bytes &opt index)
Input bytes into the parser and parse them. Will not throw errors if there is a parse error. Starts at the byte
index given by index
. Returns the number of bytes read.
(parser/eof parser)
Indicate to the parser that the end of file was reached. This puts the parser in the :dead state.
(parser/error parser)
If the parser is in the error state, returns the message associated with that error. Otherwise, returns nil.
Also flushes the parser state and parser queue, so be sure to handle everything in the queue before calling
parser/error
.
(parser/flush parser)
Clears the parser state and parse queue. Can be used to reset the parser if an error was encountered. Does not reset the line and column counter, so to begin parsing in a new context, create a new parser.
(parser/has-more parser)
Check if the parser has more values in the value queue.
(parser/insert parser value)
Insert a value into the parser. This means that the parser state can be manipulated in between chunks of bytes. This would allow a user to add extra elements to arrays and tuples, for example. Returns the parser.
(parser/new)
Creates and returns a new parser object. Parsers are state machines that can receive bytes and generate a stream of values.
(parser/produce parser &opt wrap)
Dequeue the next value in the parse queue. Will return nil if no parsed values are in the queue, otherwise will
dequeue the next value. If wrap
is truthy, will return a 1-element tuple that wraps the result. This tuple
can be used for source-mapping purposes.
(parser/state parser &opt key)
Returns a representation of the internal state of the parser. If a key is passed, only that information about the state is returned. Allowed keys are:
:delimiters - Each byte in the string represents a nested data structure. For example, if the parser state is '(["', then the parser is in the middle of parsing a string inside of square brackets inside parentheses. Can be used to augment a REPL prompt.
:frames - Each table in the array represents a 'frame' in the parser state. Frames contain information about the start of the expression being parsed as well as the type of that expression and some type-specific information.
(parser/status parser)
Gets the current status of the parser state machine. The status will be one of:
:pending - a value is being parsed.
:error - a parsing error was encountered.
:root - the parser can either read more values or safely terminate.
(parser/where parser &opt line col)
Returns the current line number and column of the parser's internal state. If line is provided, the current line number of the parser is first set to that value. If column is also provided, the current column number of the parser is also first set to that value.