-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_raw.go
More file actions
47 lines (40 loc) · 795 Bytes
/
Copy pathparse_raw.go
File metadata and controls
47 lines (40 loc) · 795 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
43
44
45
46
47
package lunar
import (
"go/ast"
"go/types"
)
const LuaPkgPath = "github.com/eandre/lunar/lua"
func (p *Parser) parseRaw(w *Writer, e *ast.CallExpr) bool {
sel, ok := e.Fun.(*ast.SelectorExpr)
if !ok {
return false
}
if sel.Sel.Name != "Raw" {
return false
}
ident, ok := sel.X.(*ast.Ident)
if !ok {
return false
}
pkg, ok := p.identObject(ident).(*types.PkgName)
if !ok {
return false
}
if pkg.Imported().Path() != LuaPkgPath {
return false
}
for _, arg := range e.Args {
switch arg := arg.(type) {
case *ast.BasicLit:
if arg.Value[0] == '"' || arg.Value[0] == '`' {
// String literal; skip quotes
w.WriteString(arg.Value[1 : len(arg.Value)-1])
} else {
w.WriteString(arg.Value)
}
default:
p.parseExpr(w, arg)
}
}
return true
}