mirror of
https://github.com/RWejlgaard/org.git
synced 2026-05-06 04:34:45 +00:00
fix: custom states not parsed correctly has been fixed (#4)
This commit is contained in:
parent
eb5f9a16ce
commit
2f98d8e0f1
2 changed files with 24 additions and 3 deletions
|
|
@ -40,7 +40,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the org file
|
// Parse the org file
|
||||||
orgFile, err := parser.ParseOrgFile(filePath)
|
orgFile, err := parser.ParseOrgFile(filePath, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error parsing org file: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error parsing org file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rwejlgaard/org/internal/config"
|
||||||
"github.com/rwejlgaard/org/internal/model"
|
"github.com/rwejlgaard/org/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parser patterns
|
// Parser patterns
|
||||||
var (
|
var (
|
||||||
headingPattern = regexp.MustCompile(`^(\*+)\s+(?:(TODO|PROG|BLOCK|DONE)\s+)?(?:\[#([A-C])\]\s+)?(.+?)(?:\s+(:[[:alnum:]_@#%:]+:)\s*)?$`)
|
|
||||||
scheduledPattern = regexp.MustCompile(`SCHEDULED:\s*<([^>]+)>`)
|
scheduledPattern = regexp.MustCompile(`SCHEDULED:\s*<([^>]+)>`)
|
||||||
deadlinePattern = regexp.MustCompile(`DEADLINE:\s*<([^>]+)>`)
|
deadlinePattern = regexp.MustCompile(`DEADLINE:\s*<([^>]+)>`)
|
||||||
clockPattern = regexp.MustCompile(`CLOCK:\s*\[([^\]]+)\](?:--\[([^\]]+)\])?`)
|
clockPattern = regexp.MustCompile(`CLOCK:\s*\[([^\]]+)\](?:--\[([^\]]+)\])?`)
|
||||||
|
|
@ -23,8 +23,29 @@ var (
|
||||||
codeBlockEnd = regexp.MustCompile(`^\s*#\+END_SRC`)
|
codeBlockEnd = regexp.MustCompile(`^\s*#\+END_SRC`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// buildHeadingPattern creates a regex pattern that matches configured states
|
||||||
|
func buildHeadingPattern(cfg *config.Config) *regexp.Regexp {
|
||||||
|
stateNames := cfg.GetStateNames()
|
||||||
|
var statesPattern string
|
||||||
|
if len(stateNames) > 0 {
|
||||||
|
// Escape state names and join with |
|
||||||
|
escapedStates := make([]string, len(stateNames))
|
||||||
|
for i, state := range stateNames {
|
||||||
|
escapedStates[i] = regexp.QuoteMeta(state)
|
||||||
|
}
|
||||||
|
statesPattern = strings.Join(escapedStates, "|")
|
||||||
|
} else {
|
||||||
|
// Fallback to default states if none configured
|
||||||
|
statesPattern = "TODO|PROG|BLOCK|DONE"
|
||||||
|
}
|
||||||
|
|
||||||
|
pattern := `^(\*+)\s+(?:(` + statesPattern + `)\s+)?(?:\[#([A-C])\]\s+)?(.+?)(?:\s+(:[[:alnum:]_@#%:]+:)\s*)?$`
|
||||||
|
return regexp.MustCompile(pattern)
|
||||||
|
}
|
||||||
|
|
||||||
// ParseOrgFile reads and parses an org-mode file
|
// ParseOrgFile reads and parses an org-mode file
|
||||||
func ParseOrgFile(path string) (*model.OrgFile, error) {
|
func ParseOrgFile(path string, cfg *config.Config) (*model.OrgFile, error) {
|
||||||
|
headingPattern := buildHeadingPattern(cfg)
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If file doesn't exist, return empty org file
|
// If file doesn't exist, return empty org file
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue