Skip to content

Commit

Permalink
Fix comments and add math constant names (#36)
Browse files Browse the repository at this point in the history
* Fix comments that break functions

* Update resolver.ts with math constant names
  • Loading branch information
JJtan2002 authored Apr 15, 2024
1 parent 80f18e8 commit 2b27d77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,16 @@ export class Resolver implements StmtNS.Visitor<void>, ExprNS.Visitor<void> {
["None", new Token(TokenType.NAME, "None", 0, 0, 0)],
["NaN", new Token(TokenType.NAME, "NaN", 0, 0, 0)],
["Infinity", new Token(TokenType.NAME, "Infinity", 0, 0, 0)],


// math constants
["math_pi", new Token(TokenType.NAME, "math_pi", 0, 0, 0)],
["math_e", new Token(TokenType.NAME, "math_e", 0, 0, 0)],
["math_ln10", new Token(TokenType.NAME, "math_ln10", 0, 0, 0)],
["math_ln2", new Token(TokenType.NAME, "math_ln2", 0, 0, 0)],
["math_log10e", new Token(TokenType.NAME, "math_log10e", 0, 0, 0)],
["math_sqrt1_2", new Token(TokenType.NAME, "math_sqrt1_2", 0, 0, 0)],
["math_sqrt2", new Token(TokenType.NAME, "math_sqrt2", 0, 0, 0)],

// math library
["math_abs", new Token(TokenType.NAME, "math_abs", 0, 0, 0)],
["math_acos", new Token(TokenType.NAME, "math_acos", 0, 0, 0)],
Expand Down
6 changes: 6 additions & 0 deletions src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ export class Tokenizer {
// Consume the rest of the line's leading whitespace.
this.advance();
}
// Handles comments
if (this.peek() === "#") {
while ((this.peek() !== '\n' && this.peek() !== '\r') && !this.isAtEnd()) {
this.advance();
}
}
// The following block handles things like
/*
def foo():
Expand Down

0 comments on commit 2b27d77

Please sign in to comment.