-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparser.go
More file actions
42 lines (36 loc) · 829 Bytes
/
Copy pathparser.go
File metadata and controls
42 lines (36 loc) · 829 Bytes
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 parser
import (
G "gorgonia.org/gorgonia"
)
// Parser is a structure that parses an expression and returns the corresponding gorgonia node
type Parser struct {
dico map[string]*G.Node
g *G.ExprGraph
}
// NewParser ...
func NewParser(g *G.ExprGraph) *Parser {
return &Parser{
dico: make(map[string]*G.Node),
g: g,
}
}
// Get a pointer to the Node from its representation in the formulae
func (p *Parser) Get(ident string) *G.Node {
return p.dico[ident]
}
// Set a value to the ident
func (p *Parser) Set(ident string, value *G.Node) {
p.dico[ident] = value
}
// Parse a string and returns the node
func (p *Parser) Parse(s string) (*G.Node, error) {
l := &exprLex{}
l.line = []byte(s)
l.dico = p.dico
l.g = p.g
gorgoniaParse(l)
if l.err != nil {
return nil, l.err
}
return l.result, nil
}