Parsing

A parse tree can be created with any of the following functions:

parse_ebnf.parsing.parse_file(ebnf: str) → parse_ebnf.PT

Parse the file named ebnf.

parse_ebnf.parsing.parse_string(ebnf: str) → parse_ebnf.PT

Parse the EBNF string ebnf.

parse_ebnf.parsing.parse_from_function(read: Callable[[int], str]) → PT

Read input data from read and parse it.

read is assumed to be a function that returns a string of the same length as its argument. A string that is shorter than the given argument is interpreted as being close to the input’s end. An empty string as a return value is interpreted as being the end of the input.

parse_ebnf.parsing.parse_pt(read: Callable[[int], str]) → PT

The same as parse_ebnf.parse_from_function().

Parsing individual nodes is not supported.

Parsing state is kept in the following class, that is managed internally and given in case of errors:

class parse_ebnf.parsing.ParserState(read: Callable[[int], str], pt: PT)

A helper class for parsing, not meant to be used externally, only read.

Keeps track of the current line and column, line and column respectively, as well as the currently read string, c. It also has a reference to the PT it is parsing, pt, and to the read function readFunc.

Has two helper functions for reading input:

  • read

  • read_no_eof

They help by maintaining line, column and c.