MCPcopy
hub / github.com/MadAppGang/dingo / parseScrutinee

Method parseScrutinee

pkg/matchparser/match_parser.go:71–107  ·  view source on GitHub ↗

parseScrutinee parses the expression being matched

()

Source from the content-addressed store, hash-verified

69
70// parseScrutinee parses the expression being matched
71func (p *MatchParser) parseScrutinee() (ast.Expr, error) {
72 startPos := p.tok.Current().Pos
73 var text []string
74
75 // Collect tokens until we hit '{'
76 depth := 0
77 for {
78 tok := p.tok.Current()
79
80 if tok.Kind == tokenizer.EOF {
81 return nil, fmt.Errorf("unexpected EOF in match scrutinee")
82 }
83
84 if tok.Kind == tokenizer.LBRACE && depth == 0 {
85 break
86 }
87
88 // Track nested braces
89 if tok.Kind == tokenizer.LBRACE {
90 depth++
91 } else if tok.Kind == tokenizer.RBRACE {
92 depth--
93 }
94
95 // Skip newlines in scrutinee
96 if tok.Kind != tokenizer.NEWLINE {
97 text = append(text, tok.Lit)
98 }
99 p.tok.Advance()
100 }
101
102 return &ast.RawExpr{
103 StartPos: startPos,
104 EndPos: p.tok.Current().Pos,
105 Text: strings.TrimSpace(strings.Join(text, " ")),
106 }, nil
107}
108
109// parseArms parses all match arms until closing brace
110func (p *MatchParser) parseArms() ([]*ast.MatchArm, []*ast.Comment, error) {

Callers 1

ParseMatchExprMethod · 0.95

Calls 3

CurrentMethod · 0.80
AdvanceMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected