Skip to content

Commit 6922b7e

Browse files
authored
Adjust some parser edge cases (deepnoodle-ai#263)
1 parent 69288f7 commit 6922b7e

File tree

5 files changed

+252
-141
lines changed

5 files changed

+252
-141
lines changed

ast/statements.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (c *Control) String() string {
179179
var out bytes.Buffer
180180
out.WriteString(c.Literal())
181181
if c.value != nil {
182-
out.WriteString(" " + c.value.Literal())
182+
out.WriteString(" " + c.value.String())
183183
}
184184
return out.String()
185185
}
@@ -212,7 +212,7 @@ func (r *Return) String() string {
212212
var out bytes.Buffer
213213
out.WriteString(r.Literal())
214214
if r.value != nil {
215-
out.WriteString(" " + r.value.Literal())
215+
out.WriteString(" " + r.value.String())
216216
}
217217
return out.String()
218218
}

compiler/compiler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (c *Compiler) Compile(node ast.Node) (*Code, error) {
130130
func (c *Compiler) compile(node ast.Node) error {
131131
switch node := node.(type) {
132132
case *ast.Nil:
133-
if err := c.compileNil(node); err != nil {
133+
if err := c.compileNil(); err != nil {
134134
return err
135135
}
136136
case *ast.Int:
@@ -318,7 +318,7 @@ func (c *Compiler) currentPosition() int {
318318
return len(c.current.instructions)
319319
}
320320

321-
func (c *Compiler) compileNil(node *ast.Nil) error {
321+
func (c *Compiler) compileNil() error {
322322
c.emit(op.Nil)
323323
return nil
324324
}
@@ -1412,10 +1412,10 @@ func (c *Compiler) compileFor(node *ast.For) error {
14121412
}
14131413
case *ast.Range:
14141414
return c.compileForRange(node, nil, cond.Container())
1415-
case *ast.Infix:
1415+
case ast.Expression:
14161416
return c.compileForCondition(node, cond)
14171417
default:
1418-
return c.compileForRange(node, nil, cond)
1418+
return fmt.Errorf("compile error: invalid for loop")
14191419
}
14201420
}
14211421

0 commit comments

Comments
 (0)