diff options
author | Wim <wim@42.be> | 2019-03-05 23:08:54 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2019-03-05 23:10:45 +0100 |
commit | 325d62b41c03f0530513a4f404cc8d7349b6885b (patch) | |
tree | d6f9f2809bdcd3a35b696b412c24cf6f54ddab78 /vendor/github.com/d5/tengo/compiler/parser/parser.go | |
parent | e955a056e2aa4a07c6375315113886b2ee86138c (diff) | |
download | matterbridge-msglm-325d62b41c03f0530513a4f404cc8d7349b6885b.tar.gz matterbridge-msglm-325d62b41c03f0530513a4f404cc8d7349b6885b.tar.bz2 matterbridge-msglm-325d62b41c03f0530513a4f404cc8d7349b6885b.zip |
Update vendor d5/tengo
Diffstat (limited to 'vendor/github.com/d5/tengo/compiler/parser/parser.go')
-rw-r--r-- | vendor/github.com/d5/tengo/compiler/parser/parser.go | 39 |
1 files changed, 31 insertions, 8 deletions
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, } |