optimizations
Some checks failed
Build / build (push) Successful in 9m47s
Publish Image / publish (push) Failing after 49s
Test / build (push) Failing after 6m19s

This commit is contained in:
Chuck Smith
2024-04-02 14:32:03 -04:00
parent 07fd82b261
commit 88e3330856
18 changed files with 510 additions and 31 deletions

View File

@@ -82,6 +82,7 @@ func New(fn string, l *lexer.Lexer) *Parser {
p.prefixParseFns = make(map[token.TokenType]prefixParseFn)
p.registerPrefix(token.IDENT, p.parseIdentifier)
p.registerPrefix(token.INT, p.parseIntegerLiteral)
p.registerPrefix(token.FLOAT, p.parseFloatLiteral)
p.registerPrefix(token.MINUS, p.parsePrefixExpression)
p.registerPrefix(token.TRUE, p.parseBoolean)
p.registerPrefix(token.FALSE, p.parseBoolean)
@@ -622,6 +623,21 @@ func (p *Parser) parseImportExpression() ast.Expression {
return expression
}
func (p *Parser) parseFloatLiteral() ast.Expression {
lit := &ast.FloatLiteral{Token: p.curToken}
value, err := strconv.ParseFloat(p.curToken.Literal, 64)
if err != nil {
msg := fmt.Sprintf("could not parse %q as float", p.curToken.Literal)
p.errors = append(p.errors, msg)
return nil
}
lit.Value = value
return lit
}
// Parse parses the input source into a top-level AST for either evaluation
// or compilation to bytecode. The parameter fn denotes the filename the source
// originated from.