Skip to content

Commit 2b27d77

Browse files
authored
Fix comments and add math constant names (#36)
* Fix comments that break functions * Update resolver.ts with math constant names
1 parent 80f18e8 commit 2b27d77

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/resolver.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,16 @@ export class Resolver implements StmtNS.Visitor<void>, ExprNS.Visitor<void> {
151151
["None", new Token(TokenType.NAME, "None", 0, 0, 0)],
152152
["NaN", new Token(TokenType.NAME, "NaN", 0, 0, 0)],
153153
["Infinity", new Token(TokenType.NAME, "Infinity", 0, 0, 0)],
154-
154+
155+
// math constants
156+
["math_pi", new Token(TokenType.NAME, "math_pi", 0, 0, 0)],
157+
["math_e", new Token(TokenType.NAME, "math_e", 0, 0, 0)],
158+
["math_ln10", new Token(TokenType.NAME, "math_ln10", 0, 0, 0)],
159+
["math_ln2", new Token(TokenType.NAME, "math_ln2", 0, 0, 0)],
160+
["math_log10e", new Token(TokenType.NAME, "math_log10e", 0, 0, 0)],
161+
["math_sqrt1_2", new Token(TokenType.NAME, "math_sqrt1_2", 0, 0, 0)],
162+
["math_sqrt2", new Token(TokenType.NAME, "math_sqrt2", 0, 0, 0)],
163+
155164
// math library
156165
["math_abs", new Token(TokenType.NAME, "math_abs", 0, 0, 0)],
157166
["math_acos", new Token(TokenType.NAME, "math_acos", 0, 0, 0)],

src/tokenizer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ export class Tokenizer {
403403
// Consume the rest of the line's leading whitespace.
404404
this.advance();
405405
}
406+
// Handles comments
407+
if (this.peek() === "#") {
408+
while ((this.peek() !== '\n' && this.peek() !== '\r') && !this.isAtEnd()) {
409+
this.advance();
410+
}
411+
}
406412
// The following block handles things like
407413
/*
408414
def foo():

0 commit comments

Comments
 (0)