Skip to content

Commit 5e217a4

Browse files
committed
extract function modifier declaration parsers
1 parent 9536ed0 commit 5e217a4

3 files changed

Lines changed: 54 additions & 52 deletions

File tree

docs/architecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Key files:
7575
- `vibes/parser_statements.go` (statement dispatch + return/raise/block parsing)
7676
- `vibes/parser_expression_statements.go` (expression/assert/assignment statement parsing)
7777
- `vibes/parser_declarations.go` (function/class declaration parsing)
78+
- `vibes/parser_function_modifiers.go` (top-level `export`/`private` function declaration parsing)
7879
- `vibes/parser_declaration_helpers.go` (parameter list and property declaration parsing)
7980
- `vibes/parser_control.go` (if/loop/begin-rescue-ensure parsing)
8081
- `vibes/parser_precedence.go` (precedence table + assignable-expression helpers)

vibes/parser_declarations.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,58 +78,6 @@ func (p *parser) parseFunctionStatement() Statement {
7878
return &FunctionStmt{Name: name, Params: params, ReturnTy: returnTy, Body: body, IsClassMethod: isClassMethod, Private: private, position: pos}
7979
}
8080

81-
func (p *parser) parseExportStatement() Statement {
82-
pos := p.curToken.Pos
83-
if p.insideClass || p.statementNesting > 0 {
84-
p.addParseError(pos, "export is only supported for top-level functions")
85-
return nil
86-
}
87-
if !p.expectPeek(tokenDef) {
88-
return nil
89-
}
90-
fnStmt := p.parseFunctionStatement()
91-
if fnStmt == nil {
92-
return nil
93-
}
94-
fn, ok := fnStmt.(*FunctionStmt)
95-
if !ok {
96-
p.addParseError(pos, "export expects a function definition")
97-
return nil
98-
}
99-
if fn.IsClassMethod {
100-
p.addParseError(pos, "export cannot be used with class methods")
101-
return nil
102-
}
103-
fn.Exported = true
104-
return fn
105-
}
106-
107-
func (p *parser) parsePrivateStatement() Statement {
108-
pos := p.curToken.Pos
109-
if p.insideClass || p.statementNesting > 0 {
110-
p.addParseError(pos, "private is only supported for top-level functions and class methods")
111-
return nil
112-
}
113-
if !p.expectPeek(tokenDef) {
114-
return nil
115-
}
116-
fnStmt := p.parseFunctionStatement()
117-
if fnStmt == nil {
118-
return nil
119-
}
120-
fn, ok := fnStmt.(*FunctionStmt)
121-
if !ok {
122-
p.addParseError(pos, "private expects a function definition")
123-
return nil
124-
}
125-
if fn.IsClassMethod {
126-
p.addParseError(pos, "private cannot be used with class methods")
127-
return nil
128-
}
129-
fn.Private = true
130-
return fn
131-
}
132-
13381
func (p *parser) parseClassStatement() Statement {
13482
pos := p.curToken.Pos
13583
if !p.expectPeek(tokenIdent) {

vibes/parser_function_modifiers.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package vibes
2+
3+
func (p *parser) parseExportStatement() Statement {
4+
pos := p.curToken.Pos
5+
if p.insideClass || p.statementNesting > 0 {
6+
p.addParseError(pos, "export is only supported for top-level functions")
7+
return nil
8+
}
9+
if !p.expectPeek(tokenDef) {
10+
return nil
11+
}
12+
fnStmt := p.parseFunctionStatement()
13+
if fnStmt == nil {
14+
return nil
15+
}
16+
fn, ok := fnStmt.(*FunctionStmt)
17+
if !ok {
18+
p.addParseError(pos, "export expects a function definition")
19+
return nil
20+
}
21+
if fn.IsClassMethod {
22+
p.addParseError(pos, "export cannot be used with class methods")
23+
return nil
24+
}
25+
fn.Exported = true
26+
return fn
27+
}
28+
29+
func (p *parser) parsePrivateStatement() Statement {
30+
pos := p.curToken.Pos
31+
if p.insideClass || p.statementNesting > 0 {
32+
p.addParseError(pos, "private is only supported for top-level functions and class methods")
33+
return nil
34+
}
35+
if !p.expectPeek(tokenDef) {
36+
return nil
37+
}
38+
fnStmt := p.parseFunctionStatement()
39+
if fnStmt == nil {
40+
return nil
41+
}
42+
fn, ok := fnStmt.(*FunctionStmt)
43+
if !ok {
44+
p.addParseError(pos, "private expects a function definition")
45+
return nil
46+
}
47+
if fn.IsClassMethod {
48+
p.addParseError(pos, "private cannot be used with class methods")
49+
return nil
50+
}
51+
fn.Private = true
52+
return fn
53+
}

0 commit comments

Comments
 (0)