Skip to content

Commit a1a282d

Browse files
committed
fixing issue with ParseProgram returning multiple values
1 parent 10cc9ce commit a1a282d

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

compiler/compiler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/dfirebaugh/punch/emitters/wat"
66
"github.com/dfirebaugh/punch/lexer"
77
"github.com/dfirebaugh/punch/parser"
8+
"github.com/sirupsen/logrus"
89
)
910

1011
const (
@@ -15,7 +16,11 @@ const (
1516
func Compile(filename string, source string) (string, []byte, string) {
1617
l := lexer.New(filename, source)
1718
p := parser.New(l)
18-
program := p.ParseProgram(filename)
19+
program, err := p.ParseProgram(filename)
20+
if err != nil {
21+
logrus.Error(err)
22+
return "", nil, ""
23+
}
1924
var ast string
2025
wat := wat.GenerateWAT(program, true)
2126
if !astDisabled {

examples/struct.pun

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
pkg main
22

3+
import (
4+
5+
)
6+
37
struct extra {
48
str note
59
}
@@ -39,5 +43,21 @@ fn send_message() {
3943
println(msg.other.extra.note)
4044
}
4145

42-
send_message()
4346

47+
message get_message() {
48+
message msg = message {
49+
sender: 2,
50+
receiver: 4,
51+
body: "hello, world",
52+
other: other {
53+
message: "hello",
54+
extra: extra {
55+
note: "this is extra info",
56+
},
57+
},
58+
}
59+
return msg
60+
}
61+
62+
message msg = get_message()
63+
println(msg)

parser/parsers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (p *Parser) parseIfStatement() (*ast.IfStatement, error) {
315315
}
316316

317317
if !p.expectCurrentTokenIs(token.LBRACE) {
318-
return nil, p.errorf("expecting current token is a '{'", p.curToken.Literal, p.peekToken.Literal)
318+
return nil, p.error("expecting current token is a '{'", p.curToken.Literal, p.peekToken.Literal)
319319
}
320320
stmt.Consequence, err = p.parseBlockStatement()
321321
if err != nil {

repl/repl.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ func (repl *REPL) handleLine(line string) bool {
6767
fmt.Fprintf(repl.out, "Command entered: %s\n", line)
6868
l := lexer.New("repl", line)
6969
p := parser.New(l)
70-
program := p.ParseProgram("repl")
70+
program, err := p.ParseProgram("repl")
71+
if err != nil {
72+
println(err.Error())
73+
return true
74+
}
7175

7276
println("ast:")
7377
json, err := program.JSONPretty()

0 commit comments

Comments
 (0)