Skip to content

OSH Word Evaluation Algorithm

andychu edited this page Jul 8, 2019 · 30 revisions

This documents implementation details. OSH differs significantly from other shells in this respect.

  • They tend to use a homogeneous tree with various flags (e.g. nosplit, assignment, etc.).
  • OSH uses a typed, heterogeneous tree (now statically checked with MyPy).

For example, word_part = LiteralPart(...) | BracedVarSub(...) | CommandSub(...) | ...

https://github.com/oilshell/oil/blob/master/frontend/syntax.asdl#L107

Preliminaries

  1. As much parsing as possible is done in a single pass, with lexer modes.
  2. There are some subsequent tweaks for detecting assignments, tildes, etc.
  3. There is a "metaprogramming" pass for brace expansion: i=0; {$((i++)),x,y}

Word Evaluation Algorithm

There are three stages:

  1. Evaluation of the typed tree. (using osh/word_eval.py)
    • There is a stricted variant of word evaluation for completion, e.g. so arbitrary processes aren't run with you hit TAB.
  2. Splitting with IFS. IFS is specified with a state machine.
  3. Globbing.

There is no such thing as "quote removal" in OSH (e.g. any more than a Python or JavaScript interpreter has "quote removal"). It's just evaluation.

Clone this wiki locally