1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This file is a lightly modified copy go/build/build.go with unused parts
12 "cmd/go/internal/fsys"
29 // A Context specifies the supporting context for a build.
31 GOARCH string // target architecture
32 GOOS string // target operating system
33 GOROOT string // Go root
34 GOPATH string // Go paths
36 // Dir is the caller's working directory, or the empty string to use
37 // the current directory of the running process. In module mode, this is used
38 // to locate the main module.
40 // If Dir is non-empty, directories passed to Import and ImportDir must
44 CgoEnabled bool // whether cgo files are included
45 UseAllFiles bool // use files regardless of +build lines, file names
46 Compiler string // compiler to assume when computing target paths
48 // The build, tool, and release tags specify build constraints
49 // that should be considered satisfied when processing +build lines.
50 // Clients creating a new context may customize BuildTags, which
51 // defaults to empty, but it is usually an error to customize ToolTags or ReleaseTags.
52 // ToolTags defaults to build tags appropriate to the current Go toolchain configuration.
53 // ReleaseTags defaults to the list of Go releases the current release is compatible with.
54 // BuildTags is not set for the Default build Context.
55 // In addition to the BuildTags, ToolTags, and ReleaseTags, build constraints
56 // consider the values of GOARCH and GOOS as satisfied tags.
57 // The last element in ReleaseTags is assumed to be the current release.
62 // The install suffix specifies a suffix to use in the name of the installation
63 // directory. By default it is empty, but custom builds that need to keep
64 // their outputs separate can set InstallSuffix to do so. For example, when
65 // using the race detector, the go command uses InstallSuffix = "race", so
66 // that on a Linux/386 system, packages are written to a directory named
67 // "linux_386_race" instead of the usual "linux_386".
70 // By default, Import uses the operating system's file system calls
71 // to read directories and files. To read from other sources,
72 // callers can set the following functions. They all have default
73 // behaviors that use the local file system, so clients need only set
74 // the functions whose behaviors they wish to change.
76 // JoinPath joins the sequence of path fragments into a single path.
77 // If JoinPath is nil, Import uses filepath.Join.
78 JoinPath func(elem ...string) string
80 // SplitPathList splits the path list into a slice of individual paths.
81 // If SplitPathList is nil, Import uses filepath.SplitList.
82 SplitPathList func(list string) []string
84 // IsAbsPath reports whether path is an absolute path.
85 // If IsAbsPath is nil, Import uses filepath.IsAbs.
86 IsAbsPath func(path string) bool
88 // IsDir reports whether the path names a directory.
89 // If IsDir is nil, Import calls os.Stat and uses the result's IsDir method.
90 IsDir func(path string) bool
92 // HasSubdir reports whether dir is lexically a subdirectory of
93 // root, perhaps multiple levels below. It does not try to check
94 // whether dir exists.
95 // If so, HasSubdir sets rel to a slash-separated path that
96 // can be joined to root to produce a path equivalent to dir.
97 // If HasSubdir is nil, Import uses an implementation built on
98 // filepath.EvalSymlinks.
99 HasSubdir func(root, dir string) (rel string, ok bool)
101 // ReadDir returns a slice of fs.FileInfo, sorted by Name,
102 // describing the content of the named directory.
103 // If ReadDir is nil, Import uses ioutil.ReadDir.
104 ReadDir func(dir string) ([]fs.FileInfo, error)
106 // OpenFile opens a file (not a directory) for reading.
107 // If OpenFile is nil, Import uses os.Open.
108 OpenFile func(path string) (io.ReadCloser, error)
111 // joinPath calls ctxt.JoinPath (if not nil) or else filepath.Join.
112 func (ctxt *Context) joinPath(elem ...string) string {
113 if f := ctxt.JoinPath; f != nil {
116 return filepath.Join(elem...)
119 // splitPathList calls ctxt.SplitPathList (if not nil) or else filepath.SplitList.
120 func (ctxt *Context) splitPathList(s string) []string {
121 if f := ctxt.SplitPathList; f != nil {
124 return filepath.SplitList(s)
127 // isAbsPath calls ctxt.IsAbsPath (if not nil) or else filepath.IsAbs.
128 func (ctxt *Context) isAbsPath(path string) bool {
129 if f := ctxt.IsAbsPath; f != nil {
132 return filepath.IsAbs(path)
135 // isDir calls ctxt.IsDir (if not nil) or else uses fsys.Stat.
136 func isDir(path string) bool {
137 fi, err := fsys.Stat(path)
138 return err == nil && fi.IsDir()
141 // hasSubdir calls ctxt.HasSubdir (if not nil) or else uses
142 // the local file system to answer the question.
143 func (ctxt *Context) hasSubdir(root, dir string) (rel string, ok bool) {
144 if f := ctxt.HasSubdir; f != nil {
148 // Try using paths we received.
149 if rel, ok = hasSubdir(root, dir); ok {
153 // Try expanding symlinks and comparing
154 // expanded against unexpanded and
155 // expanded against expanded.
156 rootSym, _ := filepath.EvalSymlinks(root)
157 dirSym, _ := filepath.EvalSymlinks(dir)
159 if rel, ok = hasSubdir(rootSym, dir); ok {
162 if rel, ok = hasSubdir(root, dirSym); ok {
165 return hasSubdir(rootSym, dirSym)
168 // hasSubdir reports if dir is within root by performing lexical analysis only.
169 func hasSubdir(root, dir string) (rel string, ok bool) {
170 root = str.WithFilePathSeparator(filepath.Clean(root))
171 dir = filepath.Clean(dir)
172 if !strings.HasPrefix(dir, root) {
175 return filepath.ToSlash(dir[len(root):]), true
178 // gopath returns the list of Go path directories.
179 func (ctxt *Context) gopath() []string {
181 for _, p := range ctxt.splitPathList(ctxt.GOPATH) {
182 if p == "" || p == ctxt.GOROOT {
183 // Empty paths are uninteresting.
184 // If the path is the GOROOT, ignore it.
185 // People sometimes set GOPATH=$GOROOT.
186 // Do not get confused by this common mistake.
189 if strings.HasPrefix(p, "~") {
190 // Path segments starting with ~ on Unix are almost always
191 // users who have incorrectly quoted ~ while setting GOPATH,
192 // preventing it from expanding to $HOME.
193 // The situation is made more confusing by the fact that
194 // bash allows quoted ~ in $PATH (most shells do not).
195 // Do not get confused by this, and do not try to use the path.
196 // It does not exist, and printing errors about it confuses
197 // those users even more, because they think "sure ~ exists!".
198 // The go command diagnoses this situation and prints a
200 // On Windows, ~ is used in short names, such as c:\progra~1
201 // for c:\program files.
209 var defaultToolTags, defaultReleaseTags []string
211 // NoGoError is the error used by Import to describe a directory
212 // containing no buildable Go source files. (It may still contain
213 // test files, files hidden by build tags, and so on.)
214 type NoGoError struct {
218 func (e *NoGoError) Error() string {
219 return "no buildable Go source files in " + e.Dir
222 // MultiplePackageError describes a directory containing
223 // multiple buildable Go source files for multiple packages.
224 type MultiplePackageError struct {
225 Dir string // directory containing files
226 Packages []string // package names found
227 Files []string // corresponding files: Files[i] declares package Packages[i]
230 func (e *MultiplePackageError) Error() string {
231 // Error string limited to two entries for compatibility.
232 return fmt.Sprintf("found packages %s (%s) and %s (%s) in %s", e.Packages[0], e.Files[0], e.Packages[1], e.Files[1], e.Dir)
235 func nameExt(name string) string {
236 i := strings.LastIndex(name, ".")
243 func fileListForExt(p *build.Package, ext string) *[]string {
247 case ".cc", ".cpp", ".cxx":
251 case ".h", ".hh", ".hpp", ".hxx":
253 case ".f", ".F", ".for", ".f90":
255 case ".s", ".S", ".sx":
260 return &p.SwigCXXFiles
267 var errNoModules = errors.New("not using modules")
269 func findImportComment(data []byte) (s string, line int) {
270 // expect keyword package
271 word, data := parseWord(data)
272 if string(word) != "package" {
276 // expect package name
277 _, data = parseWord(data)
279 // now ready for import comment, a // or /* */ comment
280 // beginning and ending on the current line.
281 for len(data) > 0 && (data[0] == ' ' || data[0] == '\t' || data[0] == '\r') {
287 case bytes.HasPrefix(data, slashSlash):
288 comment, _, _ = bytes.Cut(data[2:], newline)
289 case bytes.HasPrefix(data, slashStar):
291 comment, _, ok = bytes.Cut(data[2:], starSlash)
296 if bytes.Contains(comment, newline) {
300 comment = bytes.TrimSpace(comment)
302 // split comment into `import`, `"pkg"`
303 word, arg := parseWord(comment)
304 if string(word) != "import" {
308 line = 1 + bytes.Count(data[:cap(data)-cap(arg)], newline)
309 return strings.TrimSpace(string(arg)), line
313 slashSlash = []byte("//")
314 slashStar = []byte("/*")
315 starSlash = []byte("*/")
316 newline = []byte("\n")
319 // skipSpaceOrComment returns data with any leading spaces or comments removed.
320 func skipSpaceOrComment(data []byte) []byte {
323 case ' ', '\t', '\r', '\n':
327 if bytes.HasPrefix(data, slashSlash) {
328 i := bytes.Index(data, newline)
335 if bytes.HasPrefix(data, slashStar) {
337 i := bytes.Index(data, starSlash)
350 // parseWord skips any leading spaces or comments in data
351 // and then parses the beginning of data as an identifier or keyword,
352 // returning that word and what remains after the word.
353 func parseWord(data []byte) (word, rest []byte) {
354 data = skipSpaceOrComment(data)
356 // Parse past leading word characters.
359 r, size := utf8.DecodeRune(rest)
360 if unicode.IsLetter(r) || '0' <= r && r <= '9' || r == '_' {
367 word = data[:len(data)-len(rest)]
375 var dummyPkg build.Package
377 // fileInfo records information learned about a file included in a build.
378 type fileInfo struct {
379 name string // full name including dir
387 // Additional fields added to go/build's fileinfo for the purposes of the modindex package.
389 goBuildConstraint string
390 plusBuildConstraints []string
393 type fileImport struct {
396 doc *ast.CommentGroup
399 type fileEmbed struct {
404 var errNonSource = errors.New("non source file")
406 // getFileInfo extracts the information needed from each go file for the module
409 // If Name denotes a Go program, matchFile reads until the end of the
410 // Imports and returns that section of the file in the FileInfo's Header field,
411 // even though it only considers text until the first non-comment
414 // getFileInfo will return errNonSource if the file is not a source or object
415 // file and shouldn't even be added to IgnoredFiles.
416 func getFileInfo(dir, name string, fset *token.FileSet) (*fileInfo, error) {
417 if strings.HasPrefix(name, "_") ||
418 strings.HasPrefix(name, ".") {
422 i := strings.LastIndex(name, ".")
428 if ext != ".go" && fileListForExt(&dummyPkg, ext) == nil {
430 return nil, errNonSource
433 info := &fileInfo{name: filepath.Join(dir, name), fset: fset}
435 // binary, no reading
439 f, err := fsys.Open(info.name)
444 // TODO(matloob) should we decide whether to ignore binary only here or earlier
445 // when we create the index file?
446 var ignoreBinaryOnly bool
447 if strings.HasSuffix(name, ".go") {
448 err = readGoInfo(f, info)
449 if strings.HasSuffix(name, "_test.go") {
450 ignoreBinaryOnly = true // ignore //go:binary-only-package comments in _test.go files
453 info.header, err = readComments(f)
457 return nil, fmt.Errorf("read %s: %v", info.name, err)
460 // Look for +build comments to accept or reject the file.
461 info.goBuildConstraint, info.plusBuildConstraints, info.binaryOnly, err = getConstraints(info.header)
463 return nil, fmt.Errorf("%s: %v", name, err)
466 if ignoreBinaryOnly && info.binaryOnly {
467 info.binaryOnly = false // override info.binaryOnly
473 func cleanDecls(m map[string][]token.Position) ([]string, map[string][]token.Position) {
474 all := make([]string, 0, len(m))
475 for path := range m {
476 all = append(all, path)
483 bSlashSlash = []byte(slashSlash)
484 bStarSlash = []byte(starSlash)
485 bSlashStar = []byte(slashStar)
486 bPlusBuild = []byte("+build")
488 goBuildComment = []byte("//go:build")
490 errMultipleGoBuild = errors.New("multiple //go:build comments")
493 func isGoBuildComment(line []byte) bool {
494 if !bytes.HasPrefix(line, goBuildComment) {
497 line = bytes.TrimSpace(line)
498 rest := line[len(goBuildComment):]
499 return len(rest) == 0 || len(bytes.TrimSpace(rest)) < len(rest)
502 // Special comment denoting a binary-only package.
503 // See https://golang.org/design/2775-binary-only-packages
504 // for more about the design of binary-only packages.
505 var binaryOnlyComment = []byte("//go:binary-only-package")
507 func getConstraints(content []byte) (goBuild string, plusBuild []string, binaryOnly bool, err error) {
508 // Identify leading run of // comments and blank lines,
509 // which must be followed by a blank line.
510 // Also identify any //go:build comments.
511 content, goBuildBytes, sawBinaryOnly, err := parseFileHeader(content)
513 return "", nil, false, err
516 // If //go:build line is present, it controls, so no need to look for +build .
517 // Otherwise, get plusBuild constraints.
518 if goBuildBytes == nil {
522 if i := bytes.IndexByte(line, '\n'); i >= 0 {
523 line, p = line[:i], p[i+1:]
527 line = bytes.TrimSpace(line)
528 if !bytes.HasPrefix(line, bSlashSlash) || !bytes.Contains(line, bPlusBuild) {
532 if !constraint.IsPlusBuild(text) {
535 plusBuild = append(plusBuild, text)
539 return string(goBuildBytes), plusBuild, sawBinaryOnly, nil
542 func parseFileHeader(content []byte) (trimmed, goBuild []byte, sawBinaryOnly bool, err error) {
545 ended := false // found non-blank, non-// line, so stopped accepting // +build lines
546 inSlashStar := false // in /* */ comment
551 if i := bytes.IndexByte(line, '\n'); i >= 0 {
552 line, p = line[:i], p[i+1:]
556 line = bytes.TrimSpace(line)
557 if len(line) == 0 && !ended { // Blank line
558 // Remember position of most recent blank line.
559 // When we find the first non-blank, non-// line,
560 // this "end" position marks the latest file position
561 // where a // +build line can appear.
562 // (It must appear _before_ a blank line before the non-blank, non-// line.
563 // Yes, that's confusing, which is part of why we moved to //go:build lines.)
564 // Note that ended==false here means that inSlashStar==false,
565 // since seeing a /* would have set ended==true.
566 end = len(content) - len(p)
569 if !bytes.HasPrefix(line, slashSlash) { // Not comment line
573 if !inSlashStar && isGoBuildComment(line) {
575 return nil, nil, false, errMultipleGoBuild
579 if !inSlashStar && bytes.Equal(line, binaryOnlyComment) {
586 if i := bytes.Index(line, starSlash); i >= 0 {
588 line = bytes.TrimSpace(line[i+len(starSlash):])
593 if bytes.HasPrefix(line, bSlashSlash) {
596 if bytes.HasPrefix(line, bSlashStar) {
598 line = bytes.TrimSpace(line[len(bSlashStar):])
601 // Found non-comment text.
606 return content[:end], goBuild, sawBinaryOnly, nil
609 // saveCgo saves the information from the #cgo lines in the import "C" comment.
610 // These lines set CFLAGS, CPPFLAGS, CXXFLAGS and LDFLAGS and pkg-config directives
611 // that affect the way cgo's C code is built.
612 func (ctxt *Context) saveCgo(filename string, di *build.Package, text string) error {
613 for _, line := range strings.Split(text, "\n") {
617 // #cgo [GOOS/GOARCH...] LDFLAGS: stuff
619 line = strings.TrimSpace(line)
620 if len(line) < 5 || line[:4] != "#cgo" || (line[4] != ' ' && line[4] != '\t') {
625 line, argstr, ok := strings.Cut(strings.TrimSpace(line[4:]), ":")
627 return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig)
630 // Parse GOOS/GOARCH stuff.
631 f := strings.Fields(line)
633 return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig)
636 cond, verb := f[:len(f)-1], f[len(f)-1]
639 for _, c := range cond {
640 if ctxt.matchAuto(c, nil) {
650 args, err := splitQuoted(argstr)
652 return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig)
654 for i, arg := range args {
655 if arg, ok = expandSrcDir(arg, di.Dir); !ok {
656 return fmt.Errorf("%s: malformed #cgo argument: %s", filename, arg)
662 case "CFLAGS", "CPPFLAGS", "CXXFLAGS", "FFLAGS", "LDFLAGS":
663 // Change relative paths to absolute.
664 ctxt.makePathsAbsolute(args, di.Dir)
669 di.CgoCFLAGS = append(di.CgoCFLAGS, args...)
671 di.CgoCPPFLAGS = append(di.CgoCPPFLAGS, args...)
673 di.CgoCXXFLAGS = append(di.CgoCXXFLAGS, args...)
675 di.CgoFFLAGS = append(di.CgoFFLAGS, args...)
677 di.CgoLDFLAGS = append(di.CgoLDFLAGS, args...)
679 di.CgoPkgConfig = append(di.CgoPkgConfig, args...)
681 return fmt.Errorf("%s: invalid #cgo verb: %s", filename, orig)
687 // expandSrcDir expands any occurrence of ${SRCDIR}, making sure
688 // the result is safe for the shell.
689 func expandSrcDir(str string, srcdir string) (string, bool) {
690 // "\" delimited paths cause safeCgoName to fail
691 // so convert native paths with a different delimiter
692 // to "/" before starting (eg: on windows).
693 srcdir = filepath.ToSlash(srcdir)
695 chunks := strings.Split(str, "${SRCDIR}")
697 return str, safeCgoName(str)
700 for _, chunk := range chunks {
701 ok = ok && (chunk == "" || safeCgoName(chunk))
703 ok = ok && (srcdir == "" || safeCgoName(srcdir))
704 res := strings.Join(chunks, srcdir)
705 return res, ok && res != ""
708 // makePathsAbsolute looks for compiler options that take paths and
709 // makes them absolute. We do this because through the 1.8 release we
710 // ran the compiler in the package directory, so any relative -I or -L
711 // options would be relative to that directory. In 1.9 we changed to
712 // running the compiler in the build directory, to get consistent
713 // build results (issue #19964). To keep builds working, we change any
714 // relative -I or -L options to be absolute.
716 // Using filepath.IsAbs and filepath.Join here means the results will be
717 // different on different systems, but that's OK: -I and -L options are
718 // inherently system-dependent.
719 func (ctxt *Context) makePathsAbsolute(args []string, srcDir string) {
721 for i, arg := range args {
723 if !filepath.IsAbs(arg) {
724 args[i] = filepath.Join(srcDir, arg)
727 } else if strings.HasPrefix(arg, "-I") || strings.HasPrefix(arg, "-L") {
731 if !filepath.IsAbs(arg[2:]) {
732 args[i] = arg[:2] + filepath.Join(srcDir, arg[2:])
739 // NOTE: $ is not safe for the shell, but it is allowed here because of linker options like -Wl,$ORIGIN.
740 // We never pass these arguments to a shell (just to programs we construct argv for), so this should be okay.
741 // See golang.org/issue/6038.
742 // The @ is for OS X. See golang.org/issue/13720.
743 // The % is for Jenkins. See golang.org/issue/16959.
744 // The ! is because module paths may use them. See golang.org/issue/26716.
745 // The ~ and ^ are for sr.ht. See golang.org/issue/32260.
746 const safeString = "+-.,/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:$@%! ~^"
748 func safeCgoName(s string) bool {
752 for i := 0; i < len(s); i++ {
753 if c := s[i]; c < utf8.RuneSelf && strings.IndexByte(safeString, c) < 0 {
760 // splitQuoted splits the string s around each instance of one or more consecutive
761 // white space characters while taking into account quotes and escaping, and
762 // returns an array of substrings of s or an empty list if s contains only white space.
763 // Single quotes and double quotes are recognized to prevent splitting within the
764 // quoted region, and are removed from the resulting substrings. If a quote in s
765 // isn't closed err will be set and r will have the unclosed argument as the
766 // last element. The backslash is used for escaping.
768 // For example, the following string:
770 // a b:"c d" 'e''f' "g\""
772 // Would be parsed as:
774 // []string{"a", "b:c d", "ef", `g"`}
775 func splitQuoted(s string) (r []string, err error) {
777 arg := make([]rune, len(s))
782 for _, rune := range s {
789 case quote != '\x00':
794 case rune == '"' || rune == '\'':
798 case unicode.IsSpace(rune):
801 args = append(args, string(arg[:i]))
810 args = append(args, string(arg[:i]))
813 err = errors.New("unclosed quote")
815 err = errors.New("unfinished escaping")
820 // matchAuto interprets text as either a +build or //go:build expression (whichever works),
821 // reporting whether the expression matches the build context.
823 // matchAuto is only used for testing of tag evaluation
824 // and in #cgo lines, which accept either syntax.
825 func (ctxt *Context) matchAuto(text string, allTags map[string]bool) bool {
826 if strings.ContainsAny(text, "&|()") {
827 text = "//go:build " + text
829 text = "// +build " + text
831 x, err := constraint.Parse(text)
835 return ctxt.eval(x, allTags)
838 func (ctxt *Context) eval(x constraint.Expr, allTags map[string]bool) bool {
839 return x.Eval(func(tag string) bool { return ctxt.matchTag(tag, allTags) })
842 // matchTag reports whether the name is one of:
844 // cgo (if cgo is enabled)
849 // linux (if GOOS == android)
850 // solaris (if GOOS == illumos)
851 // tag (if tag is listed in ctxt.BuildTags or ctxt.ReleaseTags)
853 // It records all consulted tags in allTags.
854 func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
860 if ctxt.CgoEnabled && name == "cgo" {
863 if name == ctxt.GOOS || name == ctxt.GOARCH || name == ctxt.Compiler {
866 if ctxt.GOOS == "android" && name == "linux" {
869 if ctxt.GOOS == "illumos" && name == "solaris" {
872 if ctxt.GOOS == "ios" && name == "darwin" {
875 if name == "unix" && unixOS[ctxt.GOOS] {
878 if name == "boringcrypto" {
879 name = "goexperiment.boringcrypto" // boringcrypto is an old name for goexperiment.boringcrypto
883 for _, tag := range ctxt.BuildTags {
888 for _, tag := range ctxt.ToolTags {
893 for _, tag := range ctxt.ReleaseTags {
902 // goodOSArchFile returns false if the name contains a $GOOS or $GOARCH
903 // suffix which does not match the current system.
904 // The recognized name formats are:
908 // name_$(GOOS)_$(GOARCH).*
909 // name_$(GOOS)_test.*
910 // name_$(GOARCH)_test.*
911 // name_$(GOOS)_$(GOARCH)_test.*
914 // if GOOS=android, then files with GOOS=linux are also matched.
915 // if GOOS=illumos, then files with GOOS=solaris are also matched.
916 // if GOOS=ios, then files with GOOS=darwin are also matched.
917 func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
918 name, _, _ = strings.Cut(name, ".")
920 // Before Go 1.4, a file called "linux.go" would be equivalent to having a
921 // build tag "linux" in that file. For Go 1.4 and beyond, we require this
922 // auto-tagging to apply only to files with a non-empty prefix, so
923 // "foo_linux.go" is tagged but "linux.go" is not. This allows new operating
924 // systems, such as android, to arrive without breaking existing code with
925 // innocuous source code in "android.go". The easiest fix: cut everything
926 // in the name before the initial _.
927 i := strings.Index(name, "_")
931 name = name[i:] // ignore everything before first _
933 l := strings.Split(name, "_")
934 if n := len(l); n > 0 && l[n-1] == "test" {
938 if n >= 2 && knownOS[l[n-2]] && knownArch[l[n-1]] {
940 // In case we short-circuit on l[n-1].
941 allTags[l[n-2]] = true
943 return ctxt.matchTag(l[n-1], allTags) && ctxt.matchTag(l[n-2], allTags)
945 if n >= 1 && (knownOS[l[n-1]] || knownArch[l[n-1]]) {
946 return ctxt.matchTag(l[n-1], allTags)