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

consider an IR for words and ${} #604

Open
andychu opened this issue Feb 17, 2020 · 2 comments
Open

consider an IR for words and ${} #604

andychu opened this issue Feb 17, 2020 · 2 comments

Comments

@andychu
Copy link
Contributor

andychu commented Feb 17, 2020

These are confusing to disambiguate from the LST:

  • ${!ref-default} -- prefix_op and unary suffix op
  • ${!prefix@} -- prefix_op and nullary suffix_op
  • ${!array_keys[@]} -- prefix op and bracket op

We could compile it to something like:

braced_var_sub =   Ref(...) | Prefix(...) | Keys(...)

instead of prefix_op / suffix_op / bracket_op

It could be a step that's analogous to BraceExpand. It could be done at parse time, but we don't print the LST with it.

  • So maybe store functions with the more compact representation? But top-level code does it at runtime. Hm.

For words

  • osh/word_compile.py
    • $'c style \n strings' are evaluated at runtime, but they don't have to be
    • triple_quoted has the same issue? Has to strip leading space
  • We don't really need to do detection and expansion of brace substitutions separately. That was more for the LST invariant ...
@andychu
Copy link
Contributor Author

andychu commented Mar 8, 2020

NOTE: sh_lhs_expr is sort of an IR because it's used for both:

  • (( x = 42 )) and (( a[i] = 42 ))
  • x=42 and a[i]=42 (no spaces allowed)

edit: Actually it's not an IR because we don't make separate syntax tree nodes first. It's a rare case of losing information! We could make it more like one.

@andychu
Copy link
Contributor Author

andychu commented Apr 5, 2020

Note: This is done for arithmetic, e.g. for #640 and also for #651

Not sure about ${}, that may not happen for awhile.

andychu pushed a commit that referenced this issue Apr 5, 2020
andychu pushed a commit that referenced this issue Apr 5, 2020
Also refactor the code to handle the prefix query up front.

We might want to do the ${} IR in #604 to make this code simpler.

Addresses issue reported in #653.
@andychu andychu changed the title consider an IR for ${}, and consider one for a[i]=x consider an IR for ${} Jun 22, 2020
@andychu andychu changed the title consider an IR for ${} consider an IR for words and ${} Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant