Skip to content

Commit

Permalink
Merge pull request #1646 from xushiwei/ov
Browse files Browse the repository at this point in the history
stringLitEx bugfix: stringex3
  • Loading branch information
xushiwei committed Jan 20, 2024
2 parents c8a40d7 + 9a456d3 commit 676fd45
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
38 changes: 38 additions & 0 deletions parser/_testdata/stringex3/parser.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

file string_lit.gop
noEntrypoint
ast.FuncDecl:
Name:
ast.Ident:
Name: main
Type:
ast.FuncType:
Params:
ast.FieldList:
Body:
ast.BlockStmt:
List:
ast.ExprStmt:
X:
ast.CallExpr:
Fun:
ast.Ident:
Name: println
Args:
ast.BasicLit:
Kind: STRING
Value: "file:${args[0]}?${query}"
Extra:
file:
ast.IndexExpr:
X:
ast.Ident:
Name: args
Index:
ast.BasicLit:
Kind: INT
Value: 0
?
ast.Ident:
Name: query
1 change: 1 addition & 0 deletions parser/_testdata/stringex3/string_lit.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
println "file:${args[0]}?${query}"
5 changes: 3 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ loop:
}
to := pos + token.Pos(from+end)
parts = p.stringLitExpr(parts, pos+token.Pos(from), to)
pos = to
pos = to + 1
text = left[end+1:]
case '$': // $$
parts = append(parts, text[:at+2])
Expand Down Expand Up @@ -1674,7 +1674,8 @@ func hasExtra(text string) bool {
func (p *parser) stringLitExpr(parts []any, off, end token.Pos) []any {
file := p.file
base := file.Base()
expr, err := parseExprEx(p.file, p.scanner.CodeTo(int(end)-base), int(off)-base, 0)
src := p.scanner.CodeTo(int(end) - base)
expr, err := parseExprEx(p.file, src, int(off)-base, 0)
if err != nil {
p.errors = append(p.errors, err...)
expr = &ast.BadExpr{From: off, To: end}
Expand Down

0 comments on commit 676fd45

Please sign in to comment.