Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shasta extension for libbash #5

Merged
merged 29 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
46b8ebf
Updates to shasta for bash
sethsabar Feb 21, 2024
1037f11
Implemented all types of bash redirects
sethsabar Feb 28, 2024
e9bc760
update redirection structure
sethsabar Mar 2, 2024
73dadf9
fix time node implementation
sethsabar Mar 2, 2024
8355528
all bash tests pass shasta
sethsabar Mar 13, 2024
3617f0b
Shasta passing all bash scripts including those with SOH
sethsabar Mar 13, 2024
55446d4
bug fixes to make sure we're still compatible with dash
sethsabar Apr 14, 2024
bd2690d
minor bug fix
sethsabar Apr 19, 2024
c48c376
bug fix for arith nodes
sethsabar Apr 24, 2024
59303c2
bug fix eof edge case
sethsabar Apr 26, 2024
95ea75c
Integrate bash and dash tests
BolunThompson Dec 4, 2024
6167577
Add global BASH_MODE
BolunThompson Dec 4, 2024
3eae7db
Don't escape dollar signs for bash mode
BolunThompson Dec 4, 2024
bc3d55b
Backport bash changes to python 3.8
BolunThompson Dec 6, 2024
93660aa
Add BashNode superclass marker
BolunThompson Dec 6, 2024
3eb8fe6
Fix type hinting as possible
BolunThompson Dec 6, 2024
d64fde1
Remove unused bash code
BolunThompson Dec 8, 2024
cd751b2
Add bash documentation
BolunThompson Dec 8, 2024
070e805
Add libbash as dependency
BolunThompson Dec 8, 2024
a8c3441
Remove libbash as dependency
BolunThompson Dec 11, 2024
1afbeb8
Fix typo
BolunThompson Dec 11, 2024
fbf8d51
Format new code
BolunThompson Dec 11, 2024
dcf1e32
Fix linting errors
BolunThompson Dec 12, 2024
ea94fec
Refactor utf-8 check
BolunThompson Dec 12, 2024
93ee4dd
Refactor BASH_MODE for global variable
BolunThompson Dec 12, 2024
01db807
Fix code typo
BolunThompson Dec 12, 2024
1a1d50c
Update shasta version
BolunThompson Dec 15, 2024
7beed18
Add case fall through support
BolunThompson Dec 15, 2024
650d818
Fix case bug
BolunThompson Dec 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 36 additions & 0 deletions dash-bash-diffs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Differences between Dash and Bash frontends

Shasta was designed for libdash, with libbash support added later.
Both `json_to_ast` (for libdash) and `bash_to_shasta_ast` (for libbash) contain `to_ast_node(s)` functions,
which each take a parsed, untyped AST and convert it to a shasta AST as defined in `ast_node`.
Thr transformation is direct; bash is assumed to be a subset of dash. This is not strictly true, since
BolunThompson marked this conversation as resolved.
Show resolved Hide resolved
both have some minor divergences from the POSIX spec, but is good enough.

### The following fields of `AstNodes` are only used for Bash scripts:

- `RedirectionNode` and `*RedirNode`: The `fd` field is either `('var', filename)` or `('fixed', fd)`.
Dash only uses the latter form; the first exists to support bashisms like `exec {fd} > log.txt`,
which open the file and assigns `fd` the new file descriptor.
- `FileRedirNode`: 'ReadingString' subtype. Handles here-strings.
- `BackgroundNode`: The `after_ampersand` field. Handles an edge case with heredocs.

The pretty printer uses the various `nobraces` and `semicolon` fields to determine
whether braces and semicolons are printed. In dash, this doesn't matter, but in bash
they can lead to a syntax error. For example:

```bash
( { echo hi; echo bye } )
```

is invalid.

### The following AstNodes are only used for Bash scripts:

- `SelectNode`
- `ArithNode`
- `CondNode`
- `ArithForNode`
- `CoprocNode`
- `TimeNode`
- `SingleArgRedirNode`
- `GroupNode`
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX",
]
dependencies = ["libbash"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am scared of this dependency because I am afraid of dependency hell (either due to circular dependencies or because a downstream program (like PaSh) might want a different version of one and the other).

I guess we don't have this issue with libdash because we use a JSON object? Could we do sth similar here (maybe in a different PR?)? Alternatively, is my fear irrational and we just have to bite the bullet and do it? I am wondering whether someone could use shasta without needing to import libbash and whatever that includes.

Copy link
Contributor Author

@BolunThompson BolunThompson Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your intuition — although I can’t think of an obvious scenario that would cause a problem. The code right now doesn’t actually import anything from libbash (in a runtime capacity) except a handful of enums, so I can easily remove the dependency after copying those over (± some minor changes).


[project.urls]
"Homepage" = "https://github.com/binpash/shasta"
Expand Down
Loading
Loading