@boenfu/tsmonkey
v0.1.0
Published
```bash npm install @boenfu/tsmonkey ```
Downloads
2
Readme
🐒 TSMonkey
npm install @boenfu/tsmonkey
Eval
import type { Eval } from '@boenfu/tsmonkey'
Eval<'4 + 8'> // 12
Eval<'2 * (4 + 8)'> // 24
Eval<'!99'> // false
Eval<'(3 + 2) * 5 == 25'> // true
Eval<'(3 > 2) != (2 > 3)'> // true
Eval<'7 && 9'> // 9
Eval<'false || 0'> // 0
variable declaration
Eval<`
let a = 2
let b = 3
let c = a * b
c * c
`> // 36
if else
Eval<`
let a = 2
let b = 3
if(a >= b) {
return "a is greater than b"
} else {
return "a is less than b"
}
`> // "a is less than b"
function
Eval<`
let a = 5
let b = 10
function foo(a, b) {
return a - b
}
foo(b, a)
`> // 5
fibonacci
Eval<`
function fibonacci(n) {
if (n < 2) { return 0 }
if (n == 2) { return 1 }
return fibonacci(n-1) + fibonacci(n - 2)
}
fibonacci(6)
`> // 5
Parser
import type { Parser } from '@boenfu/tsmonkey'
Parser<'let a = "如果你要写年"'>
// Program<[LetStatement<Identifier<"a">, StringLiteral<"如果你要写年">>]>
Lexer
import type { Lexer } from '@boenfu/tsmonkey'
Lexer<'let a = "如果你要写年"'>
// [
// Token<TokenType.LET, "let">,
// Token<TokenType.IDENT, "a">,
// Token<TokenType.ASSIGN, "=">,
// Token<TokenType.STRING, "如果你要写年">,
// Token<TokenType.EOF, "">
// ]