Skip to content

Commit bf2e553

Browse files
committed
extract scalar literal parsers from expression parser
1 parent eec0234 commit bf2e553

3 files changed

Lines changed: 55 additions & 52 deletions

File tree

docs/architecture.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Key files:
6363
- `vibes/lexer.go`
6464
- `vibes/parser.go` (parser core initialization + token stream helpers)
6565
- `vibes/parser_errors.go` (parse errors and token labeling)
66-
- `vibes/parser_expressions.go` (expression-level parsing and call literals)
66+
- `vibes/parser_expressions.go` (expression-level parsing and call/yield/case literals)
67+
- `vibes/parser_literals.go` (identifier and scalar literal parsing)
6768
- `vibes/parser_block_literals.go` (block literals, block params, and typed union param parsing)
6869
- `vibes/parser_statements.go` (statement dispatch + return/raise/block parsing)
6970
- `vibes/parser_expression_statements.go` (expression/assert/assignment statement parsing)

vibes/parser_expressions.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package vibes
22

33
import (
44
"fmt"
5-
"strconv"
65
)
76

87
func (p *parser) parseExpression(precedence int) Expression {
@@ -32,56 +31,6 @@ func (p *parser) parseExpression(precedence int) Expression {
3231
return left
3332
}
3433

35-
func (p *parser) parseIdentifier() Expression {
36-
return &Identifier{Name: p.curToken.Literal, position: p.curToken.Pos}
37-
}
38-
39-
func (p *parser) parseIntegerLiteral() Expression {
40-
value, err := strconv.ParseInt(p.curToken.Literal, 10, 64)
41-
if err != nil {
42-
p.addParseError(p.curToken.Pos, "invalid integer literal")
43-
return nil
44-
}
45-
return &IntegerLiteral{Value: value, position: p.curToken.Pos}
46-
}
47-
48-
func (p *parser) parseFloatLiteral() Expression {
49-
value, err := strconv.ParseFloat(p.curToken.Literal, 64)
50-
if err != nil {
51-
p.addParseError(p.curToken.Pos, "invalid float literal")
52-
return nil
53-
}
54-
return &FloatLiteral{Value: value, position: p.curToken.Pos}
55-
}
56-
57-
func (p *parser) parseStringLiteral() Expression {
58-
return &StringLiteral{Value: p.curToken.Literal, position: p.curToken.Pos}
59-
}
60-
61-
func (p *parser) parseBooleanLiteral() Expression {
62-
return &BoolLiteral{Value: p.curToken.Type == tokenTrue, position: p.curToken.Pos}
63-
}
64-
65-
func (p *parser) parseNilLiteral() Expression {
66-
return &NilLiteral{position: p.curToken.Pos}
67-
}
68-
69-
func (p *parser) parseSymbolLiteral() Expression {
70-
return &SymbolLiteral{Name: p.curToken.Literal, position: p.curToken.Pos}
71-
}
72-
73-
func (p *parser) parseIvarLiteral() Expression {
74-
return &IvarExpr{Name: p.curToken.Literal, position: p.curToken.Pos}
75-
}
76-
77-
func (p *parser) parseClassVarLiteral() Expression {
78-
return &ClassVarExpr{Name: p.curToken.Literal, position: p.curToken.Pos}
79-
}
80-
81-
func (p *parser) parseSelfLiteral() Expression {
82-
return &Identifier{Name: "self", position: p.curToken.Pos}
83-
}
84-
8534
func (p *parser) parseYieldExpression() Expression {
8635
pos := p.curToken.Pos
8736
var args []Expression

vibes/parser_literals.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package vibes
2+
3+
import "strconv"
4+
5+
func (p *parser) parseIdentifier() Expression {
6+
return &Identifier{Name: p.curToken.Literal, position: p.curToken.Pos}
7+
}
8+
9+
func (p *parser) parseIntegerLiteral() Expression {
10+
value, err := strconv.ParseInt(p.curToken.Literal, 10, 64)
11+
if err != nil {
12+
p.addParseError(p.curToken.Pos, "invalid integer literal")
13+
return nil
14+
}
15+
return &IntegerLiteral{Value: value, position: p.curToken.Pos}
16+
}
17+
18+
func (p *parser) parseFloatLiteral() Expression {
19+
value, err := strconv.ParseFloat(p.curToken.Literal, 64)
20+
if err != nil {
21+
p.addParseError(p.curToken.Pos, "invalid float literal")
22+
return nil
23+
}
24+
return &FloatLiteral{Value: value, position: p.curToken.Pos}
25+
}
26+
27+
func (p *parser) parseStringLiteral() Expression {
28+
return &StringLiteral{Value: p.curToken.Literal, position: p.curToken.Pos}
29+
}
30+
31+
func (p *parser) parseBooleanLiteral() Expression {
32+
return &BoolLiteral{Value: p.curToken.Type == tokenTrue, position: p.curToken.Pos}
33+
}
34+
35+
func (p *parser) parseNilLiteral() Expression {
36+
return &NilLiteral{position: p.curToken.Pos}
37+
}
38+
39+
func (p *parser) parseSymbolLiteral() Expression {
40+
return &SymbolLiteral{Name: p.curToken.Literal, position: p.curToken.Pos}
41+
}
42+
43+
func (p *parser) parseIvarLiteral() Expression {
44+
return &IvarExpr{Name: p.curToken.Literal, position: p.curToken.Pos}
45+
}
46+
47+
func (p *parser) parseClassVarLiteral() Expression {
48+
return &ClassVarExpr{Name: p.curToken.Literal, position: p.curToken.Pos}
49+
}
50+
51+
func (p *parser) parseSelfLiteral() Expression {
52+
return &Identifier{Name: "self", position: p.curToken.Pos}
53+
}

0 commit comments

Comments
 (0)