toml: fix toml.scanner.new_simple/1 to *always* create a scanner, based on text, not a file path

pull/13770/head
Delyan Angelov 2022-03-18 16:14:44 +02:00
parent 0ca87ad09f
commit 54b0a2aa62
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 3 deletions

View File

@ -47,7 +47,8 @@ pub:
tokenize_formatting bool = true // 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, based on the file in config.input.file_path,
// or based on the text in config.input.text .
pub fn new_scanner(config Config) ?&Scanner {
config.input.validate() ?
mut text := config.input.text
@ -65,10 +66,12 @@ pub fn new_scanner(config Config) ?&Scanner {
return s
}
// returns a new *stack* allocated `Scanner` instance.
// new_simple returns a new *stack* allocated `Scanner` instance, that will work on the text in `toml_input`.
pub fn new_simple(toml_input string) ?Scanner {
config := Config{
input: input.auto_config(toml_input) ?
input: input.Config{
text: toml_input
}
}
return Scanner{
config: config