-
Notifications
You must be signed in to change notification settings - Fork 10
/
parser.go
42 lines (33 loc) · 891 Bytes
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package h
//go:generate peggy -o h_gen.go h.peg
import (
"fmt"
"github.com/eaburns/peggy/peg"
"within.website/x/langs/jbo/namcu"
)
func (p *_Parser) Parse() (int, bool) {
pos, perr := _HAccepts(p, 0)
return perr, pos >= 0
}
func (p *_Parser) ErrorTree(minPos int) *peg.Fail {
p.fail = make(map[_key]*peg.Fail) // reset fail memo table
_, tree := _HFail(p, 0, minPos)
return tree
}
func (p *_Parser) ParseTree() *peg.Node {
_, tree := _HNode(p, 0)
return tree
}
// Parse parses h.
// On success, the parseTree is returned.
// On failure, both the word-level and the raw, morphological errors are returned.
func Parse(text string) (*peg.Node, error) {
p := _NewParser(text)
if perr, ok := p.Parse(); !ok {
return nil, fmt.Errorf("h: gentoldra fi'o zvati fe li %s", namcu.Lerfu(perr))
}
tree := p.ParseTree()
RemoveSpace(tree)
CollapseLists(tree)
return tree, nil
}