@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.
Files changed (65) hide show
  1. package/README.md +856 -0
  2. package/bin/robinpath.js +374 -0
  3. package/dist/classes/ASTSerializer.d.ts +45 -0
  4. package/dist/classes/ExecutionStateTracker.d.ts +30 -0
  5. package/dist/classes/Executor.d.ts +193 -0
  6. package/dist/classes/ExpressionEvaluator.d.ts +20 -0
  7. package/dist/classes/Lexer.d.ts +86 -0
  8. package/dist/classes/Parser.d.ts +71 -0
  9. package/dist/classes/RobinPathThread.d.ts +146 -0
  10. package/dist/classes/TokenStream.d.ts +217 -0
  11. package/dist/classes/code-converter/ASTToCodeConverter.d.ts +178 -0
  12. package/dist/classes/code-converter/LineIndex.d.ts +54 -0
  13. package/dist/classes/code-converter/Printer.d.ts +117 -0
  14. package/dist/classes/code-converter/Writer.d.ts +42 -0
  15. package/dist/classes/code-converter/index.d.ts +8 -0
  16. package/dist/classes/code-converter/types.d.ts +29 -0
  17. package/dist/classes/exceptions.d.ts +26 -0
  18. package/dist/classes/index.d.ts +16 -0
  19. package/dist/index.d.ts +485 -0
  20. package/dist/index.js +13808 -0
  21. package/dist/modules/Array.d.ts +10 -0
  22. package/dist/modules/Core.d.ts +10 -0
  23. package/dist/modules/Dom.d.ts +10 -0
  24. package/dist/modules/Fetch.d.ts +6 -0
  25. package/dist/modules/Json.d.ts +10 -0
  26. package/dist/modules/Math.d.ts +10 -0
  27. package/dist/modules/Object.d.ts +10 -0
  28. package/dist/modules/Random.d.ts +6 -0
  29. package/dist/modules/String.d.ts +10 -0
  30. package/dist/modules/Test.d.ts +10 -0
  31. package/dist/modules/Time.d.ts +10 -0
  32. package/dist/parsers/ArrayLiteralParser.d.ts +17 -0
  33. package/dist/parsers/AssignmentParser.d.ts +37 -0
  34. package/dist/parsers/BracketParser.d.ts +31 -0
  35. package/dist/parsers/BreakParser.d.ts +15 -0
  36. package/dist/parsers/CellBlockParser.d.ts +11 -0
  37. package/dist/parsers/ChunkMarkerParser.d.ts +12 -0
  38. package/dist/parsers/CommandParser.d.ts +56 -0
  39. package/dist/parsers/CommentParser.d.ts +37 -0
  40. package/dist/parsers/ContinueParser.d.ts +15 -0
  41. package/dist/parsers/DecoratorParser.d.ts +29 -0
  42. package/dist/parsers/DefineParser.d.ts +18 -0
  43. package/dist/parsers/EventParser.d.ts +17 -0
  44. package/dist/parsers/ExpressionParser.d.ts +3 -0
  45. package/dist/parsers/FenceClassifier.d.ts +29 -0
  46. package/dist/parsers/ForLoopParser.d.ts +17 -0
  47. package/dist/parsers/IfBlockParser.d.ts +17 -0
  48. package/dist/parsers/ObjectLiteralParser.d.ts +17 -0
  49. package/dist/parsers/ParserUtils.d.ts +15 -0
  50. package/dist/parsers/PromptBlockParser.d.ts +10 -0
  51. package/dist/parsers/ReturnParser.d.ts +16 -0
  52. package/dist/parsers/ScopeParser.d.ts +24 -0
  53. package/dist/parsers/StringTemplateParser.d.ts +31 -0
  54. package/dist/parsers/SubexpressionParser.d.ts +33 -0
  55. package/dist/parsers/TogetherBlockParser.d.ts +18 -0
  56. package/dist/parsers/WithScopeParser.d.ts +24 -0
  57. package/dist/types/Ast.type.d.ts +455 -0
  58. package/dist/types/Environment.type.d.ts +53 -0
  59. package/dist/utils/args.d.ts +24 -0
  60. package/dist/utils/errorFormatter.d.ts +22 -0
  61. package/dist/utils/index.d.ts +8 -0
  62. package/dist/utils/stringParsing.d.ts +41 -0
  63. package/dist/utils/types.d.ts +15 -0
  64. package/dist/utils/valueConversion.d.ts +25 -0
  65. package/package.json +50 -0
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * Array module for RobinPath
4
+ * Provides array manipulation operations
5
+ */
6
+ export declare const ArrayFunctions: Record<string, BuiltinHandler>;
7
+ export declare const ArrayFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const ArrayModuleMetadata: ModuleMetadata;
9
+ declare const ArrayModule: ModuleAdapter;
10
+ export default ArrayModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * Core module for RobinPath
4
+ * Provides core built-in functions like log, obj, array, tag, range, etc.
5
+ */
6
+ export declare const CoreFunctions: Record<string, BuiltinHandler>;
7
+ export declare const CoreFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const CoreModuleMetadata: ModuleMetadata;
9
+ declare const CoreModule: ModuleAdapter;
10
+ export default CoreModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * Dom module for RobinPath
4
+ * Provides DOM manipulation and event handling operations
5
+ */
6
+ export declare const DomFunctions: Record<string, BuiltinHandler>;
7
+ export declare const DomFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const DomModuleMetadata: ModuleMetadata;
9
+ declare const DomModule: ModuleAdapter;
10
+ export default DomModule;
@@ -0,0 +1,6 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ export declare const FetchFunctions: Record<string, BuiltinHandler>;
3
+ export declare const FetchFunctionMetadata: Record<string, FunctionMetadata>;
4
+ export declare const FetchModuleMetadata: ModuleMetadata;
5
+ declare const FetchModule: ModuleAdapter;
6
+ export default FetchModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * JSON module for RobinPath
4
+ * Provides JSON parsing, stringification, and manipulation operations
5
+ */
6
+ export declare const JsonFunctions: Record<string, BuiltinHandler>;
7
+ export declare const JsonFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const JsonModuleMetadata: ModuleMetadata;
9
+ declare const JsonModule: ModuleAdapter;
10
+ export default JsonModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * Math module for RobinPath
4
+ * Provides mathematical operations and functions
5
+ */
6
+ export declare const MathFunctions: Record<string, BuiltinHandler>;
7
+ export declare const MathFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const MathModuleMetadata: ModuleMetadata;
9
+ declare const MathModule: ModuleAdapter;
10
+ export default MathModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * Object module for RobinPath
4
+ * Provides object manipulation operations (get, set, keys, values, entries, merge, clone)
5
+ */
6
+ export declare const ObjectFunctions: Record<string, BuiltinHandler>;
7
+ export declare const ObjectFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const ObjectModuleMetadata: ModuleMetadata;
9
+ declare const ObjectModule: ModuleAdapter;
10
+ export default ObjectModule;
@@ -0,0 +1,6 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ export declare const RandomFunctions: Record<string, BuiltinHandler>;
3
+ export declare const RandomFunctionMetadata: Record<string, FunctionMetadata>;
4
+ export declare const RandomModuleMetadata: ModuleMetadata;
5
+ declare const RandomModule: ModuleAdapter;
6
+ export default RandomModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * String module for RobinPath
4
+ * Provides string manipulation operations and functions
5
+ */
6
+ export declare const StringFunctions: Record<string, BuiltinHandler>;
7
+ export declare const StringFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const StringModuleMetadata: ModuleMetadata;
9
+ declare const StringModule: ModuleAdapter;
10
+ export default StringModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * Test module for RobinPath
4
+ * Provides testing and assertion functions
5
+ */
6
+ export declare const TestFunctions: Record<string, BuiltinHandler>;
7
+ export declare const TestFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const TestModuleMetadata: ModuleMetadata;
9
+ declare const TestModule: ModuleAdapter;
10
+ export default TestModule;
@@ -0,0 +1,10 @@
1
+ import { BuiltinHandler, FunctionMetadata, ModuleMetadata, ModuleAdapter } from '../index';
2
+ /**
3
+ * Time module for RobinPath
4
+ * Provides date/time operations and utilities
5
+ */
6
+ export declare const TimeFunctions: Record<string, BuiltinHandler>;
7
+ export declare const TimeFunctionMetadata: Record<string, FunctionMetadata>;
8
+ export declare const TimeModuleMetadata: ModuleMetadata;
9
+ declare const TimeModule: ModuleAdapter;
10
+ export default TimeModule;
@@ -0,0 +1,17 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ export interface ArrayLiteralResult {
4
+ code: string;
5
+ endToken: Token;
6
+ startToken: Token;
7
+ }
8
+ export declare class ArrayLiteralParser {
9
+ /**
10
+ * Parse an array literal from TokenStream
11
+ * Expects stream to be positioned at the '[' token
12
+ *
13
+ * @param stream - TokenStream positioned at the '[' token
14
+ * @returns Parsed array literal with code and end token
15
+ */
16
+ static parse(stream: TokenStream): ArrayLiteralResult;
17
+ }
@@ -0,0 +1,37 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { Assignment, CodePosition } from '../types/Ast.type';
4
+ export interface AssignmentParserContext {
5
+ /**
6
+ * Parse a statement from the stream (for subexpressions)
7
+ */
8
+ parseStatement?: (stream: TokenStream) => any;
9
+ /**
10
+ * Create code position from tokens
11
+ */
12
+ createCodePosition?: (startToken: Token, endToken: Token) => CodePosition;
13
+ }
14
+ export declare class AssignmentParser {
15
+ /**
16
+ * Parse a variable assignment statement
17
+ * Expects stream to be positioned at the variable token
18
+ *
19
+ * @param stream - TokenStream positioned at the variable token
20
+ * @param context - Optional context with helper methods
21
+ * @returns Assignment AST node
22
+ */
23
+ static parse(stream: TokenStream, context?: AssignmentParserContext): Assignment;
24
+ /**
25
+ * Parse a simple fallback value (string, number, boolean, null)
26
+ */
27
+ private static parseFallbackValue;
28
+ /**
29
+ * Parse the value part of an assignment
30
+ * Returns the assignment data and the end token
31
+ */
32
+ /**
33
+ * Check if there's a binary operator ahead that would indicate we need parseExpression
34
+ */
35
+ private static isBinaryOperatorAhead;
36
+ private static parseAssignmentValue;
37
+ }
@@ -0,0 +1,31 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { CodePosition, Statement } from '../types/Ast.type';
4
+ export interface BracketParserContext {
5
+ /**
6
+ * Parse a statement from the stream
7
+ */
8
+ parseStatement: (stream: TokenStream) => Statement | null;
9
+ /**
10
+ * Create code position from tokens
11
+ */
12
+ createCodePosition: (startToken: Token, endToken: Token) => CodePosition;
13
+ }
14
+ export declare class BracketParser {
15
+ /**
16
+ * Parse a parenthesized block from TokenStream
17
+ * Expects stream to be positioned at the '(' token
18
+ * Syntax: ( ... )
19
+ *
20
+ * @param stream - TokenStream positioned at the '(' token
21
+ * @param context - Context with helper methods
22
+ * @returns Array of statements inside the parentheses
23
+ */
24
+ static parse(stream: TokenStream, context: BracketParserContext): Statement[];
25
+ /**
26
+ * Check if the current token is the start of a bracket
27
+ * @param stream - TokenStream to check
28
+ * @returns true if current token is LPAREN
29
+ */
30
+ static isBracket(stream: TokenStream): boolean;
31
+ }
@@ -0,0 +1,15 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { BreakStatement, CodePosition } from '../types/Ast.type';
4
+ export interface BreakParserContext {
5
+ createCodePosition: (start: Token, end: Token) => CodePosition;
6
+ }
7
+ /**
8
+ * Parse a break statement
9
+ * Syntax: break [comment]
10
+ *
11
+ * @param stream - TokenStream positioned at the 'break' keyword
12
+ * @param context - Context with helper methods
13
+ * @returns Parsed BreakStatement
14
+ */
15
+ export declare function parseBreak(stream: TokenStream, context: BreakParserContext): BreakStatement;
@@ -0,0 +1,11 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { CellBlock } from '../types/Ast.type';
3
+ /**
4
+ * Parse a cell block from the current position
5
+ *
6
+ * @param stream - Token stream positioned at the cell open fence
7
+ * @param source - Full source code string
8
+ * @param parseStatement - Function to parse statements (for code cells)
9
+ * @returns CellBlock if parsed, null otherwise
10
+ */
11
+ export declare function parseCellBlock(stream: TokenStream, source: string, _parseStatement: (stream: TokenStream) => any): Promise<CellBlock | null>;
@@ -0,0 +1,12 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { ChunkMarkerStatement } from '../types/Ast.type';
3
+ /**
4
+ * Parse a chunk marker from the current line
5
+ *
6
+ * Syntax: --- chunk:<id> [key:value ...] ---
7
+ *
8
+ * @param stream - Token stream positioned at the start of a potential chunk marker
9
+ * @param source - Full source code string for extracting raw line
10
+ * @returns ChunkMarkerStatement if parsed, null otherwise
11
+ */
12
+ export declare function parseChunkMarker(stream: TokenStream, source: string): ChunkMarkerStatement | null;
@@ -0,0 +1,56 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { CommandCall, Arg, ScopeBlock, CodePosition } from '../types/Ast.type';
4
+ export interface CommandParserContext {
5
+ /**
6
+ * Parse a statement from the stream (for callback blocks)
7
+ */
8
+ parseStatement?: (stream: TokenStream) => any;
9
+ /**
10
+ * Parse a scope block (do/enddo)
11
+ */
12
+ parseScope?: (stream: TokenStream) => ScopeBlock;
13
+ /**
14
+ * Create code position from tokens
15
+ */
16
+ createCodePosition?: (startToken: Token, endToken: Token) => CodePosition;
17
+ }
18
+ export declare class CommandParser {
19
+ /**
20
+ * Parse a command call from TokenStream
21
+ * Expects stream to be positioned at the command name (identifier or keyword)
22
+ *
23
+ * @param stream - TokenStream positioned at the command name
24
+ * @param context - Optional context for parsing callbacks and creating code positions
25
+ * @returns Parsed CommandCall
26
+ */
27
+ static parse(stream: TokenStream, context?: CommandParserContext): CommandCall;
28
+ /**
29
+ * Parse command name (handles module.function syntax)
30
+ */
31
+ private static parseCommandName;
32
+ /**
33
+ * Parse parenthesized function call: command(...)
34
+ */
35
+ private static parseParenthesizedCall;
36
+ /**
37
+ * Parse space-separated function call: command arg1 arg2
38
+ */
39
+ private static parseSpaceSeparatedCall;
40
+ /**
41
+ * Parse a single argument (positional or named)
42
+ */
43
+ private static parseArgument;
44
+ /**
45
+ * Parse an argument value (handles literals, variables, subexpressions, objects, arrays)
46
+ */
47
+ static parseArgumentValue(stream: TokenStream, context?: CommandParserContext): Arg | null;
48
+ /**
49
+ * Parse "into $var" syntax
50
+ */
51
+ private static parseInto;
52
+ /**
53
+ * Parse callback block (with only)
54
+ */
55
+ private static parseCallback;
56
+ }
@@ -0,0 +1,37 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { CommentWithPosition, CommentStatement, Statement } from '../types/Ast.type';
3
+ export declare class CommentParser {
4
+ /**
5
+ * Parse comments from the stream and determine if they should be attached to the next statement
6
+ * or kept as a standalone comment node
7
+ *
8
+ * Strategy:
9
+ * 1. Collect all consecutive comments
10
+ * 2. After comments, if we hit a newline, check if next token is also newline (blank line)
11
+ * 3. If blank line -> create standalone comment node
12
+ * 4. Otherwise -> return comments to attach to next statement
13
+ *
14
+ * @param stream - TokenStream positioned at a COMMENT token
15
+ * @returns Object with:
16
+ * - comments: Array of CommentWithPosition for comments to attach
17
+ * - commentNode: CommentStatement if comments should be standalone (orphaned)
18
+ * - consumed: Whether comments were consumed from the stream
19
+ */
20
+ static parseComments(stream: TokenStream): {
21
+ comments: CommentWithPosition[];
22
+ commentNode: CommentStatement | null;
23
+ consumed: boolean;
24
+ };
25
+ /**
26
+ * Parse inline comment from the stream (comment on same line as code)
27
+ *
28
+ * @param stream - TokenStream positioned at a COMMENT token
29
+ * @param statementLine - Line number of the statement (0-based)
30
+ * @returns CommentWithPosition if inline comment found, null otherwise
31
+ */
32
+ static parseInlineComment(stream: TokenStream, statementLine: number): CommentWithPosition | null;
33
+ /**
34
+ * Attach comments to a statement
35
+ */
36
+ static attachComments(statement: Statement, comments: CommentWithPosition[]): void;
37
+ }
@@ -0,0 +1,15 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { ContinueStatement, CodePosition } from '../types/Ast.type';
4
+ export interface ContinueParserContext {
5
+ createCodePosition: (start: Token, end: Token) => CodePosition;
6
+ }
7
+ /**
8
+ * Parse a continue statement
9
+ * Syntax: continue [comment]
10
+ *
11
+ * @param stream - TokenStream positioned at the 'continue' keyword
12
+ * @param context - Context with helper methods
13
+ * @returns Parsed ContinueStatement
14
+ */
15
+ export declare function parseContinue(stream: TokenStream, context: ContinueParserContext): ContinueStatement;
@@ -0,0 +1,29 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { DecoratorCall } from '../types/Ast.type';
4
+ export interface DecoratorParserContext {
5
+ parseStatement: (stream: TokenStream) => any;
6
+ parseComment: (stream: TokenStream) => any;
7
+ }
8
+ /**
9
+ * Parse a decorator call
10
+ * Expects stream to be positioned at the '@' decorator token
11
+ *
12
+ * @param stream - TokenStream positioned at the decorator token
13
+ * @param context - Context with helper methods
14
+ * @returns Parsed DecoratorCall or null if not a decorator
15
+ */
16
+ export declare function parseDecorator(stream: TokenStream, context: DecoratorParserContext): DecoratorCall | null;
17
+ /**
18
+ * Parse multiple decorators that appear before a statement
19
+ * Decorators must be on consecutive lines (or same line) before the target statement
20
+ *
21
+ * @param stream - TokenStream positioned at the first decorator (or the statement if no decorators)
22
+ * @param context - Context with helper methods
23
+ * @returns Array of parsed decorators, the position after the last decorator, and the next token
24
+ */
25
+ export declare function parseDecorators(stream: TokenStream, context: DecoratorParserContext): {
26
+ decorators: DecoratorCall[];
27
+ positionAfter: number;
28
+ nextToken: Token | null;
29
+ };
@@ -0,0 +1,18 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Statement, DefineFunction, DecoratorCall } from '../types/Ast.type';
3
+ import { Environment } from '../index';
4
+ export declare class DefineParser {
5
+ /**
6
+ * Parse a 'def' function definition block
7
+ * Expects stream to be positioned at the 'def' keyword
8
+ *
9
+ * @param stream - TokenStream positioned at the 'def' keyword
10
+ * @param parseStatement - Callback to parse a statement from the stream
11
+ * @param parseComment - Callback to parse a comment from the stream
12
+ * @param decorators - Optional decorators to attach to this function
13
+ * @param environment - Optional environment for executing parse decorators
14
+ * @returns Parsed DefineFunction
15
+ */
16
+ static parse(stream: TokenStream, parseStatement: (stream: TokenStream) => Statement | null, _parseComment: (stream: TokenStream) => Statement | null, // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ decorators?: DecoratorCall[], environment?: Environment | null): Promise<DefineFunction>;
18
+ }
@@ -0,0 +1,17 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Statement, OnBlock, DecoratorCall } from '../types/Ast.type';
3
+ import { Environment } from '../index';
4
+ export declare class EventParser {
5
+ /**
6
+ * Parse an 'on' event handler block
7
+ * Expects stream to be positioned at the 'on' keyword
8
+ *
9
+ * @param stream - TokenStream positioned at the 'on' keyword
10
+ * @param parseStatement - Callback to parse a statement from the stream
11
+ * @param parseComment - Callback to parse a comment from the stream
12
+ * @param decorators - Optional decorators to attach to this event handler
13
+ * @param environment - Optional environment for executing parse decorators
14
+ * @returns Parsed OnBlock
15
+ */
16
+ static parse(stream: TokenStream, parseStatement: (stream: TokenStream) => Statement | null, parseComment: (stream: TokenStream) => Statement | null, decorators?: DecoratorCall[], environment?: Environment | null): Promise<OnBlock>;
17
+ }
@@ -0,0 +1,3 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Expression, Statement } from '../types/Ast.type';
3
+ export declare function parseExpression(stream: TokenStream, parseStatement?: (stream: TokenStream) => Statement | null, parseComment?: (stream: TokenStream) => Statement | null): Expression;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Fence Classifier - Classifies fence lines with priority order
3
+ *
4
+ * Priority order (to avoid ambiguity):
5
+ * 1. ---cell ...--- (cell open)
6
+ * 2. ---end--- (cell close)
7
+ * 3. --- chunk:... --- (chunk marker)
8
+ * 4. bare --- (prompt fence open/close)
9
+ */
10
+ export type FenceClassification = {
11
+ kind: 'cell_open';
12
+ cellType: string;
13
+ meta: Record<string, string>;
14
+ } | {
15
+ kind: 'cell_end';
16
+ } | {
17
+ kind: 'chunk_marker';
18
+ id: string;
19
+ meta: Record<string, string>;
20
+ } | {
21
+ kind: 'prompt_fence';
22
+ } | null;
23
+ /**
24
+ * Classify a fence line according to priority order
25
+ *
26
+ * @param line - Raw line string to classify
27
+ * @returns Classification result or null if not a fence line
28
+ */
29
+ export declare function classifyFenceLine(line: string): FenceClassification;
@@ -0,0 +1,17 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { ForLoop, Statement, CodePosition, DecoratorCall } from '../types/Ast.type';
4
+ export interface ForLoopParserContext {
5
+ parseStatement: (stream: TokenStream) => Statement | null;
6
+ parseComment: (stream: TokenStream) => Statement | null;
7
+ createCodePosition: (start: Token, end: Token) => CodePosition;
8
+ }
9
+ /**
10
+ * Parse a 'for' loop from TokenStream
11
+ *
12
+ * @param stream - TokenStream positioned at the 'for' keyword
13
+ * @param context - Context with helper methods
14
+ * @param decorators - Optional decorators to attach to this for loop
15
+ * @returns Parsed ForLoop
16
+ */
17
+ export declare function parseForLoop(stream: TokenStream, context: ForLoopParserContext, decorators?: DecoratorCall[]): ForLoop;
@@ -0,0 +1,17 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { IfBlock, InlineIf, Statement, CodePosition, DecoratorCall } from '../types/Ast.type';
4
+ export interface IfBlockParserContext {
5
+ parseStatement: (stream: TokenStream) => Statement | null;
6
+ parseComment: (stream: TokenStream) => Statement | null;
7
+ createCodePosition: (start: Token, end: Token) => CodePosition;
8
+ }
9
+ /**
10
+ * Parse an if statement (either inline or block)
11
+ *
12
+ * @param stream - TokenStream positioned at the 'if' keyword
13
+ * @param context - Context with helper methods
14
+ * @param decorators - Optional decorators to attach to this if block
15
+ * @returns Parsed IfBlock or InlineIf
16
+ */
17
+ export declare function parseIf(stream: TokenStream, context: IfBlockParserContext, decorators?: DecoratorCall[]): IfBlock | InlineIf;
@@ -0,0 +1,17 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ export interface ObjectLiteralResult {
4
+ code: string;
5
+ endToken: Token;
6
+ startToken: Token;
7
+ }
8
+ export declare class ObjectLiteralParser {
9
+ /**
10
+ * Parse an object literal from TokenStream
11
+ * Expects stream to be positioned at the '{' token
12
+ *
13
+ * @param stream - TokenStream positioned at the '{' token
14
+ * @returns Parsed object literal with code and end token
15
+ */
16
+ static parse(stream: TokenStream): ObjectLiteralResult;
17
+ }
@@ -0,0 +1,15 @@
1
+ import { Token } from '../classes/Lexer';
2
+ import { CodePosition } from '../types/Ast.type';
3
+ import { TokenStream } from '../classes/TokenStream';
4
+ /**
5
+ * Create CodePosition from start and end tokens
6
+ * @param startToken - The token where the node starts
7
+ * @param endToken - The token where the node ends
8
+ * @returns 0-indexed CodePosition
9
+ */
10
+ export declare function createCodePosition(startToken: Token, endToken: Token): CodePosition;
11
+ /**
12
+ * Skip whitespace and comments on the current line
13
+ * @param stream - TokenStream to skip in
14
+ */
15
+ export declare function skipWhitespaceOnLine(stream: TokenStream): void;
@@ -0,0 +1,10 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { PromptBlockStatement } from '../types/Ast.type';
3
+ /**
4
+ * Parse a prompt block from the current position
5
+ *
6
+ * @param stream - Token stream positioned at the opening prompt fence
7
+ * @param source - Full source code string
8
+ * @returns PromptBlockStatement if parsed, null otherwise
9
+ */
10
+ export declare function parsePromptBlock(stream: TokenStream, source: string): PromptBlockStatement | null;
@@ -0,0 +1,16 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { Token } from '../classes/Lexer';
3
+ import { ReturnStatement, CodePosition, Statement } from '../types/Ast.type';
4
+ export interface ReturnParserContext {
5
+ createCodePosition: (start: Token, end: Token) => CodePosition;
6
+ parseStatement?: (stream: TokenStream) => Statement | null;
7
+ }
8
+ /**
9
+ * Parse a return statement
10
+ * Syntax: return [value]
11
+ *
12
+ * @param stream - TokenStream positioned at the 'return' keyword
13
+ * @param context - Context with helper methods
14
+ * @returns Parsed ReturnStatement
15
+ */
16
+ export declare function parseReturn(stream: TokenStream, context: ReturnParserContext): ReturnStatement;
@@ -0,0 +1,24 @@
1
+ import { TokenStream } from '../classes/TokenStream';
2
+ import { ScopeBlock, Statement, DecoratorCall } from '../types/Ast.type';
3
+ export declare class ScopeParser {
4
+ /**
5
+ * Maximum number of iterations allowed before detecting an infinite loop
6
+ */
7
+ static readonly MAX_STUCK_ITERATIONS = 100;
8
+ /**
9
+ * Debug mode flag - set to true to enable logging
10
+ * Can be controlled via VITE_DEBUG environment variable or set programmatically
11
+ */
12
+ static debug: boolean;
13
+ /**
14
+ * Parse a 'do' scope block
15
+ * Expects stream to be positioned at the 'do' keyword
16
+ *
17
+ * @param stream - TokenStream positioned at the 'do' keyword
18
+ * @param parseStatement - Callback to parse a statement from the stream
19
+ * @param parseComment - Callback to parse a comment from the stream
20
+ * @param decorators - Optional decorators to attach to this do block
21
+ * @returns Parsed ScopeBlock
22
+ */
23
+ static parse(stream: TokenStream, parseStatement: (stream: TokenStream) => Statement | null, _parseComment: (stream: TokenStream) => Statement | null, decorators?: DecoratorCall[]): ScopeBlock;
24
+ }
@@ -0,0 +1,31 @@
1
+ import { Frame } from '../index';
2
+ import { Value } from '../utils/types';
3
+ export interface StringTemplateParserContext {
4
+ /**
5
+ * Resolve a variable by name and path
6
+ */
7
+ resolveVariable: (name: string, path?: any[], frameOverride?: Frame) => Value;
8
+ /**
9
+ * Get the current frame's last value
10
+ */
11
+ getLastValue: (frameOverride?: Frame) => Value;
12
+ /**
13
+ * Execute a subexpression code string
14
+ */
15
+ executeSubexpression: (code: string, frameOverride?: Frame) => Promise<Value>;
16
+ }
17
+ export declare class StringTemplateParser {
18
+ /**
19
+ * Evaluate a template string with variable interpolation and subexpressions
20
+ *
21
+ * @param template - The template string content (without backticks, already unescaped)
22
+ * @param context - Context with methods to resolve variables and execute subexpressions
23
+ * @param frameOverride - Optional frame override for variable resolution
24
+ * @returns The evaluated string
25
+ */
26
+ static evaluate(template: string, context: StringTemplateParserContext, frameOverride?: Frame): Promise<string>;
27
+ /**
28
+ * Convert a value to string representation
29
+ */
30
+ private static valueToString;
31
+ }