77 "fmt"
88 "os"
99 "path/filepath"
10- "regexp"
1110 "strings"
1211
1312 "github.com/githubnext/gh-aw/pkg/console"
@@ -17,57 +16,6 @@ import (
1716
1817var log = logger .New ("parser:frontmatter" )
1918
20- // IncludeDirectivePattern matches @include, @import (deprecated), or {{#import (new) directives
21- // The colon after #import is optional and ignored if present
22- var IncludeDirectivePattern = regexp .MustCompile (`^(?:@(?:include|import)(\?)?\s+(.+)|{{#import(\?)?\s*:?\s*(.+?)\s*}})$` )
23-
24- // LegacyIncludeDirectivePattern matches only the deprecated @include and @import directives
25- var LegacyIncludeDirectivePattern = regexp .MustCompile (`^@(?:include|import)(\?)?\s+(.+)$` )
26-
27- // ImportDirectiveMatch holds the parsed components of an import directive
28- type ImportDirectiveMatch struct {
29- IsOptional bool
30- Path string
31- IsLegacy bool
32- Original string
33- }
34-
35- // ParseImportDirective parses an import directive and returns its components
36- func ParseImportDirective (line string ) * ImportDirectiveMatch {
37- trimmedLine := strings .TrimSpace (line )
38-
39- // Check if it matches the import pattern at all
40- matches := IncludeDirectivePattern .FindStringSubmatch (trimmedLine )
41- if matches == nil {
42- return nil
43- }
44-
45- // Check if it's legacy syntax
46- isLegacy := LegacyIncludeDirectivePattern .MatchString (trimmedLine )
47-
48- var isOptional bool
49- var path string
50-
51- if isLegacy {
52- // Legacy syntax: @include? path or @import? path
53- // Group 1: optional marker, Group 2: path
54- isOptional = matches [1 ] == "?"
55- path = strings .TrimSpace (matches [2 ])
56- } else {
57- // New syntax: {{#import?: path}} or {{#import: path}} (colon is optional)
58- // Group 3: optional marker, Group 4: path
59- isOptional = matches [3 ] == "?"
60- path = strings .TrimSpace (matches [4 ])
61- }
62-
63- return & ImportDirectiveMatch {
64- IsOptional : isOptional ,
65- Path : path ,
66- IsLegacy : isLegacy ,
67- Original : trimmedLine ,
68- }
69- }
70-
7119// ImportsResult holds the result of processing imports from frontmatter
7220type ImportsResult struct {
7321 MergedTools string // Merged tools configuration from all imports
0 commit comments