mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-10 18:13:18 +01:00
internal/shaderlister: bug fix: directives in multiline comments didn't work
This commit is contained in:
parent
1a206ae53c
commit
696e6484fc
@ -187,16 +187,18 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
reShaderSourceDirective = regexp.MustCompile(`(?m)^\s*//` + regexp.QuoteMeta(shaderSourceDirective) + `$`)
|
||||
reShaderFileDirective = regexp.MustCompile(`(?m)^\s*//` + regexp.QuoteMeta(shaderFileDirective) + ` `)
|
||||
reShaderSourceDirective = regexp.MustCompile(`^\s*//` + regexp.QuoteMeta(shaderSourceDirective) + `$`)
|
||||
reShaderFileDirective = regexp.MustCompile(`^\s*//` + regexp.QuoteMeta(shaderFileDirective) + ` `)
|
||||
)
|
||||
|
||||
func hasShaderSourceDirectiveInComment(commentGroup *ast.CommentGroup) bool {
|
||||
for _, line := range commentGroup.List {
|
||||
if reShaderSourceDirective.MatchString(line.Text) {
|
||||
for _, c := range commentGroup.List {
|
||||
for _, line := range strings.Split(c.Text, "\n") {
|
||||
if reShaderSourceDirective.MatchString(line) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@ -221,20 +223,21 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
funcs = append(funcs, f)
|
||||
}
|
||||
}
|
||||
for _, c := range f.Comments {
|
||||
for _, l := range c.List {
|
||||
for _, cg := range f.Comments {
|
||||
for _, c := range cg.List {
|
||||
// Ignore the line if it is in a function declaration.
|
||||
if slices.ContainsFunc(funcs, func(f *ast.FuncDecl) bool {
|
||||
return f.Pos() <= l.Pos() && l.Pos() < f.End()
|
||||
return f.Pos() <= c.Pos() && c.Pos() < f.End()
|
||||
}) {
|
||||
continue
|
||||
}
|
||||
|
||||
m := reShaderFileDirective.FindString(l.Text)
|
||||
if m == "" {
|
||||
for _, line := range strings.Split(c.Text, "\n") {
|
||||
m := reShaderFileDirective.FindString(line)
|
||||
if len(m) == 0 {
|
||||
continue
|
||||
}
|
||||
patterns := strings.TrimPrefix(l.Text, m)
|
||||
patterns := strings.TrimPrefix(line, m)
|
||||
for _, pattern := range strings.FieldsFunc(patterns, isAsciiSpace) {
|
||||
pattern := filepath.Join(pkg.Dir, filepath.FromSlash(pattern))
|
||||
if _, ok := visitedPatterns[pattern]; ok {
|
||||
@ -256,7 +259,7 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
return nil
|
||||
}
|
||||
visitedPaths[path] = struct{}{}
|
||||
goFile := pkg.Fset.Position(c.Pos()).Filename
|
||||
goFile := pkg.Fset.Position(cg.Pos()).Filename
|
||||
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, goFile, path)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -280,7 +283,7 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
continue
|
||||
}
|
||||
visitedPaths[path] = struct{}{}
|
||||
goFile := pkg.Fset.Position(c.Pos()).Filename
|
||||
goFile := pkg.Fset.Position(cg.Pos()).Filename
|
||||
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, goFile, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -290,6 +293,7 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
topLevelDecls := map[ast.Decl]struct{}{}
|
||||
for _, file := range pkg.Syntax {
|
||||
|
@ -81,3 +81,8 @@ func foo() {
|
||||
|
||||
//ebitengine:shaderfile *_notkage.go
|
||||
}
|
||||
|
||||
// A directive in a comment block is not ignored.
|
||||
/*
|
||||
//ebitengine:shaderfile *_kage.go
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user