diff options
Diffstat (limited to 'vendor/github.com/d5/tengo/compiler/parser')
3 files changed, 33 insertions, 37 deletions
diff --git a/vendor/github.com/d5/tengo/compiler/parser/parse_file.go b/vendor/github.com/d5/tengo/compiler/parser/parse_file.go deleted file mode 100644 index 0482c775..00000000 --- a/vendor/github.com/d5/tengo/compiler/parser/parse_file.go +++ /dev/null @@ -1,28 +0,0 @@ -package parser - -import ( - "io" - - "github.com/d5/tengo/compiler/ast" - "github.com/d5/tengo/compiler/source" -) - -// ParseFile parses a file with a given src. -func ParseFile(file *source.File, src []byte, trace io.Writer) (res *ast.File, err error) { - p := NewParser(file, src, trace) - - defer func() { - if e := recover(); e != nil { - if _, ok := e.(bailout); !ok { - panic(e) - } - } - - p.errors.Sort() - err = p.errors.Err() - }() - - res, err = p.ParseFile() - - return -} diff --git a/vendor/github.com/d5/tengo/compiler/parser/parse_source.go b/vendor/github.com/d5/tengo/compiler/parser/parse_source.go index 5d242db4..5c71436d 100644 --- a/vendor/github.com/d5/tengo/compiler/parser/parse_source.go +++ b/vendor/github.com/d5/tengo/compiler/parser/parse_source.go @@ -12,5 +12,6 @@ func ParseSource(filename string, src []byte, trace io.Writer) (res *ast.File, e fileSet := source.NewFileSet() file := fileSet.AddFile(filename, -1, len(src)) - return ParseFile(file, src, trace) + p := NewParser(file, src, trace) + return p.ParseFile() } diff --git a/vendor/github.com/d5/tengo/compiler/parser/parser.go b/vendor/github.com/d5/tengo/compiler/parser/parser.go index 93f04f7c..1f609ab5 100644 --- a/vendor/github.com/d5/tengo/compiler/parser/parser.go +++ b/vendor/github.com/d5/tengo/compiler/parser/parser.go @@ -57,7 +57,18 @@ func NewParser(file *source.File, src []byte, trace io.Writer) *Parser { } // ParseFile parses the source and returns an AST file unit. -func (p *Parser) ParseFile() (*ast.File, error) { +func (p *Parser) ParseFile() (file *ast.File, err error) { + defer func() { + if e := recover(); e != nil { + if _, ok := e.(bailout); !ok { + panic(e) + } + } + + p.errors.Sort() + err = p.errors.Err() + }() + if p.trace { defer un(trace(p, "File")) } @@ -71,10 +82,12 @@ func (p *Parser) ParseFile() (*ast.File, error) { return nil, p.errors.Err() } - return &ast.File{ + file = &ast.File{ InputFile: p.file, Stmts: stmts, - }, nil + } + + return } func (p *Parser) parseExpr() ast.Expr { @@ -1002,16 +1015,26 @@ func (p *Parser) parseMapElementLit() *ast.MapElementLit { defer un(trace(p, "MapElementLit")) } - // key: read identifier token but it's not actually an identifier - ident := p.parseIdent() + pos := p.pos + name := "_" + + if p.token == token.Ident { + name = p.tokenLit + } else if p.token == token.String { + v, _ := strconv.Unquote(p.tokenLit) + name = v + } else { + p.errorExpected(pos, "map key") + } + + p.next() colonPos := p.expect(token.Colon) - valueExpr := p.parseExpr() return &ast.MapElementLit{ - Key: ident.Name, - KeyPos: ident.NamePos, + Key: name, + KeyPos: pos, ColonPos: colonPos, Value: valueExpr, } |