big tings
This commit is contained in:
31
parser/decoders/list.go
Normal file
31
parser/decoders/list.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.max-richter.dev/max/marka/parser/matcher"
|
||||
"git.max-richter.dev/max/marka/template"
|
||||
)
|
||||
|
||||
func List(input string, block template.Block) (value any, error error) {
|
||||
blocks, err := template.CompileTemplate(block.ListTemplate)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot extract blocks: %w", err)
|
||||
}
|
||||
|
||||
var out []any
|
||||
|
||||
for line := range strings.SplitSeq(strings.TrimSuffix(input, "\n"), "\n") {
|
||||
matches := matcher.MatchBlocksFuzzy(line, blocks, 0.3)
|
||||
|
||||
res, err := Parse(matches)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not match blocks: %w", err)
|
||||
}
|
||||
|
||||
out = append(out, res)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
Reference in New Issue
Block a user