@robinpath/robinpath 0.30.0
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.
- package/README.md +856 -0
- package/bin/robinpath.js +374 -0
- package/dist/classes/ASTSerializer.d.ts +45 -0
- package/dist/classes/ExecutionStateTracker.d.ts +30 -0
- package/dist/classes/Executor.d.ts +193 -0
- package/dist/classes/ExpressionEvaluator.d.ts +20 -0
- package/dist/classes/Lexer.d.ts +86 -0
- package/dist/classes/Parser.d.ts +71 -0
- package/dist/classes/RobinPathThread.d.ts +146 -0
- package/dist/classes/TokenStream.d.ts +217 -0
- package/dist/classes/code-converter/ASTToCodeConverter.d.ts +178 -0
- package/dist/classes/code-converter/LineIndex.d.ts +54 -0
- package/dist/classes/code-converter/Printer.d.ts +117 -0
- package/dist/classes/code-converter/Writer.d.ts +42 -0
- package/dist/classes/code-converter/index.d.ts +8 -0
- package/dist/classes/code-converter/types.d.ts +29 -0
- package/dist/classes/exceptions.d.ts +26 -0
- package/dist/classes/index.d.ts +16 -0
- package/dist/index.d.ts +485 -0
- package/dist/index.js +13808 -0
- package/dist/modules/Array.d.ts +10 -0
- package/dist/modules/Core.d.ts +10 -0
- package/dist/modules/Dom.d.ts +10 -0
- package/dist/modules/Fetch.d.ts +6 -0
- package/dist/modules/Json.d.ts +10 -0
- package/dist/modules/Math.d.ts +10 -0
- package/dist/modules/Object.d.ts +10 -0
- package/dist/modules/Random.d.ts +6 -0
- package/dist/modules/String.d.ts +10 -0
- package/dist/modules/Test.d.ts +10 -0
- package/dist/modules/Time.d.ts +10 -0
- package/dist/parsers/ArrayLiteralParser.d.ts +17 -0
- package/dist/parsers/AssignmentParser.d.ts +37 -0
- package/dist/parsers/BracketParser.d.ts +31 -0
- package/dist/parsers/BreakParser.d.ts +15 -0
- package/dist/parsers/CellBlockParser.d.ts +11 -0
- package/dist/parsers/ChunkMarkerParser.d.ts +12 -0
- package/dist/parsers/CommandParser.d.ts +56 -0
- package/dist/parsers/CommentParser.d.ts +37 -0
- package/dist/parsers/ContinueParser.d.ts +15 -0
- package/dist/parsers/DecoratorParser.d.ts +29 -0
- package/dist/parsers/DefineParser.d.ts +18 -0
- package/dist/parsers/EventParser.d.ts +17 -0
- package/dist/parsers/ExpressionParser.d.ts +3 -0
- package/dist/parsers/FenceClassifier.d.ts +29 -0
- package/dist/parsers/ForLoopParser.d.ts +17 -0
- package/dist/parsers/IfBlockParser.d.ts +17 -0
- package/dist/parsers/ObjectLiteralParser.d.ts +17 -0
- package/dist/parsers/ParserUtils.d.ts +15 -0
- package/dist/parsers/PromptBlockParser.d.ts +10 -0
- package/dist/parsers/ReturnParser.d.ts +16 -0
- package/dist/parsers/ScopeParser.d.ts +24 -0
- package/dist/parsers/StringTemplateParser.d.ts +31 -0
- package/dist/parsers/SubexpressionParser.d.ts +33 -0
- package/dist/parsers/TogetherBlockParser.d.ts +18 -0
- package/dist/parsers/WithScopeParser.d.ts +24 -0
- package/dist/types/Ast.type.d.ts +455 -0
- package/dist/types/Environment.type.d.ts +53 -0
- package/dist/utils/args.d.ts +24 -0
- package/dist/utils/errorFormatter.d.ts +22 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/stringParsing.d.ts +41 -0
- package/dist/utils/types.d.ts +15 -0
- package/dist/utils/valueConversion.d.ts +25 -0
- package/package.json +50 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LineIndex - Fast row/col → offset conversion
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* LineIndex interface for fast row/col → offset conversion
|
|
6
|
+
*/
|
|
7
|
+
export interface LineIndex {
|
|
8
|
+
offsetAt(row: number, col: number, exclusive?: boolean): number;
|
|
9
|
+
lineEndOffset(row: number): number;
|
|
10
|
+
hasNewline(row: number): boolean;
|
|
11
|
+
getLine(row: number): string;
|
|
12
|
+
getLines(): string[];
|
|
13
|
+
lineCount(): number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* LineIndex implementation - Fast row/col → offset conversion
|
|
17
|
+
*
|
|
18
|
+
* Build once per originalScript. Provides O(1) offset conversion
|
|
19
|
+
* by pre-computing line-start offsets.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LineIndexImpl implements LineIndex {
|
|
22
|
+
private readonly lineStartOffsets;
|
|
23
|
+
private readonly lines;
|
|
24
|
+
private readonly originalScript;
|
|
25
|
+
constructor(originalScript: string);
|
|
26
|
+
/**
|
|
27
|
+
* Convert row/column to character offset
|
|
28
|
+
* @param row Zero-based row number
|
|
29
|
+
* @param col Zero-based column number
|
|
30
|
+
* @param exclusive If true, return offset one past the column (for end positions)
|
|
31
|
+
* @returns Character offset in the script string
|
|
32
|
+
*/
|
|
33
|
+
offsetAt(row: number, col: number, exclusive?: boolean): number;
|
|
34
|
+
/**
|
|
35
|
+
* Get the offset at the end of a line (after the newline)
|
|
36
|
+
*/
|
|
37
|
+
lineEndOffset(row: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a line has a newline character
|
|
40
|
+
*/
|
|
41
|
+
hasNewline(row: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get the text content of a specific line
|
|
44
|
+
*/
|
|
45
|
+
getLine(row: number): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get all lines as an array
|
|
48
|
+
*/
|
|
49
|
+
getLines(): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Get the total number of lines
|
|
52
|
+
*/
|
|
53
|
+
lineCount(): number;
|
|
54
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { PrintContext, CommentWithPosition } from './types';
|
|
2
|
+
import { Value } from '../../utils/types';
|
|
3
|
+
import { Statement } from '../../types/Ast.type';
|
|
4
|
+
import { Writer } from './Writer';
|
|
5
|
+
/**
|
|
6
|
+
* Printer class - AST → string conversion
|
|
7
|
+
*
|
|
8
|
+
* Pure function(s), no access to originalScript.
|
|
9
|
+
* Uses a Writer to avoid heavy string concatenations.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Printer {
|
|
12
|
+
private static printersRegistry;
|
|
13
|
+
/**
|
|
14
|
+
* Print a statement node to code
|
|
15
|
+
*/
|
|
16
|
+
static printNode(node: Statement, ctx: PrintContext): string;
|
|
17
|
+
/**
|
|
18
|
+
* Print a comment
|
|
19
|
+
*/
|
|
20
|
+
static printComment(comment: CommentWithPosition, indentLevel?: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get value type
|
|
23
|
+
*/
|
|
24
|
+
static getValueType(value: Value): 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array';
|
|
25
|
+
/**
|
|
26
|
+
* Convert value type
|
|
27
|
+
*/
|
|
28
|
+
static convertValueType(value: Value, targetType: 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array'): Value | null;
|
|
29
|
+
/**
|
|
30
|
+
* Print argument/expression code
|
|
31
|
+
*/
|
|
32
|
+
static printArg(arg: any, _ctx: PrintContext): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Print a variable reference
|
|
35
|
+
*/
|
|
36
|
+
static printVarRef(name: string, path?: any[]): string;
|
|
37
|
+
/**
|
|
38
|
+
* Print an into target
|
|
39
|
+
*/
|
|
40
|
+
static printIntoTarget(targetName: string, targetPath?: any[]): string;
|
|
41
|
+
/**
|
|
42
|
+
* Print assignment node
|
|
43
|
+
*/
|
|
44
|
+
static printAssignment(node: any, writer: Writer, ctx: PrintContext): void;
|
|
45
|
+
/**
|
|
46
|
+
* Print cell block node
|
|
47
|
+
*/
|
|
48
|
+
static printCellBlock(node: any, writer: Writer, ctx: PrintContext): void;
|
|
49
|
+
/**
|
|
50
|
+
* Print chunk marker node
|
|
51
|
+
*/
|
|
52
|
+
static printChunkMarker(node: any, writer: Writer, _ctx: PrintContext): void;
|
|
53
|
+
/**
|
|
54
|
+
* Print command node
|
|
55
|
+
*/
|
|
56
|
+
static printCommand(node: any, writer: Writer, ctx: PrintContext): void;
|
|
57
|
+
/**
|
|
58
|
+
* Print a comment node
|
|
59
|
+
*/
|
|
60
|
+
static printCommentNode(node: any, writer: Writer, _ctx: PrintContext): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get leading comments from a statement node.
|
|
63
|
+
*/
|
|
64
|
+
private static getLeadingComments;
|
|
65
|
+
/**
|
|
66
|
+
* Get inline comment from a statement node.
|
|
67
|
+
*/
|
|
68
|
+
static getInlineComment(stmt: any): CommentWithPosition | null;
|
|
69
|
+
/**
|
|
70
|
+
* Format an inline comment as a string to append to a line.
|
|
71
|
+
*/
|
|
72
|
+
static formatInlineComment(comment: CommentWithPosition | null): string;
|
|
73
|
+
/**
|
|
74
|
+
* Emit decorators for a node if they exist.
|
|
75
|
+
*/
|
|
76
|
+
private static emitDecorators;
|
|
77
|
+
/**
|
|
78
|
+
* Emit leading comments for a statement, preserving blank lines between them.
|
|
79
|
+
*/
|
|
80
|
+
static emitLeadingComments(stmt: any, writer: Writer, _ctx: PrintContext, indentLevel: number): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Check if there's a blank line gap between the last comment and a statement.
|
|
83
|
+
*/
|
|
84
|
+
static emitBlankLineAfterComments(stmt: any, writer: Writer): void;
|
|
85
|
+
/**
|
|
86
|
+
* Check if there's a blank line gap between two statements.
|
|
87
|
+
*/
|
|
88
|
+
static emitBlankLineBetweenStatements(prevStmt: any, currentStmt: any, writer: Writer): void;
|
|
89
|
+
/**
|
|
90
|
+
* Print define (function definition) node
|
|
91
|
+
*/
|
|
92
|
+
static printDefine(node: any, writer: Writer, ctx: PrintContext): void;
|
|
93
|
+
/**
|
|
94
|
+
* Print do block node
|
|
95
|
+
*/
|
|
96
|
+
static printDo(node: any, writer: Writer, ctx: PrintContext): void;
|
|
97
|
+
/**
|
|
98
|
+
* Print for loop node
|
|
99
|
+
*/
|
|
100
|
+
static printForLoop(node: any, writer: Writer, ctx: PrintContext): void;
|
|
101
|
+
/**
|
|
102
|
+
* Print ifBlock node
|
|
103
|
+
*/
|
|
104
|
+
static printIfBlock(node: any, writer: Writer, ctx: PrintContext): void;
|
|
105
|
+
/**
|
|
106
|
+
* Print on block node
|
|
107
|
+
*/
|
|
108
|
+
static printOnBlock(node: any, writer: Writer, ctx: PrintContext): void;
|
|
109
|
+
/**
|
|
110
|
+
* Print prompt block node
|
|
111
|
+
*/
|
|
112
|
+
static printPromptBlock(node: any, writer: Writer, _ctx: PrintContext): void;
|
|
113
|
+
/**
|
|
114
|
+
* Print together block node
|
|
115
|
+
*/
|
|
116
|
+
static printTogether(node: any, writer: Writer, ctx: PrintContext): void;
|
|
117
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writer - Efficient string building for code generation
|
|
3
|
+
*
|
|
4
|
+
* Avoids repeated string concatenation by using an array-based approach.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Writer {
|
|
7
|
+
private parts;
|
|
8
|
+
private currentIndent;
|
|
9
|
+
private indentString;
|
|
10
|
+
/**
|
|
11
|
+
* Push a string to the output
|
|
12
|
+
*/
|
|
13
|
+
push(text: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Push a newline
|
|
16
|
+
*/
|
|
17
|
+
newline(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Set the indentation level
|
|
20
|
+
*/
|
|
21
|
+
indent(level: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Push text with current indentation
|
|
24
|
+
*/
|
|
25
|
+
pushIndented(text: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Push a line with current indentation
|
|
28
|
+
*/
|
|
29
|
+
pushLine(text: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Push a blank line
|
|
32
|
+
*/
|
|
33
|
+
pushBlankLine(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the final string
|
|
36
|
+
*/
|
|
37
|
+
toString(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Clear all content
|
|
40
|
+
*/
|
|
41
|
+
clear(): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Converter Module - Exports
|
|
3
|
+
*/
|
|
4
|
+
export { ASTToCodeConverter, PatchPlanner, PatchApplier, CommentLayoutNormalizer } from './ASTToCodeConverter';
|
|
5
|
+
export { Writer } from './Writer';
|
|
6
|
+
export { LineIndexImpl } from './LineIndex';
|
|
7
|
+
export { Printer } from './Printer';
|
|
8
|
+
export type { Patch, CommentLayout, PrintContext, LineIndex, CommentWithPosition } from './types';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CommentWithPosition } from '../../types/Ast.type';
|
|
2
|
+
import { LineIndex } from './LineIndex';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a patch operation to apply to source code
|
|
5
|
+
*/
|
|
6
|
+
export interface Patch {
|
|
7
|
+
startOffset: number;
|
|
8
|
+
endOffset: number;
|
|
9
|
+
replacement: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Comment layout information for a statement
|
|
13
|
+
*/
|
|
14
|
+
export interface CommentLayout {
|
|
15
|
+
leadingComments: CommentWithPosition[];
|
|
16
|
+
inlineComment: CommentWithPosition | null;
|
|
17
|
+
leadingGapLines: number;
|
|
18
|
+
trailingBlankLinesAfterStandaloneComment: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Context for printing AST nodes
|
|
22
|
+
*/
|
|
23
|
+
export interface PrintContext {
|
|
24
|
+
indentLevel: number;
|
|
25
|
+
lineIndex: LineIndex;
|
|
26
|
+
originalScript?: string;
|
|
27
|
+
allowExtractOriginalCode?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export type { CommentWithPosition, LineIndex };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Value } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Special exception used to signal early return from functions or global scope
|
|
4
|
+
*/
|
|
5
|
+
export declare class ReturnException extends Error {
|
|
6
|
+
value: Value;
|
|
7
|
+
constructor(value: Value);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Special exception used to signal break from loops
|
|
11
|
+
*/
|
|
12
|
+
export declare class BreakException extends Error {
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Special exception used to signal continue to next iteration of loops
|
|
17
|
+
*/
|
|
18
|
+
export declare class ContinueException extends Error {
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Special exception used to signal end of script execution
|
|
23
|
+
*/
|
|
24
|
+
export declare class EndException extends Error {
|
|
25
|
+
constructor();
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel export for all RobinPath classes
|
|
3
|
+
*/
|
|
4
|
+
export { Lexer, TokenKind, KEYWORDS } from './Lexer';
|
|
5
|
+
export type { Token, SourcePosition } from './Lexer';
|
|
6
|
+
export { TokenStream } from './TokenStream';
|
|
7
|
+
export { Parser } from './Parser';
|
|
8
|
+
export { ExpressionEvaluator } from './ExpressionEvaluator';
|
|
9
|
+
export { Executor } from './Executor';
|
|
10
|
+
export { ExecutionStateTracker } from './ExecutionStateTracker';
|
|
11
|
+
export type { ExecutionLog, ExecutionStepInfo, LogCallback } from './ExecutionStateTracker';
|
|
12
|
+
export { ReturnException, BreakException, EndException } from './exceptions';
|
|
13
|
+
export { RobinPathThread } from './RobinPathThread';
|
|
14
|
+
export { ASTSerializer } from './ASTSerializer';
|
|
15
|
+
export { ASTToCodeConverter, Printer, LineIndexImpl } from './code-converter';
|
|
16
|
+
export type { PrintContext, LineIndex } from './code-converter';
|