aboutsummaryrefslogtreecommitdiff
path: root/config/parser.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-04-02 06:23:30 +0000
committerGravatar Runxi Yu2026-04-02 06:28:39 +0000
commita041d523de389b65b98a5373a8034041db2a8d83 (patch)
tree7b423dc735f463be616045f2c3c2095a7737aca7 /config/parser.go
parentresearch: Add dynamic pack resources (diff)
*: Remove
Diffstat (limited to 'config/parser.go')
-rw-r--r--config/parser.go88
1 files changed, 0 insertions, 88 deletions
diff --git a/config/parser.go b/config/parser.go
deleted file mode 100644
index c56a68d5..00000000
--- a/config/parser.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package config
-
-import (
- "bufio"
- "errors"
- "fmt"
- "io"
-)
-
-// ParseConfig reads and parses Git configuration entries from r.
-func ParseConfig(r io.Reader) (*Config, error) {
- parser := &configParser{
- reader: bufio.NewReader(r),
- lineNum: 1,
- }
-
- return parser.parse()
-}
-
-type configParser struct {
- reader *bufio.Reader
- lineNum int
- currentSection string
- currentSubsec string
- peeked byte
- hasPeeked bool
-}
-
-func (p *configParser) parse() (*Config, error) {
- cfg := &Config{}
-
- err := p.skipBOM()
- if err != nil {
- return nil, err
- }
-
- for {
- ch, err := p.nextChar()
- if errors.Is(err, io.EOF) {
- break
- }
-
- if err != nil {
- return nil, err
- }
-
- // Skip leading whitespace between entries.
- if isWhitespace(ch) {
- continue
- }
-
- // Comments
- if ch == '#' || ch == ';' {
- err := p.skipToEOL()
- if err != nil && !errors.Is(err, io.EOF) {
- return nil, err
- }
-
- continue
- }
-
- // Section header
- if ch == '[' {
- err := p.parseSection()
- if err != nil {
- return nil, fmt.Errorf("furgit: config: line %d: %w", p.lineNum, err)
- }
-
- continue
- }
-
- // Key-value pair
- if isLetter(ch) {
- p.unreadChar(ch)
-
- err := p.parseKeyValue(cfg)
- if err != nil {
- return nil, fmt.Errorf("furgit: config: line %d: %w", p.lineNum, err)
- }
-
- continue
- }
-
- return nil, fmt.Errorf("furgit: config: line %d: unexpected character %q", p.lineNum, ch)
- }
-
- return cfg, nil
-}