Module toml.parser stdlib

toml.parser
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
6
Imported by:
1
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imported by

  • Standard Library

Aliases

This section is empty.

Constants

#constant all_formatting

all_formatting            = [token.Kind.whitespace, .tab, .cr, .nl]

#constant space_formatting

space_formatting          = [token.Kind.whitespace, .tab]

#constant keys_and_space_formatting

keys_and_space_formatting = [token.Kind.whitespace, .tab, .minus, .bare, .quoted, .boolean,
	.number, .underscore]

Sum types

This section is empty.

Functions

This section is empty.

Structs

#struct Parser

pub struct Parser {
pub:
	config Config
mut:
	scanner   &scanner.Scanner = unsafe { nil }
	prev_tok  token.Token
	tok       token.Token
	peek_tok  token.Token
	tokens    []token.Token // To be able to peek more than one token ahead.
	skip_next bool
	// The root map (map is called table in TOML world)
	root_map                          map[string]ast.Value
	root_map_key                      DottedKey
	explicit_declared                 []DottedKey
	explicit_declared_array_of_tables []DottedKey
	implicit_declared                 []DottedKey
	// Array of Tables state
	last_aot       DottedKey
	last_aot_index int
	// Root of the tree
	ast_root &ast.Root = &ast.Root{}
}

Parser contains the necessary fields for keeping the state of the parsing process.

#fn new_parser

fn new_parser(config Config) Parser

new_parser returns a new, stack allocated, Parser.

#fn (&Parser) init

fn (mut p &Parser) init() !

init initializes the parser.

#fn (&Parser) run_checker

fn (mut p &Parser) run_checker() !

run_checker validates the parsed ast.Value nodes in the the generated AST.

#fn (&Parser) run_decoder

fn (mut p &Parser) run_decoder() !

run_decoder decodes values in the parsed ast.Value nodes in the the generated AST.

#fn (&Parser) parse

fn (mut p &Parser) parse() !&toml.ast.Root

parse starts parsing the input and returns the root of the generated AST.

#fn (&Parser) next

fn (mut p &Parser) next() !

next forwards the parser to the next token.

#fn (&Parser) peek

fn (mut p &Parser) peek(n int) !toml.token.Token

peek peeks forward n tokens.

peek returns .unknown if it can not peek ahead long enough.

#fn (&Parser) check

fn (mut p &Parser) check(check_token toml.token.Kind) !

check forwards the parser to the next token if the current token's Kind is equal that of check_token.

#fn (&Parser) peek_for_correct_line_ending_or_fail

fn (mut p &Parser) peek_for_correct_line_ending_or_fail() !

peek_for_correct_line_ending_or_fail peeks past any formatting tokens and return an error if the next token is not one of [.cr, .nl, .hash, .eof].

#fn (&Parser) check_one_of

fn (mut p &Parser) check_one_of(tokens []toml.token.Kind) !

check_one_of forwards the parser to the next token if the current token's Kind can be found in tokens. Otherwise it returns an error.

#fn (&Parser) ignore_while

fn (mut p &Parser) ignore_while(tokens []toml.token.Kind)

ignore_while forwards the parser to the next token as long as the current token's Kind can be found in tokens. This is helpful for ignoring a stream of formatting tokens.

#fn (&Parser) ignore_while_peek

fn (mut p &Parser) ignore_while_peek(tokens []toml.token.Kind)

ignore_while_peek forwards the parser to the next token as long as peek_tok token's Kind can be found in tokens. This is helpful for ignoring a stream of formatting tokens.

In contrast to ignore_while, ignore_while_peek compares on peek_tok this is sometimes necessary since not all parser calls forward using the next call.

#fn (&Parser) peek_over

fn (mut p &Parser) peek_over(i int, tokens []toml.token.Kind) !(toml.token.Token, int)

peek_over peeks ahead from token starting at i skipping over any token.Kinds found in tokens. peek_over returns the next token not found in tokens.

#fn (&Parser) is_at

fn (mut p &Parser) is_at(expected_token toml.token.Kind) bool

is_at returns true if the token kind is equal to expected_token.

#fn (&Parser) expect

fn (mut p &Parser) expect(expected_token toml.token.Kind) !

expect will error if the token kind is not equal to expected_token.

#fn (&Parser) build_abs_dotted_key

fn (p &Parser) build_abs_dotted_key(key DottedKey) DottedKey

build_abs_dotted_key returns the absolute dotted key path.

#fn (&Parser) check_explicitly_declared

fn (p &Parser) check_explicitly_declared(key DottedKey) !

check_explicitly_declared returns an error if key has been explicitly declared.

#fn (&Parser) check_explicitly_declared_array_of_tables

fn (p &Parser) check_explicitly_declared_array_of_tables(key DottedKey) !

check_explicitly_declared_array_of_tables returns an error if key has been explicitly declared as an array of tables.

#fn (&Parser) check_implicitly_declared

fn (p &Parser) check_implicitly_declared(key DottedKey) !

check_implicitly_declared returns an error if key has been implicitly declared.

#fn (&Parser) find_table

fn (mut p &Parser) find_table() !&map[string]toml.ast.Value

find_table returns a reference to a map if found in the root table given a "dotted" key (a.b.c).

If some segments of the key does not exist in the root table find_table will allocate a new map for each segment. This behavior is needed because you can reference maps by multiple keys "dotted" (separated by "." periods) in TOML documents.

See also find_in_table.

#fn (&Parser) allocate_table

fn (mut p &Parser) allocate_table(key DottedKey) !

allocate_table allocates all tables in "dotted" key (a.b.c) in the root table.

#fn (&Parser) sub_table_key

fn (mut p &Parser) sub_table_key(key DottedKey) (DottedKey, DottedKey)

sub_table_key returns the logic parts of a dotted key (a.b.c) for use with the find_sub_table method.

#fn (&Parser) find_sub_table

fn (mut p &Parser) find_sub_table(key DottedKey) !&map[string]toml.ast.Value

find_sub_table returns a reference to a map if found in the root table given a "dotted" key (a.b.c).

If some segments of the key does not exist in the input map find_sub_table will allocate a new map for the segment. This behavior is needed because you can reference maps by multiple keys "dotted" (separated by "." periods) in TOML documents.

See also find_in_table.

#fn (&Parser) find_in_table

fn (mut p &Parser) find_in_table(mut table &map[string]toml.ast.Value, key DottedKey) !&map[string]toml.ast.Value

find_in_table returns a reference to a map if found in table given a "dotted" key (a.b.c).

If some segments of the key does not exist in the input map find_in_table will allocate a new map for the segment. This behavior is needed because you can reference maps by multiple keys "dotted" (separated by "." periods) in TOML documents.

#fn (&Parser) find_array_of_tables

fn (mut p &Parser) find_array_of_tables() ![]toml.ast.Value

find_array_of_tables returns an array if found in the root table based on the parser's last encountered "Array Of Tables" key.

If the state key does not exist find_array_in_table will return an error.

#fn (&Parser) allocate_in_table

fn (mut p &Parser) allocate_in_table(mut table &map[string]toml.ast.Value, key DottedKey) !

allocate_in_table allocates all tables in "dotted" key (a.b.c) in table.

#fn (&Parser) dotted_key

fn (mut p &Parser) dotted_key() !DottedKey

dotted_key returns a string of the next tokens parsed as sub/nested/path keys (e.g. a.b.c). In TOML, this form of key is referred to as a "dotted" key.

#fn (&Parser) root_table

fn (mut p &Parser) root_table() !

root_table parses next tokens into the root map of ast.Values.

The V map type is corresponding to a "table" in TOML.

#fn (&Parser) excerpt

fn (p &Parser) excerpt() string

excerpt returns a string of the characters surrounding Parser.tok.pos

#fn (&Parser) table_contents

fn (mut p &Parser) table_contents(mut tbl &map[string]toml.ast.Value) !

table_contents parses next tokens into a map of ast.Values.

The V map type is corresponding to a "table" in TOML.

#fn (&Parser) inline_table

fn (mut p &Parser) inline_table(mut tbl &map[string]toml.ast.Value) !

inline_table parses next tokens into a map of ast.Values.

The V map type is corresponding to a "table" in TOML.

#fn (&Parser) array_of_tables

autofree_bugmanualfree
fn (mut p &Parser) array_of_tables(mut table &map[string]toml.ast.Value) !

array_of_tables parses next tokens into an array of ast.Values.

#fn (&Parser) array_of_tables_contents

fn (mut p &Parser) array_of_tables_contents() ![]toml.ast.Value

array_of_tables_contents parses next tokens into an array of ast.Values.

#fn (&Parser) double_array_of_tables

autofree_bugmanualfree
fn (mut p &Parser) double_array_of_tables(mut table &map[string]toml.ast.Value) !

double_array_of_tables parses next tokens into an array of tables of arrays of ast.Values...

#fn (&Parser) double_array_of_tables_contents

fn (mut p &Parser) double_array_of_tables_contents(target_key DottedKey) ![]toml.ast.Value

double_array_of_tables_contents parses next tokens into an array of ast.Values.

#fn (&Parser) array

fn (mut p &Parser) array() ![]toml.ast.Value

array parses next tokens into an array of ast.Values.

#fn (&Parser) comment

fn (mut p &Parser) comment() toml.ast.Comment

comment returns an ast.Comment type.

#fn (&Parser) key

fn (mut p &Parser) key() !toml.ast.Key

key parse and returns an ast.Key type.

Keys are the token(s) appearing before an assignment operator (=).

#fn (&Parser) key_value

fn (mut p &Parser) key_value() !(toml.ast.Key, toml.ast.Value)

key_value parse and returns a pair ast.Key and ast.Value type.

see also key and value

#fn (&Parser) dotted_key_value

fn (mut p &Parser) dotted_key_value() !(DottedKey, toml.ast.Value)

dotted_key_value parse and returns a pair DottedKey and ast.Value type.

see also key and value

#fn (&Parser) value

fn (mut p &Parser) value() !toml.ast.Value

value parse and returns an ast.Value type.

values are the token(s) appearing after an assignment operator (=).

#fn (&Parser) number_or_date

fn (mut p &Parser) number_or_date() !toml.ast.Value

number_or_date parse and returns an ast.Value type as one of [ast.Date, ast.Time, ast.DateTime, ast.Number]

#fn (&Parser) bare

fn (mut p &Parser) bare() !toml.ast.Bare

bare parse and returns an ast.Bare type.

#fn (&Parser) quoted

fn (mut p &Parser) quoted() toml.ast.Quoted

quoted parse and returns an ast.Quoted type.

#fn (&Parser) boolean

fn (mut p &Parser) boolean() !toml.ast.Bool

boolean parse and returns an ast.Bool type.

#fn (&Parser) number

fn (mut p &Parser) number() toml.ast.Number

number parse and returns an ast.Number type.

#fn (&Parser) date_time

fn (mut p &Parser) date_time() !toml.ast.DateTimeType

date_time parses dates and time in RFC 3339 format.

https://datatracker.ietf.org/doc/html/rfc3339

#fn (&Parser) date

fn (mut p &Parser) date() !toml.ast.Date

date parse and returns an ast.Date type.

#fn (&Parser) time

fn (mut p &Parser) time() !toml.ast.Time

time parse and returns an ast.Time type.

#fn (&Parser) eof

fn (mut p &Parser) eof() toml.ast.EOF

eof returns an ast.EOF type.

#struct Config

pub struct Config {
pub:
	scanner       &scanner.Scanner = unsafe { nil }
	run_checks    bool = true
	decode_values bool = true
}

Config is used to configure a Parser instance.

run_checks is used to en- or disable running of the strict checker.Checker type checks.

decode_values is used to en- or disable decoding of values with the decoder.Decoder.

Interfaces

This section is empty.

Enums

This section is empty.