just-bash 0.1.5__py3-none-any.whl
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.
- just_bash/__init__.py +55 -0
- just_bash/ast/__init__.py +213 -0
- just_bash/ast/factory.py +320 -0
- just_bash/ast/types.py +953 -0
- just_bash/bash.py +220 -0
- just_bash/commands/__init__.py +23 -0
- just_bash/commands/argv/__init__.py +5 -0
- just_bash/commands/argv/argv.py +21 -0
- just_bash/commands/awk/__init__.py +5 -0
- just_bash/commands/awk/awk.py +1168 -0
- just_bash/commands/base64/__init__.py +5 -0
- just_bash/commands/base64/base64.py +138 -0
- just_bash/commands/basename/__init__.py +5 -0
- just_bash/commands/basename/basename.py +72 -0
- just_bash/commands/bash/__init__.py +5 -0
- just_bash/commands/bash/bash.py +188 -0
- just_bash/commands/cat/__init__.py +5 -0
- just_bash/commands/cat/cat.py +173 -0
- just_bash/commands/checksum/__init__.py +5 -0
- just_bash/commands/checksum/checksum.py +179 -0
- just_bash/commands/chmod/__init__.py +5 -0
- just_bash/commands/chmod/chmod.py +216 -0
- just_bash/commands/column/__init__.py +5 -0
- just_bash/commands/column/column.py +180 -0
- just_bash/commands/comm/__init__.py +5 -0
- just_bash/commands/comm/comm.py +150 -0
- just_bash/commands/compression/__init__.py +5 -0
- just_bash/commands/compression/compression.py +298 -0
- just_bash/commands/cp/__init__.py +5 -0
- just_bash/commands/cp/cp.py +149 -0
- just_bash/commands/curl/__init__.py +5 -0
- just_bash/commands/curl/curl.py +801 -0
- just_bash/commands/cut/__init__.py +5 -0
- just_bash/commands/cut/cut.py +327 -0
- just_bash/commands/date/__init__.py +5 -0
- just_bash/commands/date/date.py +258 -0
- just_bash/commands/diff/__init__.py +5 -0
- just_bash/commands/diff/diff.py +118 -0
- just_bash/commands/dirname/__init__.py +5 -0
- just_bash/commands/dirname/dirname.py +56 -0
- just_bash/commands/du/__init__.py +5 -0
- just_bash/commands/du/du.py +150 -0
- just_bash/commands/echo/__init__.py +5 -0
- just_bash/commands/echo/echo.py +125 -0
- just_bash/commands/env/__init__.py +5 -0
- just_bash/commands/env/env.py +163 -0
- just_bash/commands/expand/__init__.py +5 -0
- just_bash/commands/expand/expand.py +299 -0
- just_bash/commands/expr/__init__.py +5 -0
- just_bash/commands/expr/expr.py +273 -0
- just_bash/commands/file/__init__.py +5 -0
- just_bash/commands/file/file.py +274 -0
- just_bash/commands/find/__init__.py +5 -0
- just_bash/commands/find/find.py +623 -0
- just_bash/commands/fold/__init__.py +5 -0
- just_bash/commands/fold/fold.py +160 -0
- just_bash/commands/grep/__init__.py +5 -0
- just_bash/commands/grep/grep.py +418 -0
- just_bash/commands/head/__init__.py +5 -0
- just_bash/commands/head/head.py +167 -0
- just_bash/commands/help/__init__.py +5 -0
- just_bash/commands/help/help.py +67 -0
- just_bash/commands/hostname/__init__.py +5 -0
- just_bash/commands/hostname/hostname.py +21 -0
- just_bash/commands/html_to_markdown/__init__.py +5 -0
- just_bash/commands/html_to_markdown/html_to_markdown.py +191 -0
- just_bash/commands/join/__init__.py +5 -0
- just_bash/commands/join/join.py +252 -0
- just_bash/commands/jq/__init__.py +5 -0
- just_bash/commands/jq/jq.py +280 -0
- just_bash/commands/ln/__init__.py +5 -0
- just_bash/commands/ln/ln.py +127 -0
- just_bash/commands/ls/__init__.py +5 -0
- just_bash/commands/ls/ls.py +280 -0
- just_bash/commands/mkdir/__init__.py +5 -0
- just_bash/commands/mkdir/mkdir.py +92 -0
- just_bash/commands/mv/__init__.py +5 -0
- just_bash/commands/mv/mv.py +142 -0
- just_bash/commands/nl/__init__.py +5 -0
- just_bash/commands/nl/nl.py +180 -0
- just_bash/commands/od/__init__.py +5 -0
- just_bash/commands/od/od.py +157 -0
- just_bash/commands/paste/__init__.py +5 -0
- just_bash/commands/paste/paste.py +100 -0
- just_bash/commands/printf/__init__.py +5 -0
- just_bash/commands/printf/printf.py +157 -0
- just_bash/commands/pwd/__init__.py +5 -0
- just_bash/commands/pwd/pwd.py +23 -0
- just_bash/commands/read/__init__.py +5 -0
- just_bash/commands/read/read.py +185 -0
- just_bash/commands/readlink/__init__.py +5 -0
- just_bash/commands/readlink/readlink.py +86 -0
- just_bash/commands/registry.py +844 -0
- just_bash/commands/rev/__init__.py +5 -0
- just_bash/commands/rev/rev.py +74 -0
- just_bash/commands/rg/__init__.py +5 -0
- just_bash/commands/rg/rg.py +1048 -0
- just_bash/commands/rm/__init__.py +5 -0
- just_bash/commands/rm/rm.py +106 -0
- just_bash/commands/search_engine/__init__.py +13 -0
- just_bash/commands/search_engine/matcher.py +170 -0
- just_bash/commands/search_engine/regex.py +159 -0
- just_bash/commands/sed/__init__.py +5 -0
- just_bash/commands/sed/sed.py +863 -0
- just_bash/commands/seq/__init__.py +5 -0
- just_bash/commands/seq/seq.py +190 -0
- just_bash/commands/shell/__init__.py +5 -0
- just_bash/commands/shell/shell.py +206 -0
- just_bash/commands/sleep/__init__.py +5 -0
- just_bash/commands/sleep/sleep.py +62 -0
- just_bash/commands/sort/__init__.py +5 -0
- just_bash/commands/sort/sort.py +411 -0
- just_bash/commands/split/__init__.py +5 -0
- just_bash/commands/split/split.py +237 -0
- just_bash/commands/sqlite3/__init__.py +5 -0
- just_bash/commands/sqlite3/sqlite3_cmd.py +505 -0
- just_bash/commands/stat/__init__.py +5 -0
- just_bash/commands/stat/stat.py +150 -0
- just_bash/commands/strings/__init__.py +5 -0
- just_bash/commands/strings/strings.py +150 -0
- just_bash/commands/tac/__init__.py +5 -0
- just_bash/commands/tac/tac.py +158 -0
- just_bash/commands/tail/__init__.py +5 -0
- just_bash/commands/tail/tail.py +180 -0
- just_bash/commands/tar/__init__.py +5 -0
- just_bash/commands/tar/tar.py +1067 -0
- just_bash/commands/tee/__init__.py +5 -0
- just_bash/commands/tee/tee.py +63 -0
- just_bash/commands/timeout/__init__.py +5 -0
- just_bash/commands/timeout/timeout.py +188 -0
- just_bash/commands/touch/__init__.py +5 -0
- just_bash/commands/touch/touch.py +91 -0
- just_bash/commands/tr/__init__.py +5 -0
- just_bash/commands/tr/tr.py +297 -0
- just_bash/commands/tree/__init__.py +5 -0
- just_bash/commands/tree/tree.py +139 -0
- just_bash/commands/true/__init__.py +5 -0
- just_bash/commands/true/true.py +32 -0
- just_bash/commands/uniq/__init__.py +5 -0
- just_bash/commands/uniq/uniq.py +323 -0
- just_bash/commands/wc/__init__.py +5 -0
- just_bash/commands/wc/wc.py +169 -0
- just_bash/commands/which/__init__.py +5 -0
- just_bash/commands/which/which.py +52 -0
- just_bash/commands/xan/__init__.py +5 -0
- just_bash/commands/xan/xan.py +1663 -0
- just_bash/commands/xargs/__init__.py +5 -0
- just_bash/commands/xargs/xargs.py +136 -0
- just_bash/commands/yq/__init__.py +5 -0
- just_bash/commands/yq/yq.py +848 -0
- just_bash/fs/__init__.py +29 -0
- just_bash/fs/in_memory_fs.py +621 -0
- just_bash/fs/mountable_fs.py +504 -0
- just_bash/fs/overlay_fs.py +894 -0
- just_bash/fs/read_write_fs.py +455 -0
- just_bash/interpreter/__init__.py +37 -0
- just_bash/interpreter/builtins/__init__.py +92 -0
- just_bash/interpreter/builtins/alias.py +154 -0
- just_bash/interpreter/builtins/cd.py +76 -0
- just_bash/interpreter/builtins/control.py +127 -0
- just_bash/interpreter/builtins/declare.py +336 -0
- just_bash/interpreter/builtins/export.py +56 -0
- just_bash/interpreter/builtins/let.py +44 -0
- just_bash/interpreter/builtins/local.py +57 -0
- just_bash/interpreter/builtins/mapfile.py +152 -0
- just_bash/interpreter/builtins/misc.py +378 -0
- just_bash/interpreter/builtins/readonly.py +80 -0
- just_bash/interpreter/builtins/set.py +234 -0
- just_bash/interpreter/builtins/shopt.py +201 -0
- just_bash/interpreter/builtins/source.py +136 -0
- just_bash/interpreter/builtins/test.py +290 -0
- just_bash/interpreter/builtins/unset.py +53 -0
- just_bash/interpreter/conditionals.py +387 -0
- just_bash/interpreter/control_flow.py +381 -0
- just_bash/interpreter/errors.py +116 -0
- just_bash/interpreter/expansion.py +1156 -0
- just_bash/interpreter/interpreter.py +813 -0
- just_bash/interpreter/types.py +134 -0
- just_bash/network/__init__.py +1 -0
- just_bash/parser/__init__.py +39 -0
- just_bash/parser/lexer.py +948 -0
- just_bash/parser/parser.py +2162 -0
- just_bash/py.typed +0 -0
- just_bash/query_engine/__init__.py +83 -0
- just_bash/query_engine/builtins/__init__.py +1283 -0
- just_bash/query_engine/evaluator.py +578 -0
- just_bash/query_engine/parser.py +525 -0
- just_bash/query_engine/tokenizer.py +329 -0
- just_bash/query_engine/types.py +373 -0
- just_bash/types.py +180 -0
- just_bash-0.1.5.dist-info/METADATA +410 -0
- just_bash-0.1.5.dist-info/RECORD +193 -0
- just_bash-0.1.5.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Interpreter types for just-bash."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import TYPE_CHECKING, Callable, Optional, Awaitable
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from ..ast.types import FunctionDefNode, ScriptNode, StatementNode, CommandNode
|
|
8
|
+
from ..types import ExecResult, IFileSystem, Command, ExecutionLimits
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class ShellOptions:
|
|
13
|
+
"""Shell options (set -e, etc.)."""
|
|
14
|
+
|
|
15
|
+
errexit: bool = False
|
|
16
|
+
"""set -e: Exit immediately if a command exits with non-zero status."""
|
|
17
|
+
|
|
18
|
+
pipefail: bool = False
|
|
19
|
+
"""set -o pipefail: Return exit status of last failing command in pipeline."""
|
|
20
|
+
|
|
21
|
+
nounset: bool = False
|
|
22
|
+
"""set -u: Treat unset variables as an error when substituting."""
|
|
23
|
+
|
|
24
|
+
xtrace: bool = False
|
|
25
|
+
"""set -x: Print commands and their arguments as they are executed."""
|
|
26
|
+
|
|
27
|
+
verbose: bool = False
|
|
28
|
+
"""set -v: Print shell input lines as they are read."""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class InterpreterState:
|
|
33
|
+
"""Mutable state maintained by the interpreter."""
|
|
34
|
+
|
|
35
|
+
env: dict[str, str] = field(default_factory=dict)
|
|
36
|
+
"""Environment variables."""
|
|
37
|
+
|
|
38
|
+
cwd: str = "/home/user"
|
|
39
|
+
"""Current working directory."""
|
|
40
|
+
|
|
41
|
+
previous_dir: str = "/home/user"
|
|
42
|
+
"""Previous directory (for cd -)."""
|
|
43
|
+
|
|
44
|
+
functions: dict[str, "FunctionDefNode"] = field(default_factory=dict)
|
|
45
|
+
"""Defined functions."""
|
|
46
|
+
|
|
47
|
+
local_scopes: list[dict[str, Optional[str]]] = field(default_factory=list)
|
|
48
|
+
"""Stack of local variable scopes for function calls."""
|
|
49
|
+
|
|
50
|
+
call_depth: int = 0
|
|
51
|
+
"""Current function call depth."""
|
|
52
|
+
|
|
53
|
+
source_depth: int = 0
|
|
54
|
+
"""Current source script nesting depth."""
|
|
55
|
+
|
|
56
|
+
command_count: int = 0
|
|
57
|
+
"""Total commands executed (for limits)."""
|
|
58
|
+
|
|
59
|
+
last_exit_code: int = 0
|
|
60
|
+
"""Exit code of last command."""
|
|
61
|
+
|
|
62
|
+
last_arg: str = ""
|
|
63
|
+
"""Last argument of previous command (for $_)."""
|
|
64
|
+
|
|
65
|
+
start_time: float = 0.0
|
|
66
|
+
"""Time when shell started (for $SECONDS)."""
|
|
67
|
+
|
|
68
|
+
last_background_pid: int = 0
|
|
69
|
+
"""PID of last background job (for $!)."""
|
|
70
|
+
|
|
71
|
+
current_line: int = 0
|
|
72
|
+
"""Current line number being executed (for $LINENO)."""
|
|
73
|
+
|
|
74
|
+
options: ShellOptions = field(default_factory=ShellOptions)
|
|
75
|
+
"""Shell options."""
|
|
76
|
+
|
|
77
|
+
in_condition: bool = False
|
|
78
|
+
"""True when executing condition for if/while/until."""
|
|
79
|
+
|
|
80
|
+
loop_depth: int = 0
|
|
81
|
+
"""Current loop nesting depth (for break/continue)."""
|
|
82
|
+
|
|
83
|
+
parent_has_loop_context: bool = False
|
|
84
|
+
"""True if spawned from within a loop context."""
|
|
85
|
+
|
|
86
|
+
group_stdin: Optional[str] = None
|
|
87
|
+
"""Stdin for commands in compound commands."""
|
|
88
|
+
|
|
89
|
+
readonly_vars: set[str] = field(default_factory=set)
|
|
90
|
+
"""Set of readonly variable names."""
|
|
91
|
+
|
|
92
|
+
expansion_exit_code: Optional[int] = None
|
|
93
|
+
"""Exit code from expansion errors."""
|
|
94
|
+
|
|
95
|
+
expansion_stderr: str = ""
|
|
96
|
+
"""Stderr from expansion errors."""
|
|
97
|
+
|
|
98
|
+
associative_arrays: set[str] = field(default_factory=set)
|
|
99
|
+
"""Set of associative array variable names."""
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass
|
|
103
|
+
class InterpreterContext:
|
|
104
|
+
"""Context provided to interpreter methods."""
|
|
105
|
+
|
|
106
|
+
state: InterpreterState
|
|
107
|
+
"""Mutable interpreter state."""
|
|
108
|
+
|
|
109
|
+
fs: "IFileSystem"
|
|
110
|
+
"""Filesystem interface."""
|
|
111
|
+
|
|
112
|
+
commands: dict[str, "Command"]
|
|
113
|
+
"""Command registry."""
|
|
114
|
+
|
|
115
|
+
limits: "ExecutionLimits"
|
|
116
|
+
"""Execution limits."""
|
|
117
|
+
|
|
118
|
+
exec_fn: Callable[[str, Optional[dict[str, str]], Optional[str]], Awaitable["ExecResult"]]
|
|
119
|
+
"""Function to execute a script string."""
|
|
120
|
+
|
|
121
|
+
execute_script: Callable[["ScriptNode"], Awaitable["ExecResult"]]
|
|
122
|
+
"""Function to execute a script AST."""
|
|
123
|
+
|
|
124
|
+
execute_statement: Callable[["StatementNode"], Awaitable["ExecResult"]]
|
|
125
|
+
"""Function to execute a statement AST."""
|
|
126
|
+
|
|
127
|
+
execute_command: Callable[["CommandNode", str], Awaitable["ExecResult"]]
|
|
128
|
+
"""Function to execute a command AST."""
|
|
129
|
+
|
|
130
|
+
fetch: Optional[Callable[[str], Awaitable[bytes]]] = None
|
|
131
|
+
"""Optional secure fetch function for network commands."""
|
|
132
|
+
|
|
133
|
+
sleep: Optional[Callable[[float], Awaitable[None]]] = None
|
|
134
|
+
"""Optional sleep function for testing with mock clocks."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Network module for just-bash."""
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Parser module for just-bash."""
|
|
2
|
+
|
|
3
|
+
from .lexer import (
|
|
4
|
+
Lexer,
|
|
5
|
+
Token,
|
|
6
|
+
TokenType,
|
|
7
|
+
tokenize,
|
|
8
|
+
HeredocInfo,
|
|
9
|
+
is_valid_name,
|
|
10
|
+
is_valid_assignment_lhs,
|
|
11
|
+
RESERVED_WORDS,
|
|
12
|
+
)
|
|
13
|
+
from .parser import (
|
|
14
|
+
Parser,
|
|
15
|
+
ParseException,
|
|
16
|
+
parse,
|
|
17
|
+
MAX_INPUT_SIZE,
|
|
18
|
+
MAX_TOKENS,
|
|
19
|
+
MAX_PARSE_ITERATIONS,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
# Lexer
|
|
24
|
+
"Lexer",
|
|
25
|
+
"Token",
|
|
26
|
+
"TokenType",
|
|
27
|
+
"tokenize",
|
|
28
|
+
"HeredocInfo",
|
|
29
|
+
"is_valid_name",
|
|
30
|
+
"is_valid_assignment_lhs",
|
|
31
|
+
"RESERVED_WORDS",
|
|
32
|
+
# Parser
|
|
33
|
+
"Parser",
|
|
34
|
+
"ParseException",
|
|
35
|
+
"parse",
|
|
36
|
+
"MAX_INPUT_SIZE",
|
|
37
|
+
"MAX_TOKENS",
|
|
38
|
+
"MAX_PARSE_ITERATIONS",
|
|
39
|
+
]
|