just-bash 1.1.0 → 1.2.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/dist/Bash.d.ts +18 -0
- package/dist/ai/index.d.ts +6 -1
- package/dist/bin/chunks/awk2-6XCE67AX.js +20 -0
- package/dist/bin/chunks/awk2-DKAZ7LPG.js +20 -0
- package/dist/bin/chunks/awk2-GAJ72X3Z.js +20 -0
- package/dist/bin/chunks/awk2-HJAPWU2N.js +18 -0
- package/dist/bin/chunks/awk2-LVXC5OAC.js +20 -0
- package/dist/bin/chunks/awk2-T6HR4EYO.js +20 -0
- package/dist/bin/chunks/awk2-UYU2UYZ2.js +20 -0
- package/dist/bin/chunks/awk2-W64AZN7P.js +20 -0
- package/dist/bin/chunks/find-7BUNQZX4.js +11 -0
- package/dist/bin/chunks/find-YATLECXJ.js +11 -0
- package/dist/bin/chunks/grep-PHBFGJCV.js +15 -0
- package/dist/bin/chunks/sed-B6FXUN7R.js +80 -0
- package/dist/bin/chunks/sed-RHLDIXPL.js +76 -0
- package/dist/bin/chunks/sed-SYSATJXR.js +75 -0
- package/dist/bin/just-bash.js +102 -102
- package/dist/bin/shell/chunks/awk2-6XCE67AX.js +20 -0
- package/dist/bin/shell/chunks/awk2-DKAZ7LPG.js +20 -0
- package/dist/bin/shell/chunks/awk2-GAJ72X3Z.js +20 -0
- package/dist/bin/shell/chunks/awk2-HJAPWU2N.js +18 -0
- package/dist/bin/shell/chunks/awk2-LVXC5OAC.js +20 -0
- package/dist/bin/shell/chunks/awk2-T6HR4EYO.js +20 -0
- package/dist/bin/shell/chunks/awk2-UYU2UYZ2.js +20 -0
- package/dist/bin/shell/chunks/awk2-W64AZN7P.js +20 -0
- package/dist/bin/shell/chunks/find-7BUNQZX4.js +11 -0
- package/dist/bin/shell/chunks/find-YATLECXJ.js +11 -0
- package/dist/bin/shell/chunks/grep-PHBFGJCV.js +15 -0
- package/dist/bin/shell/chunks/sed-B6FXUN7R.js +80 -0
- package/dist/bin/shell/chunks/sed-RHLDIXPL.js +76 -0
- package/dist/bin/shell/chunks/sed-SYSATJXR.js +75 -0
- package/dist/bin/shell/shell.js +124 -128
- package/dist/bundle/ai/index.js +423 -386
- package/dist/bundle/chunks/awk2-365HINHI.js +19 -0
- package/dist/bundle/chunks/awk2-7YCFY7D2.js +19 -0
- package/dist/bundle/chunks/awk2-7YL3P4KU.js +19 -0
- package/dist/bundle/chunks/awk2-ETXZHQQ4.js +19 -0
- package/dist/bundle/chunks/awk2-FMEL7ESV.js +19 -0
- package/dist/bundle/chunks/awk2-LE4QUFGK.js +19 -0
- package/dist/bundle/chunks/awk2-MGHA6JPJ.js +17 -0
- package/dist/bundle/chunks/awk2-XEAK5PBN.js +19 -0
- package/dist/bundle/chunks/find-KP4M5DWC.js +10 -0
- package/dist/bundle/chunks/find-WM6ZETA7.js +10 -0
- package/dist/bundle/chunks/grep-CZTYKNEE.js +14 -0
- package/dist/bundle/chunks/sed-2WWCANZT.js +79 -0
- package/dist/bundle/chunks/sed-5LZHAGFR.js +74 -0
- package/dist/bundle/chunks/sed-V7XSBPTD.js +75 -0
- package/dist/bundle/index.js +8 -8
- package/dist/commands/awk/ast.d.ts +201 -0
- package/dist/commands/awk/awk2.d.ts +7 -0
- package/dist/commands/awk/builtins.d.ts +17 -0
- package/dist/commands/awk/interpreter/context.d.ts +53 -0
- package/dist/commands/awk/interpreter/expressions.d.ts +17 -0
- package/dist/commands/awk/interpreter/fields.d.ts +25 -0
- package/dist/commands/awk/interpreter/helpers.d.ts +29 -0
- package/dist/commands/awk/interpreter/index.d.ts +8 -0
- package/dist/commands/awk/interpreter/interpreter.d.ts +50 -0
- package/dist/commands/awk/interpreter/statements.d.ts +11 -0
- package/dist/commands/awk/interpreter/types.d.ts +13 -0
- package/dist/commands/awk/interpreter/variables.d.ts +35 -0
- package/dist/commands/awk/interpreter2.d.ts +90 -0
- package/dist/commands/awk/lexer.d.ts +100 -0
- package/dist/commands/awk/parser2.d.ts +73 -0
- package/dist/commands/find/matcher.d.ts +6 -2
- package/dist/commands/find/types.d.ts +13 -0
- package/dist/commands/sed/executor.d.ts +1 -1
- package/dist/commands/sed/lexer.d.ts +74 -0
- package/dist/commands/sed/parser.d.ts +4 -0
- package/dist/commands/sed/types.d.ts +66 -2
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWK Interpreter
|
|
3
|
+
*
|
|
4
|
+
* Main interpreter class that orchestrates AWK program execution.
|
|
5
|
+
*/
|
|
6
|
+
import type { AwkProgram } from "../ast.js";
|
|
7
|
+
import type { AwkRuntimeContext } from "./context.js";
|
|
8
|
+
export declare class AwkInterpreter {
|
|
9
|
+
private ctx;
|
|
10
|
+
private program;
|
|
11
|
+
private rangeStates;
|
|
12
|
+
constructor(ctx: AwkRuntimeContext);
|
|
13
|
+
/**
|
|
14
|
+
* Initialize the interpreter with a program.
|
|
15
|
+
* Must be called before executeBegin/executeLine/executeEnd.
|
|
16
|
+
*/
|
|
17
|
+
execute(program: AwkProgram): void;
|
|
18
|
+
/**
|
|
19
|
+
* Execute all BEGIN blocks.
|
|
20
|
+
*/
|
|
21
|
+
executeBegin(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Execute rules for a single input line.
|
|
24
|
+
*/
|
|
25
|
+
executeLine(line: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Execute all END blocks.
|
|
28
|
+
*/
|
|
29
|
+
executeEnd(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the accumulated output.
|
|
32
|
+
*/
|
|
33
|
+
getOutput(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Get the exit code.
|
|
36
|
+
*/
|
|
37
|
+
getExitCode(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Get the runtime context (for access to control flow flags, etc.)
|
|
40
|
+
*/
|
|
41
|
+
getContext(): AwkRuntimeContext;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a rule matches the current line.
|
|
44
|
+
*/
|
|
45
|
+
private matchesRule;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a pattern matches.
|
|
48
|
+
*/
|
|
49
|
+
private matchPattern;
|
|
50
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWK Statement Execution
|
|
3
|
+
*
|
|
4
|
+
* Async statement executor supporting file I/O operations.
|
|
5
|
+
*/
|
|
6
|
+
import type { AwkStmt } from "../ast.js";
|
|
7
|
+
import type { AwkRuntimeContext } from "./context.js";
|
|
8
|
+
/**
|
|
9
|
+
* Execute a block of statements.
|
|
10
|
+
*/
|
|
11
|
+
export declare function executeBlock(ctx: AwkRuntimeContext, statements: AwkStmt[]): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWK Interpreter Types
|
|
3
|
+
*/
|
|
4
|
+
export type AwkValue = string | number;
|
|
5
|
+
/**
|
|
6
|
+
* File system interface for AWK file operations
|
|
7
|
+
*/
|
|
8
|
+
export interface AwkFileSystem {
|
|
9
|
+
readFile: (path: string) => Promise<string>;
|
|
10
|
+
writeFile: (path: string, content: string) => Promise<void>;
|
|
11
|
+
appendFile: (path: string, content: string) => Promise<void>;
|
|
12
|
+
resolvePath: (cwd: string, path: string) => string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWK Variable and Array Operations
|
|
3
|
+
*
|
|
4
|
+
* Handles user variables, built-in variables, and arrays.
|
|
5
|
+
*/
|
|
6
|
+
import type { AwkRuntimeContext } from "./context.js";
|
|
7
|
+
import type { AwkValue } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Get a variable value. Handles built-in variables.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getVariable(ctx: AwkRuntimeContext, name: string): AwkValue;
|
|
12
|
+
/**
|
|
13
|
+
* Set a variable value. Handles built-in variables with special behavior.
|
|
14
|
+
*/
|
|
15
|
+
export declare function setVariable(ctx: AwkRuntimeContext, name: string, value: AwkValue): void;
|
|
16
|
+
/**
|
|
17
|
+
* Get an array element value.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getArrayElement(ctx: AwkRuntimeContext, array: string, key: string): AwkValue;
|
|
20
|
+
/**
|
|
21
|
+
* Set an array element value.
|
|
22
|
+
*/
|
|
23
|
+
export declare function setArrayElement(ctx: AwkRuntimeContext, array: string, key: string, value: AwkValue): void;
|
|
24
|
+
/**
|
|
25
|
+
* Check if an array element exists.
|
|
26
|
+
*/
|
|
27
|
+
export declare function hasArrayElement(ctx: AwkRuntimeContext, array: string, key: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Delete an array element.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deleteArrayElement(ctx: AwkRuntimeContext, array: string, key: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Delete an entire array.
|
|
34
|
+
*/
|
|
35
|
+
export declare function deleteArray(ctx: AwkRuntimeContext, array: string): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWK Interpreter
|
|
3
|
+
*
|
|
4
|
+
* Tree-walking interpreter that executes an AWK AST.
|
|
5
|
+
*/
|
|
6
|
+
import type { AwkExpr, AwkFunctionDef, AwkProgram } from "./ast.js";
|
|
7
|
+
export type AwkValue = string | number;
|
|
8
|
+
export interface AwkRuntimeContext {
|
|
9
|
+
FS: string;
|
|
10
|
+
OFS: string;
|
|
11
|
+
ORS: string;
|
|
12
|
+
NR: number;
|
|
13
|
+
NF: number;
|
|
14
|
+
FNR: number;
|
|
15
|
+
FILENAME: string;
|
|
16
|
+
RSTART: number;
|
|
17
|
+
RLENGTH: number;
|
|
18
|
+
SUBSEP: string;
|
|
19
|
+
fields: string[];
|
|
20
|
+
line: string;
|
|
21
|
+
vars: Record<string, AwkValue>;
|
|
22
|
+
arrays: Record<string, Record<string, AwkValue>>;
|
|
23
|
+
functions: Map<string, AwkFunctionDef>;
|
|
24
|
+
lines?: string[];
|
|
25
|
+
lineIndex?: number;
|
|
26
|
+
fieldSep: RegExp;
|
|
27
|
+
maxIterations: number;
|
|
28
|
+
maxRecursionDepth: number;
|
|
29
|
+
currentRecursionDepth: number;
|
|
30
|
+
exitCode: number;
|
|
31
|
+
shouldExit: boolean;
|
|
32
|
+
shouldNext: boolean;
|
|
33
|
+
loopBreak: boolean;
|
|
34
|
+
loopContinue: boolean;
|
|
35
|
+
returnValue?: AwkValue;
|
|
36
|
+
hasReturn: boolean;
|
|
37
|
+
output: string;
|
|
38
|
+
random?: () => number;
|
|
39
|
+
}
|
|
40
|
+
export declare function createRuntimeContext(fieldSep?: RegExp, maxIterations?: number): AwkRuntimeContext;
|
|
41
|
+
export declare class AwkInterpreter {
|
|
42
|
+
private ctx;
|
|
43
|
+
private program;
|
|
44
|
+
private rangeStates;
|
|
45
|
+
constructor(ctx: AwkRuntimeContext);
|
|
46
|
+
execute(program: AwkProgram): string;
|
|
47
|
+
executeBegin(): void;
|
|
48
|
+
executeLine(line: string): void;
|
|
49
|
+
executeEnd(): void;
|
|
50
|
+
getOutput(): string;
|
|
51
|
+
getExitCode(): number;
|
|
52
|
+
private splitFields;
|
|
53
|
+
private matchesRule;
|
|
54
|
+
private matchPattern;
|
|
55
|
+
private matchRegex;
|
|
56
|
+
private executeBlock;
|
|
57
|
+
private executeStmt;
|
|
58
|
+
private executePrint;
|
|
59
|
+
private executePrintf;
|
|
60
|
+
private executeIf;
|
|
61
|
+
private executeWhile;
|
|
62
|
+
private executeDoWhile;
|
|
63
|
+
private executeFor;
|
|
64
|
+
private executeForIn;
|
|
65
|
+
private executeDelete;
|
|
66
|
+
evalExpr(expr: AwkExpr): AwkValue;
|
|
67
|
+
private getField;
|
|
68
|
+
private setField;
|
|
69
|
+
private getVariable;
|
|
70
|
+
private setVariable;
|
|
71
|
+
private getArrayElement;
|
|
72
|
+
private setArrayElement;
|
|
73
|
+
private evalBinaryOp;
|
|
74
|
+
private isComparisonOp;
|
|
75
|
+
private evalComparison;
|
|
76
|
+
private looksLikeNumber;
|
|
77
|
+
private evalUnaryOp;
|
|
78
|
+
private evalFunctionCall;
|
|
79
|
+
private callUserFunction;
|
|
80
|
+
private evalAssignment;
|
|
81
|
+
private evalPreIncrement;
|
|
82
|
+
private evalPreDecrement;
|
|
83
|
+
private evalPostIncrement;
|
|
84
|
+
private evalPostDecrement;
|
|
85
|
+
private evalInExpr;
|
|
86
|
+
private evalGetline;
|
|
87
|
+
isTruthy(val: AwkValue): boolean;
|
|
88
|
+
toNumber(val: AwkValue): number;
|
|
89
|
+
toString(val: AwkValue): string;
|
|
90
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWK Lexer
|
|
3
|
+
*
|
|
4
|
+
* Tokenizes AWK source code into a stream of tokens.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum TokenType {
|
|
7
|
+
NUMBER = "NUMBER",
|
|
8
|
+
STRING = "STRING",
|
|
9
|
+
REGEX = "REGEX",
|
|
10
|
+
IDENT = "IDENT",
|
|
11
|
+
BEGIN = "BEGIN",
|
|
12
|
+
END = "END",
|
|
13
|
+
IF = "IF",
|
|
14
|
+
ELSE = "ELSE",
|
|
15
|
+
WHILE = "WHILE",
|
|
16
|
+
DO = "DO",
|
|
17
|
+
FOR = "FOR",
|
|
18
|
+
IN = "IN",
|
|
19
|
+
BREAK = "BREAK",
|
|
20
|
+
CONTINUE = "CONTINUE",
|
|
21
|
+
NEXT = "NEXT",
|
|
22
|
+
NEXTFILE = "NEXTFILE",
|
|
23
|
+
EXIT = "EXIT",
|
|
24
|
+
RETURN = "RETURN",
|
|
25
|
+
DELETE = "DELETE",
|
|
26
|
+
FUNCTION = "FUNCTION",
|
|
27
|
+
PRINT = "PRINT",
|
|
28
|
+
PRINTF = "PRINTF",
|
|
29
|
+
GETLINE = "GETLINE",
|
|
30
|
+
PLUS = "PLUS",
|
|
31
|
+
MINUS = "MINUS",
|
|
32
|
+
STAR = "STAR",
|
|
33
|
+
SLASH = "SLASH",
|
|
34
|
+
PERCENT = "PERCENT",
|
|
35
|
+
CARET = "CARET",
|
|
36
|
+
EQ = "EQ",
|
|
37
|
+
NE = "NE",
|
|
38
|
+
LT = "LT",
|
|
39
|
+
GT = "GT",
|
|
40
|
+
LE = "LE",
|
|
41
|
+
GE = "GE",
|
|
42
|
+
MATCH = "MATCH",
|
|
43
|
+
NOT_MATCH = "NOT_MATCH",
|
|
44
|
+
AND = "AND",
|
|
45
|
+
OR = "OR",
|
|
46
|
+
NOT = "NOT",
|
|
47
|
+
ASSIGN = "ASSIGN",
|
|
48
|
+
PLUS_ASSIGN = "PLUS_ASSIGN",
|
|
49
|
+
MINUS_ASSIGN = "MINUS_ASSIGN",
|
|
50
|
+
STAR_ASSIGN = "STAR_ASSIGN",
|
|
51
|
+
SLASH_ASSIGN = "SLASH_ASSIGN",
|
|
52
|
+
PERCENT_ASSIGN = "PERCENT_ASSIGN",
|
|
53
|
+
CARET_ASSIGN = "CARET_ASSIGN",
|
|
54
|
+
INCREMENT = "INCREMENT",
|
|
55
|
+
DECREMENT = "DECREMENT",
|
|
56
|
+
QUESTION = "QUESTION",
|
|
57
|
+
COLON = "COLON",
|
|
58
|
+
COMMA = "COMMA",
|
|
59
|
+
SEMICOLON = "SEMICOLON",
|
|
60
|
+
NEWLINE = "NEWLINE",
|
|
61
|
+
LPAREN = "LPAREN",
|
|
62
|
+
RPAREN = "RPAREN",
|
|
63
|
+
LBRACE = "LBRACE",
|
|
64
|
+
RBRACE = "RBRACE",
|
|
65
|
+
LBRACKET = "LBRACKET",
|
|
66
|
+
RBRACKET = "RBRACKET",
|
|
67
|
+
DOLLAR = "DOLLAR",
|
|
68
|
+
APPEND = "APPEND",
|
|
69
|
+
PIPE = "PIPE",
|
|
70
|
+
EOF = "EOF"
|
|
71
|
+
}
|
|
72
|
+
export interface Token {
|
|
73
|
+
type: TokenType;
|
|
74
|
+
value: string | number;
|
|
75
|
+
line: number;
|
|
76
|
+
column: number;
|
|
77
|
+
}
|
|
78
|
+
export declare class AwkLexer {
|
|
79
|
+
private input;
|
|
80
|
+
private pos;
|
|
81
|
+
private line;
|
|
82
|
+
private column;
|
|
83
|
+
private lastTokenType;
|
|
84
|
+
constructor(input: string);
|
|
85
|
+
tokenize(): Token[];
|
|
86
|
+
private makeToken;
|
|
87
|
+
private peek;
|
|
88
|
+
private advance;
|
|
89
|
+
private skipWhitespace;
|
|
90
|
+
private nextToken;
|
|
91
|
+
private canBeRegex;
|
|
92
|
+
private readString;
|
|
93
|
+
private readRegex;
|
|
94
|
+
private readNumber;
|
|
95
|
+
private readIdentifier;
|
|
96
|
+
private readOperator;
|
|
97
|
+
private isDigit;
|
|
98
|
+
private isAlpha;
|
|
99
|
+
private isAlphaNumeric;
|
|
100
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWK Parser
|
|
3
|
+
*
|
|
4
|
+
* Recursive descent parser that builds an AST from tokens.
|
|
5
|
+
*/
|
|
6
|
+
import type { AwkProgram } from "./ast.js";
|
|
7
|
+
export declare class AwkParser {
|
|
8
|
+
private tokens;
|
|
9
|
+
private pos;
|
|
10
|
+
parse(input: string): AwkProgram;
|
|
11
|
+
private current;
|
|
12
|
+
private advance;
|
|
13
|
+
private match;
|
|
14
|
+
private check;
|
|
15
|
+
private expect;
|
|
16
|
+
private skipNewlines;
|
|
17
|
+
private skipTerminators;
|
|
18
|
+
private parseProgram;
|
|
19
|
+
private parseFunction;
|
|
20
|
+
private parseRule;
|
|
21
|
+
private parseBlock;
|
|
22
|
+
private parseStatement;
|
|
23
|
+
private parseIf;
|
|
24
|
+
private parseWhile;
|
|
25
|
+
private parseDoWhile;
|
|
26
|
+
private parseFor;
|
|
27
|
+
private parsePrint;
|
|
28
|
+
/**
|
|
29
|
+
* Parse a print argument - same as ternary but treats > and >> at the TOP LEVEL
|
|
30
|
+
* (not inside ternary) as redirection rather than comparison operators.
|
|
31
|
+
*/
|
|
32
|
+
private parsePrintArg;
|
|
33
|
+
/**
|
|
34
|
+
* Look ahead to see if there's a ternary ? operator before the next statement terminator.
|
|
35
|
+
* This tells us whether > is comparison (in ternary condition) or redirection.
|
|
36
|
+
*/
|
|
37
|
+
private lookAheadForTernary;
|
|
38
|
+
private parsePrintOr;
|
|
39
|
+
private parsePrintAnd;
|
|
40
|
+
private parsePrintIn;
|
|
41
|
+
private parsePrintMatch;
|
|
42
|
+
/**
|
|
43
|
+
* Like parseComparison but doesn't consume > and >> (for print redirection)
|
|
44
|
+
*/
|
|
45
|
+
private parsePrintComparison;
|
|
46
|
+
private parsePrintf;
|
|
47
|
+
private parseExpression;
|
|
48
|
+
private parseAssignment;
|
|
49
|
+
private parseTernary;
|
|
50
|
+
private parseOr;
|
|
51
|
+
/**
|
|
52
|
+
* Continue parsing a logical OR/AND expression from a given left-hand side.
|
|
53
|
+
* Used when we've already parsed part of an expression (e.g., a regex in pattern context).
|
|
54
|
+
*/
|
|
55
|
+
private parseLogicalOrRest;
|
|
56
|
+
/**
|
|
57
|
+
* Continue parsing a logical AND expression from a given left-hand side.
|
|
58
|
+
*/
|
|
59
|
+
private parseLogicalAndRest;
|
|
60
|
+
private parseAnd;
|
|
61
|
+
private parseIn;
|
|
62
|
+
private parseMatch;
|
|
63
|
+
private parseComparison;
|
|
64
|
+
private parseConcatenation;
|
|
65
|
+
private canStartExpression;
|
|
66
|
+
private isComparisonOrHigherOp;
|
|
67
|
+
private parseAddSub;
|
|
68
|
+
private parseMulDiv;
|
|
69
|
+
private parseUnary;
|
|
70
|
+
private parsePower;
|
|
71
|
+
private parsePostfix;
|
|
72
|
+
private parsePrimary;
|
|
73
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import type { EvalContext, Expression } from "./types.js";
|
|
2
|
-
|
|
1
|
+
import type { EvalContext, EvalResult, Expression } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Evaluate a find expression and return both match result and prune flag.
|
|
4
|
+
* The prune flag is set when -prune is evaluated and returns true.
|
|
5
|
+
*/
|
|
6
|
+
export declare function evaluateExpressionWithPrune(expr: Expression, ctx: EvalContext): EvalResult;
|
|
3
7
|
export declare function collectNewerRefs(expr: Expression | null): string[];
|
|
@@ -6,6 +6,10 @@ export type Expression = {
|
|
|
6
6
|
type: "path";
|
|
7
7
|
pattern: string;
|
|
8
8
|
ignoreCase?: boolean;
|
|
9
|
+
} | {
|
|
10
|
+
type: "regex";
|
|
11
|
+
pattern: string;
|
|
12
|
+
ignoreCase?: boolean;
|
|
9
13
|
} | {
|
|
10
14
|
type: "type";
|
|
11
15
|
fileType: "f" | "d";
|
|
@@ -27,6 +31,10 @@ export type Expression = {
|
|
|
27
31
|
type: "perm";
|
|
28
32
|
mode: number;
|
|
29
33
|
matchType: "exact" | "all" | "any";
|
|
34
|
+
} | {
|
|
35
|
+
type: "prune";
|
|
36
|
+
} | {
|
|
37
|
+
type: "print";
|
|
30
38
|
} | {
|
|
31
39
|
type: "not";
|
|
32
40
|
expr: Expression;
|
|
@@ -62,6 +70,11 @@ export interface EvalContext {
|
|
|
62
70
|
mode: number;
|
|
63
71
|
newerRefTimes: Map<string, number>;
|
|
64
72
|
}
|
|
73
|
+
export interface EvalResult {
|
|
74
|
+
matches: boolean;
|
|
75
|
+
pruned: boolean;
|
|
76
|
+
printed: boolean;
|
|
77
|
+
}
|
|
65
78
|
export interface ParseResult {
|
|
66
79
|
expr: Expression | null;
|
|
67
80
|
pathIndex: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SedCommand, SedExecutionLimits, SedState } from "./types.js";
|
|
2
|
-
export declare function createInitialState(totalLines: number): SedState;
|
|
2
|
+
export declare function createInitialState(totalLines: number, filename?: string, rangeStates?: Map<string, import("./types.js").RangeState>): SedState;
|
|
3
3
|
export interface ExecuteContext {
|
|
4
4
|
lines: string[];
|
|
5
5
|
currentLineIndex: number;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SED Lexer
|
|
3
|
+
*
|
|
4
|
+
* Tokenizes sed scripts into a stream of tokens.
|
|
5
|
+
* Sed has context-sensitive tokenization - the meaning of characters
|
|
6
|
+
* depends heavily on what command is being parsed.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum SedTokenType {
|
|
9
|
+
NUMBER = "NUMBER",
|
|
10
|
+
DOLLAR = "DOLLAR",// $ - last line
|
|
11
|
+
PATTERN = "PATTERN",// /regex/
|
|
12
|
+
STEP = "STEP",// first~step
|
|
13
|
+
LBRACE = "LBRACE",// {
|
|
14
|
+
RBRACE = "RBRACE",// }
|
|
15
|
+
SEMICOLON = "SEMICOLON",// ;
|
|
16
|
+
NEWLINE = "NEWLINE",
|
|
17
|
+
COMMA = "COMMA",// , - address range separator
|
|
18
|
+
COMMAND = "COMMAND",// p, d, h, H, g, G, x, n, N, P, D, q, Q, z, =, l, F, v
|
|
19
|
+
SUBSTITUTE = "SUBSTITUTE",// s/pattern/replacement/flags
|
|
20
|
+
TRANSLITERATE = "TRANSLITERATE",// y/source/dest/
|
|
21
|
+
LABEL_DEF = "LABEL_DEF",// :name
|
|
22
|
+
BRANCH = "BRANCH",// b [label]
|
|
23
|
+
BRANCH_ON_SUBST = "BRANCH_ON_SUBST",// t [label]
|
|
24
|
+
BRANCH_ON_NO_SUBST = "BRANCH_ON_NO_SUBST",// T [label]
|
|
25
|
+
TEXT_CMD = "TEXT_CMD",// a\, i\, c\ with text
|
|
26
|
+
FILE_READ = "FILE_READ",// r filename
|
|
27
|
+
FILE_READ_LINE = "FILE_READ_LINE",// R filename
|
|
28
|
+
FILE_WRITE = "FILE_WRITE",// w filename
|
|
29
|
+
FILE_WRITE_LINE = "FILE_WRITE_LINE",// W filename
|
|
30
|
+
EXECUTE = "EXECUTE",// e [command]
|
|
31
|
+
EOF = "EOF",
|
|
32
|
+
ERROR = "ERROR"
|
|
33
|
+
}
|
|
34
|
+
export interface SedToken {
|
|
35
|
+
type: SedTokenType;
|
|
36
|
+
value: string | number;
|
|
37
|
+
pattern?: string;
|
|
38
|
+
replacement?: string;
|
|
39
|
+
flags?: string;
|
|
40
|
+
source?: string;
|
|
41
|
+
dest?: string;
|
|
42
|
+
text?: string;
|
|
43
|
+
label?: string;
|
|
44
|
+
filename?: string;
|
|
45
|
+
command?: string;
|
|
46
|
+
first?: number;
|
|
47
|
+
step?: number;
|
|
48
|
+
line: number;
|
|
49
|
+
column: number;
|
|
50
|
+
}
|
|
51
|
+
export declare class SedLexer {
|
|
52
|
+
private input;
|
|
53
|
+
private pos;
|
|
54
|
+
private line;
|
|
55
|
+
private column;
|
|
56
|
+
constructor(input: string);
|
|
57
|
+
tokenize(): SedToken[];
|
|
58
|
+
private makeToken;
|
|
59
|
+
private peek;
|
|
60
|
+
private advance;
|
|
61
|
+
private skipWhitespace;
|
|
62
|
+
private nextToken;
|
|
63
|
+
private readNumber;
|
|
64
|
+
private readPattern;
|
|
65
|
+
private readLabelDef;
|
|
66
|
+
private readCommand;
|
|
67
|
+
private readSubstitute;
|
|
68
|
+
private readTransliterate;
|
|
69
|
+
private readTextCommand;
|
|
70
|
+
private readBranch;
|
|
71
|
+
private readFileCommand;
|
|
72
|
+
private readExecute;
|
|
73
|
+
private isDigit;
|
|
74
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { SedCommand } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parse multiple sed scripts into a list of commands.
|
|
4
|
+
* This is the main entry point for parsing sed scripts.
|
|
5
|
+
*/
|
|
2
6
|
export declare function parseMultipleScripts(scripts: string[], extendedRegex?: boolean): {
|
|
3
7
|
commands: SedCommand[];
|
|
4
8
|
error?: string;
|
|
@@ -9,7 +9,7 @@ export interface AddressRange {
|
|
|
9
9
|
start?: SedAddress;
|
|
10
10
|
end?: SedAddress;
|
|
11
11
|
}
|
|
12
|
-
export type SedCommandType = "substitute" | "print" | "printFirstLine" | "delete" | "deleteFirstLine" | "append" | "insert" | "change" | "hold" | "holdAppend" | "get" | "getAppend" | "exchange" | "next" | "nextAppend" | "quit" | "transliterate" | "lineNumber" | "branch" | "branchOnSubst" | "branchOnNoSubst" | "label" | "zap" | "group";
|
|
12
|
+
export type SedCommandType = "substitute" | "print" | "printFirstLine" | "delete" | "deleteFirstLine" | "append" | "insert" | "change" | "hold" | "holdAppend" | "get" | "getAppend" | "exchange" | "next" | "nextAppend" | "quit" | "quitSilent" | "transliterate" | "lineNumber" | "branch" | "branchOnSubst" | "branchOnNoSubst" | "label" | "zap" | "group" | "list" | "printFilename" | "version" | "readFile" | "readFileLine" | "writeFile" | "writeFirstLine" | "execute";
|
|
13
13
|
export interface SubstituteCommand {
|
|
14
14
|
type: "substitute";
|
|
15
15
|
address?: AddressRange;
|
|
@@ -71,6 +71,12 @@ export interface NextCommand {
|
|
|
71
71
|
export interface QuitCommand {
|
|
72
72
|
type: "quit";
|
|
73
73
|
address?: AddressRange;
|
|
74
|
+
exitCode?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface QuitSilentCommand {
|
|
77
|
+
type: "quitSilent";
|
|
78
|
+
address?: AddressRange;
|
|
79
|
+
exitCode?: number;
|
|
74
80
|
}
|
|
75
81
|
export interface NextAppendCommand {
|
|
76
82
|
type: "nextAppend";
|
|
@@ -122,7 +128,45 @@ export interface GroupCommand {
|
|
|
122
128
|
address?: AddressRange;
|
|
123
129
|
commands: SedCommand[];
|
|
124
130
|
}
|
|
125
|
-
export
|
|
131
|
+
export interface ListCommand {
|
|
132
|
+
type: "list";
|
|
133
|
+
address?: AddressRange;
|
|
134
|
+
}
|
|
135
|
+
export interface PrintFilenameCommand {
|
|
136
|
+
type: "printFilename";
|
|
137
|
+
address?: AddressRange;
|
|
138
|
+
}
|
|
139
|
+
export interface VersionCommand {
|
|
140
|
+
type: "version";
|
|
141
|
+
address?: AddressRange;
|
|
142
|
+
minVersion?: string;
|
|
143
|
+
}
|
|
144
|
+
export interface ReadFileCommand {
|
|
145
|
+
type: "readFile";
|
|
146
|
+
address?: AddressRange;
|
|
147
|
+
filename: string;
|
|
148
|
+
}
|
|
149
|
+
export interface ReadFileLineCommand {
|
|
150
|
+
type: "readFileLine";
|
|
151
|
+
address?: AddressRange;
|
|
152
|
+
filename: string;
|
|
153
|
+
}
|
|
154
|
+
export interface WriteFileCommand {
|
|
155
|
+
type: "writeFile";
|
|
156
|
+
address?: AddressRange;
|
|
157
|
+
filename: string;
|
|
158
|
+
}
|
|
159
|
+
export interface WriteFirstLineCommand {
|
|
160
|
+
type: "writeFirstLine";
|
|
161
|
+
address?: AddressRange;
|
|
162
|
+
filename: string;
|
|
163
|
+
}
|
|
164
|
+
export interface ExecuteCommand {
|
|
165
|
+
type: "execute";
|
|
166
|
+
address?: AddressRange;
|
|
167
|
+
command?: string;
|
|
168
|
+
}
|
|
169
|
+
export type SedCommand = SubstituteCommand | PrintCommand | PrintFirstLineCommand | DeleteCommand | DeleteFirstLineCommand | AppendCommand | InsertCommand | ChangeCommand | HoldCommand | HoldAppendCommand | GetCommand | GetAppendCommand | ExchangeCommand | NextCommand | QuitCommand | QuitSilentCommand | NextAppendCommand | TransliterateCommand | LineNumberCommand | BranchCommand | BranchOnSubstCommand | BranchOnNoSubstCommand | LabelCommand | ZapCommand | GroupCommand | ListCommand | PrintFilenameCommand | VersionCommand | ReadFileCommand | ReadFileLineCommand | WriteFileCommand | WriteFirstLineCommand | ExecuteCommand;
|
|
126
170
|
export interface SedState {
|
|
127
171
|
patternSpace: string;
|
|
128
172
|
holdSpace: string;
|
|
@@ -131,10 +175,30 @@ export interface SedState {
|
|
|
131
175
|
deleted: boolean;
|
|
132
176
|
printed: boolean;
|
|
133
177
|
quit: boolean;
|
|
178
|
+
quitSilent: boolean;
|
|
179
|
+
exitCode?: number;
|
|
134
180
|
appendBuffer: string[];
|
|
135
181
|
substitutionMade: boolean;
|
|
136
182
|
lineNumberOutput: string[];
|
|
137
183
|
restartCycle: boolean;
|
|
184
|
+
currentFilename?: string;
|
|
185
|
+
pendingFileReads: Array<{
|
|
186
|
+
filename: string;
|
|
187
|
+
wholeFile: boolean;
|
|
188
|
+
}>;
|
|
189
|
+
pendingFileWrites: Array<{
|
|
190
|
+
filename: string;
|
|
191
|
+
content: string;
|
|
192
|
+
}>;
|
|
193
|
+
pendingExecute?: {
|
|
194
|
+
command: string;
|
|
195
|
+
replacePattern: boolean;
|
|
196
|
+
};
|
|
197
|
+
rangeStates: Map<string, RangeState>;
|
|
198
|
+
}
|
|
199
|
+
export interface RangeState {
|
|
200
|
+
active: boolean;
|
|
201
|
+
startLine?: number;
|
|
138
202
|
}
|
|
139
203
|
export interface SedExecutionLimits {
|
|
140
204
|
maxIterations: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { BashOptions, ExecOptions } from "./Bash.js";
|
|
1
|
+
export type { BashLogger, BashOptions, ExecOptions } from "./Bash.js";
|
|
2
2
|
export { Bash } from "./Bash.js";
|
|
3
3
|
export type { AllCommandName, CommandName, NetworkCommandName, } from "./commands/registry.js";
|
|
4
4
|
export { getCommandNames, getNetworkCommandNames, } from "./commands/registry.js";
|