mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Introduce shorthand function parse.Parse
This commit is contained in:
parent
33643163a3
commit
2ee8efc1b4
|
@ -52,14 +52,13 @@ func main() {
|
|||
panic(lr.Err)
|
||||
}
|
||||
|
||||
p := parse.NewParser(name)
|
||||
pe := p.Parse(lr.Line, false)
|
||||
n, pe := parse.Parse(name, lr.Line)
|
||||
if pe != nil {
|
||||
fmt.Print(pe.(*util.ContextualError).Pprint())
|
||||
continue
|
||||
}
|
||||
|
||||
ee := ev.Eval(name, lr.Line, p.Root)
|
||||
ee := ev.Eval(name, lr.Line, n)
|
||||
if ee != nil {
|
||||
fmt.Println(ee.(*util.ContextualError).Pprint())
|
||||
continue
|
||||
|
|
|
@ -150,6 +150,17 @@ func (p *Parser) Parse(text string, tab bool) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Parse is a shorthand for constructing a Paser, call Parse and take out its
|
||||
// Root.
|
||||
func Parse(name, text string) (Node, error) {
|
||||
p := NewParser(name)
|
||||
err := p.Parse(text, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p.Root, nil
|
||||
}
|
||||
|
||||
// parse parses a chunk and ensures there are no trailing tokens
|
||||
func (p *Parser) parse() *ListNode {
|
||||
chunk := p.chunk()
|
||||
|
|
Loading…
Reference in New Issue
Block a user