Janet 1.17.1-e1c4fc2 Documentation
(Other Versions: 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 cfunction source
(parser/byte parser b)

Input a single byte into the parser byte stream. Returns the parser.
Community Examples

parser/clone cfunction source
(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.
Community Examples

parser/consume cfunction source
(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.
Community Examples

parser/eof cfunction source
(parser/eof parser)

Indicate that the end of file was reached to the parser. This puts the parser in the :dead state.
Community Examples

parser/error cfunction source
(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.
Community Examples

parser/flush cfunction source
(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.
Community Examples

parser/has-more cfunction source
(parser/has-more parser)

Check if the parser has more values in the value queue.
Community Examples

parser/insert cfunction source
(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.
Community Examples

parser/new cfunction source
(parser/new)

Creates and returns a new parser object. Parsers are state machines that can receive bytes, and generate a stream of values.
Community Examples

parser/produce cfunction source
(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.
Community Examples

parser/state cfunction source
(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.
Community Examples

parser/status cfunction source
(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.
Community Examples

parser/where cfunction source
(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.
Community Examples