ga-lang 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ import type { Token } from './token.js';
2
+ export interface Expr {
3
+ accept<T>(visitor: ExprVisitor<T>): T;
4
+ }
5
+ export interface ExprVisitor<T> {
6
+ visitVariableExpr(expr: VariableExpr): T;
7
+ visitLiteralExpr(expr: LiteralExpr): T;
8
+ visitCallExpr(expr: CallExpr): T;
9
+ visitBinaryExpr(expr: BinaryExpr): T;
10
+ }
11
+ export interface Stmt {
12
+ accept<T>(visitor: StmtVisitor<T>): T;
13
+ }
14
+ export interface StmtVisitor<T> {
15
+ visitPrintStmt(stmt: PrintStmt): T;
16
+ visitVarStmt(stmt: VarStmt): T;
17
+ visitFunctionStmt(stmt: FunctionStmt): T;
18
+ visitBlockStmt(stmt: BlockStmt): T;
19
+ visitExpressionStmt(stmt: ExpressionStmt): T;
20
+ visitReturnStmt(stmt: ReturnStmt): T;
21
+ }
22
+ export declare class VariableExpr implements Expr {
23
+ name: Token;
24
+ constructor(name: Token);
25
+ accept<T>(visitor: ExprVisitor<T>): T;
26
+ }
27
+ export declare class LiteralExpr implements Expr {
28
+ value: any;
29
+ constructor(value: any);
30
+ accept<T>(visitor: ExprVisitor<T>): T;
31
+ }
32
+ export declare class CallExpr implements Expr {
33
+ callee: VariableExpr;
34
+ args: Expr[];
35
+ constructor(callee: VariableExpr, args: Expr[]);
36
+ accept<T>(visitor: ExprVisitor<T>): T;
37
+ }
38
+ export declare class BinaryExpr implements Expr {
39
+ left: Expr;
40
+ operator: Token;
41
+ right: Expr;
42
+ constructor(left: Expr, operator: Token, right: Expr);
43
+ accept<T>(visitor: ExprVisitor<T>): T;
44
+ }
45
+ export declare class PrintStmt implements Stmt {
46
+ expression: Expr;
47
+ constructor(expression: Expr);
48
+ accept<T>(visitor: StmtVisitor<T>): T;
49
+ }
50
+ export declare class VarStmt implements Stmt {
51
+ name: Token;
52
+ initializer: Expr | null;
53
+ constructor(name: Token, initializer: Expr | null);
54
+ accept<T>(visitor: StmtVisitor<T>): T;
55
+ }
56
+ export declare class FunctionStmt implements Stmt {
57
+ name: Token;
58
+ params: Token[];
59
+ body: Stmt[];
60
+ constructor(name: Token, params: Token[], body: Stmt[]);
61
+ accept<T>(visitor: StmtVisitor<T>): T;
62
+ }
63
+ export declare class BlockStmt implements Stmt {
64
+ statements: Stmt[];
65
+ constructor(statements: Stmt[]);
66
+ accept<T>(visitor: StmtVisitor<T>): T;
67
+ }
68
+ export declare class ExpressionStmt implements Stmt {
69
+ expression: Expr;
70
+ constructor(expression: Expr);
71
+ accept<T>(visitor: StmtVisitor<T>): T;
72
+ }
73
+ export declare class ReturnStmt implements Stmt {
74
+ value: Expr | null;
75
+ constructor(value: Expr | null);
76
+ accept<T>(visitor: StmtVisitor<T>): T;
77
+ }
@@ -0,0 +1,22 @@
1
+ import { BinaryExpr, FunctionStmt, ReturnStmt, type BlockStmt, type CallExpr, type ExpressionStmt, type ExprVisitor, type LiteralExpr, type PrintStmt, type Stmt, type StmtVisitor, type VariableExpr, type VarStmt } from './ast.js';
2
+ export declare class Interpreter implements ExprVisitor<any>, StmtVisitor<void> {
3
+ private environment;
4
+ interpret(statements: Stmt[]): void;
5
+ private execute;
6
+ visitPrintStmt(stmt: PrintStmt): void;
7
+ private toDevanagariString;
8
+ private numberToDevanagari;
9
+ visitVarStmt(stmt: VarStmt): void;
10
+ visitFunctionStmt(stmt: FunctionStmt): void;
11
+ visitBlockStmt(stmt: BlockStmt): void;
12
+ visitExpressionStmt(stmt: ExpressionStmt): void;
13
+ visitReturnStmt(stmt: ReturnStmt): void;
14
+ visitLiteralExpr(expr: LiteralExpr): any;
15
+ private isDevanagariNumber;
16
+ private devanagariToNumber;
17
+ visitVariableExpr(expr: VariableExpr): any;
18
+ visitCallExpr(expr: CallExpr): any;
19
+ visitBinaryExpr(expr: BinaryExpr): any;
20
+ private toNumber;
21
+ private evaluate;
22
+ }
@@ -0,0 +1,66 @@
1
+ import { Token, TokenKind } from './token.js';
2
+ export declare class Lexer {
3
+ private source;
4
+ private tokens;
5
+ private startPos;
6
+ private currentPos;
7
+ private line;
8
+ constructor(source: string);
9
+ /**
10
+ * Read tokens from source
11
+ */
12
+ readTokens(): Token[];
13
+ /**
14
+ * Read individual lexeme
15
+ */
16
+ readToken(): void;
17
+ /**
18
+ * Read character
19
+ */
20
+ readChar(): string;
21
+ /**
22
+ * Create token out of individual lexeme
23
+ * @param {TokenKind} kind
24
+ * @param {any} literal
25
+ */
26
+ createToken(kind: TokenKind, literal?: any): void;
27
+ /**
28
+ * Check if we've reached the end of file
29
+ */
30
+ private isAtEnd;
31
+ /**
32
+ * Peek next character
33
+ */
34
+ private peekNextChar;
35
+ /**
36
+ * Get next character
37
+ */
38
+ private getNextChar;
39
+ /**
40
+ * Check if the character is devanagari character
41
+ * @param {string} char
42
+ */
43
+ private isDevnagariChar;
44
+ /**
45
+ * Check if the character is devanagari digit
46
+ * @param {string} char
47
+ */
48
+ private isDevanagariDigit;
49
+ /**
50
+ * Check if the character is whitespace
51
+ * @param {string} char
52
+ */
53
+ private isWhitespace;
54
+ /**
55
+ * Read devanagari character sequence as number
56
+ */
57
+ private readDevanagariDigit;
58
+ /**
59
+ * Read devanagari character sequence as identifier
60
+ */
61
+ private readDevanagariIdentifier;
62
+ /**
63
+ * Read string literals
64
+ */
65
+ private readDevanagariString;
66
+ }
@@ -0,0 +1,4 @@
1
+ import { Lexer } from './lexer.js';
2
+ import { Parser } from './parser.js';
3
+ import { Interpreter } from './interpreter.js';
4
+ export { Lexer, Parser, Interpreter };
package/dist/src/main.js CHANGED
@@ -28,3 +28,5 @@ function main() {
28
28
  }
29
29
  }
30
30
  main();
31
+ // Export Lexer, Parser, and Interpreter
32
+ export { Lexer, Parser, Interpreter };
@@ -0,0 +1,28 @@
1
+ import { type Stmt } from './ast.js';
2
+ import { type Token } from './token.js';
3
+ export declare class Parser {
4
+ private tokens;
5
+ private currentPos;
6
+ constructor(tokens: Token[]);
7
+ parse(): Stmt[];
8
+ private parseStmt;
9
+ private parseReturnStmt;
10
+ private parseExpressionStmt;
11
+ private parsePrintStmt;
12
+ private parseVarStmt;
13
+ private parseFunctionStmt;
14
+ private parseBlock;
15
+ private parseExpression;
16
+ private parseAddition;
17
+ private parseMultiplication;
18
+ private parseCall;
19
+ private parsePrimary;
20
+ private match;
21
+ private consume;
22
+ private check;
23
+ private advance;
24
+ private peek;
25
+ private previous;
26
+ private isAtEnd;
27
+ private error;
28
+ }
@@ -0,0 +1,38 @@
1
+ export declare enum TokenKind {
2
+ Eof = "Eof",
3
+ Illegal = "Illegal",
4
+ Comma = "Comma",
5
+ Colon = "Colon",
6
+ Period = "Period",
7
+ Semicolon = "Semicolon",
8
+ OpenParen = "OpenParen",
9
+ CloseParen = "CloseParen",
10
+ OpenCurly = "OpenCurly",
11
+ CloseCurly = "CloseCurly",
12
+ Plus = "Plus",
13
+ Minus = "Minus",
14
+ Star = "Star",
15
+ Slash = "Slash",
16
+ Mod = "Mod",
17
+ Bang = "Bang",
18
+ Equal = "Equal",
19
+ Number = "Number",
20
+ Character = "Character",
21
+ String = "String",
22
+ Identifier = "Identifier",
23
+ Let = "Let",
24
+ Function = "Function",
25
+ Print = "Print",
26
+ Return = "Return",
27
+ If = "If",
28
+ Else = "Else",
29
+ True = "True",
30
+ False = "False"
31
+ }
32
+ export declare const keywords: Record<string, TokenKind>;
33
+ export declare class Token {
34
+ kind: TokenKind;
35
+ lexeme: string;
36
+ line: number;
37
+ constructor(kind: TokenKind, lexeme: string, line: number);
38
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "ga-lang",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "An interpreted toy programming language",
5
5
  "type": "module",
6
- "main": "dist/main.js",
6
+ "main": "dist/src/main.js",
7
+ "types": "dist/src/main.d.ts",
7
8
  "bin": {
8
9
  "ga": "./bin/ga.js"
9
10
  },
@@ -12,12 +13,13 @@
12
13
  "prettier:fix": "prettier --write \"./**/*.{js,ts,json}\"",
13
14
  "clean": "rm -rf dist",
14
15
  "build": "pnpm run clean && tsc",
15
- "test": "pnpm run build && node --test ./dist/tests/**/*.js",
16
+ "build:tests": "tsc -p tsconfig.test.json",
17
+ "test": "pnpm run build && pnpm run build:tests && node --test ./dist/tests/**/*.js",
16
18
  "ga": "pnpm run build && node dist/src/main.js"
17
19
  },
18
20
  "repository": {
19
21
  "type": "git",
20
- "url": "git+https://github.com/bvsvntv/ga.git"
22
+ "url": "git+https://github.com/bvsvntv/ga-lang.git"
21
23
  },
22
24
  "keywords": [
23
25
  "devanagari",
@@ -28,14 +30,17 @@
28
30
  "author": "Basanta Rai",
29
31
  "license": "MIT",
30
32
  "bugs": {
31
- "url": "https://github.com/bvsvntv/ga/issues"
33
+ "url": "https://github.com/bvsvntv/ga-lang/issues"
32
34
  },
33
- "homepage": "https://github.com/bvsvntv/ga#readme",
35
+ "homepage": "https://github.com/bvsvntv/ga-lang#readme",
34
36
  "packageManager": "pnpm@10.25.0",
35
37
  "engines": {
36
38
  "node": ">=22.x.x",
37
39
  "pnpm": ">=10.x.x"
38
40
  },
41
+ "exports": {
42
+ ".": "./dist/src/main.js"
43
+ },
39
44
  "devEngines": {
40
45
  "runtime": {
41
46
  "name": "node",
package/src/main.ts CHANGED
@@ -36,3 +36,6 @@ function main(): void {
36
36
  }
37
37
 
38
38
  main();
39
+
40
+ // Export Lexer, Parser, and Interpreter
41
+ export { Lexer, Parser, Interpreter };
package/tsconfig.json CHANGED
@@ -9,6 +9,7 @@
9
9
  "moduleDetection": "force",
10
10
  "isolatedModules": true,
11
11
  "verbatimModuleSyntax": true,
12
+ "declaration": true,
12
13
 
13
14
  /* Strictness */
14
15
  "strict": true,
@@ -20,6 +21,6 @@
20
21
  "rootDir": ".",
21
22
  "outDir": "./dist"
22
23
  },
23
- "include": ["src/**/*.ts", "tests/**/*.test.ts"],
24
+ "include": ["src/**/*.ts"],
24
25
  "exclude": ["node_modules", "dist"]
25
26
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": false,
5
+ "noEmit": false,
6
+ "outDir": "./dist"
7
+ },
8
+ "include": ["tests/**/*.ts", "src/**/*.ts"]
9
+ }