Skip to content

Commit

Permalink
Convert the rune array to string during scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsayantan committed Apr 12, 2022
1 parent ec12ffc commit 78f119b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *Parser) Parse() []Stmt {
return nil
}

statements = append(statements,expr)
statements = append(statements, expr)
}

return statements
Expand All @@ -51,8 +51,8 @@ func (p *Parser) statement() (Stmt, error) {
return p.expressionStatement()
}

// printStatement parses a print statement. Since the print keyword is
// already consumed by the match method earlier, we just parse the
// printStatement parses a print statement. Since the print keyword is
// already consumed by the match method earlier, we just parse the
// subsequent expression, consume the terminating semicolon and emit the
// syntax tree.
func (p *Parser) printStatement() (Stmt, error) {
Expand All @@ -69,8 +69,8 @@ func (p *Parser) printStatement() (Stmt, error) {
return &Print{Expression: expr}, nil
}

// expressionStatement parses expression statements. It kind of acts like a
// fallthrough condition. If we can't match with any known statements, we
// expressionStatement parses expression statements. It kind of acts like a
// fallthrough condition. If we can't match with any known statements, we
// assume it's a expression statement.
func (p *Parser) expressionStatement() (Stmt, error) {
expr, err := p.expression()
Expand Down
2 changes: 1 addition & 1 deletion scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (sc *Scanner) scanString() {
// Trim the surrounding quotes and just take the string literal.
val := sc.sourceRunes[sc.start+1 : sc.current-1]

sc.addToken(String, val)
sc.addToken(String, string(val))
}

func (sc *Scanner) scanNumber() {
Expand Down

0 comments on commit 78f119b

Please sign in to comment.