1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

toml: easier scanner configuration (#12016)

This commit is contained in:
Larpon
2021-09-29 13:53:06 +02:00
committed by GitHub
parent f2c710d306
commit 4ff061927b
3 changed files with 43 additions and 13 deletions

View File

@@ -38,7 +38,7 @@ pub:
tokenize_formating bool // if true, generate tokens for `\n`, ` `, `\t`, `\r` etc.
}
// new_scanner returns a new heap allocated `Scanner` instance.
// new_scanner returns a new *heap* allocated `Scanner` instance.
pub fn new_scanner(config Config) ?&Scanner {
config.input.validate() ?
mut text := config.input.text
@@ -56,6 +56,17 @@ pub fn new_scanner(config Config) ?&Scanner {
return s
}
// returns a new *stack* allocated `Scanner` instance.
pub fn new_simple(toml_input string) ?Scanner {
config := Config{
input: input.auto_config(toml_input) ?
}
return Scanner{
config: config
text: config.input.read_input() ?
}
}
// scan returns the next token from the input.
[direct_array_access]
pub fn (mut s Scanner) scan() ?token.Token {