shell.grammer package¶
Submodules¶
shell.grammer.literals module¶
shell.grammer.parse_functions module¶
- shell.grammer.parse_functions.expand_variables(terms: List[str], env: dict, completenames_options: List[str], ignore_invalid_syntax: bool, wildcard_value='$', escape=False) Iterable[str] [source]¶
Replace variables with their values. E.g.
a = 1 print $a # gets converted to `print 1`
- shell.grammer.parse_functions.expand_variables_inline(line: str, env: dict, completenames_options: List[str], ignore_invalid_syntax: bool) str [source]¶
Expand $variables in line.
- shell.grammer.parse_functions.indent_width(line: str) Tuple[str, str] [source]¶
Return a tuple that represents the length of the indentation in spaces and tabs.
shell.grammer.parser module¶
Parse tokens. Tokens are defined in shell.grammer.tokenizer
Parsing rules;
lines: a BREAK-separated sequence of line
line: statement with optional INDENT
statement:
- assignment # a = 1
- conditional # if .. then ..
- conjunction # add 1 |> echo
- definition # f (x): ..
- return_statement # return 1
conjunction: a PIPE-separated sequence of expression
expression: a command
Lines with an assignment.
# a b = 10 11 ; print $a ;
|-------------||-----||----------||-----|
assignment break expression break
|-----| |-----|
terms terms
A line with a conjunction.
# range 1 5 |> print '# ' |> print
|----------------------------------------------| (conjunction)
|----------||----||----------------------------|
expression pipe conjunction
|----------| |----------||----||----------|
terms expression pipe expression
|----------| |----------|
terms terms