Commit Graph

50 Commits

Author SHA1 Message Date
Kenneth Skovhus 08cf72b615 [WIP] Support multiple statements (#26)
* Rename prebuild target clashing with build target

* Add test:watch target and documentation

* Support multiple statements in substitutions

* Inline the _statements rule

This removes a reduction step by the `_statements -> _statement` rule,
which avoids a reduce/reduce conflict between `_statements` and
`command`.
2018-08-06 10:39:05 -07:00
Kenneth Skovhus 9bbd80dee1 Add support for C-style for statements (#23) 2018-08-05 19:25:19 -07:00
Kenneth Skovhus 886a957d1e Add support for strings ending with $ (#24) 2018-08-02 16:32:30 -07:00
Max Brunsfeld 065a4ec425 Rework test expressions
Fixes #11
2018-05-24 11:47:12 -07:00
Max Brunsfeld 73d6705bc2 Allow other redirects between a heredoc's delimiter and body
Fixes #16
2018-03-29 09:54:08 -07:00
Max Brunsfeld 2d96fc5fcb Add more code to the case statements test 2018-03-16 15:41:09 -07:00
Max Brunsfeld 68e93bd898 Allow for statements without in clauses 2018-03-02 10:18:42 -08:00
Max Brunsfeld 87a832d94e Allow regexes after '==', not just '=~' 2018-03-01 14:22:38 -08:00
Max Brunsfeld c7484ad85f Allow ;; at end of line of case item 2018-03-01 14:04:29 -08:00
Max Brunsfeld 0791027596 Add regex syntax inside of expansions 2018-03-01 10:41:16 -08:00
Max Brunsfeld f33bf06de2 Distinguish unset commands from regular commands 2018-03-01 10:12:10 -08:00
Max Brunsfeld 69d64558a3 Rename control_flow test file to statements 2018-03-01 10:06:38 -08:00
Max Brunsfeld 384d920af5 Allow $ in strings 2018-03-01 09:54:08 -08:00
Max Brunsfeld c7e42b8e96 Add special lexing for regexes after `=~` 2018-03-01 09:53:10 -08:00
Max Brunsfeld 0d9f854862 Revert "Don't parse square bracket commands as special syntax"
This reverts commit c34619a1c4.

Bracket command syntax was actually not interfering with the parsing
of words with special characters.
2018-02-28 22:46:47 -08:00
Max Brunsfeld 4920373ca4 Add special variable @, expressions in declarations 2018-02-28 17:32:48 -08:00
Max Brunsfeld 87b3276186 Generalize case statement parsing
* Fix handling of '|' in case items
* Don't require ;; for last case item

Fixes #8
2018-02-28 16:29:42 -08:00
Max Brunsfeld 2a5b01b885 Generalize parsing of expansion operators 2018-02-28 16:28:55 -08:00
Max Brunsfeld 86c5561ba8 Allow file redirects on while statements 2018-02-28 16:28:30 -08:00
Max Brunsfeld 6f81608535 Always lex braces and brackets as separate tokens
The lexer needs to always return braces and brackets separately so that
the parser can decide if they are part of some construct like an array
subscript or a variable expansion. This means that there was no point
in moving bare-word tokenization into the external scanner. I've moved
it back into the normal scanner.

The tricky part is how to deal with the separate '}' and ']' tokens
in the case where they are *not* part of a subscript or an expansion.
For example, in code like `echo {hi}`, the syntax tree should still
clearly indicate that only *one* argument is being passed to echo.
For now, we achieve this by grouping the '{', hi, and '}' tokens into
a single `concatenation` node, which is a bit odd, but it's the best
we can do.
2018-02-28 14:33:50 -08:00
Max Brunsfeld c34619a1c4 Don't parse square bracket commands as special syntax 2018-02-28 14:32:58 -08:00
Mads Hartmann c410548caf Handle escape sequences in strings (#7)
This should fix #6
2018-02-28 12:15:05 -08:00
Max Brunsfeld 675a581839 Allow special characters in bare word arguments
I've moved tokenization of bare words into the external scanner. This
way we can keep the grammar simple, but support some fancy rules that
I've inferred from experimenting with bash:

- Only allow '}' inside of a bare word if '}' isn't a valid lookahead
token (i.e. we're not inside of a variable expansion).
- Only allow ']' at the *start* of a bare word if neither ']' nor ']]'
are valid lookahead tokens (i.e. we're not inside of a square bracket
command or an array subscript).
- Parentheses seem to never be allowed in bare words. You have to quote
them.

For alphanumeric words, I fall through to the normal scanner so that it
can continue to distinguish reserved words from other words.

Fixes #5
2018-02-27 16:55:20 -08:00
Max Brunsfeld 8a0a4a8501 Parse for loop identifier as a variable name
Also remove some duplication in expression and concatenation
2018-02-27 13:46:36 -08:00
Mads Hartmann 8ca2ecd52d Add support for exporting environment variables (#4)
* Add support for exporting environment variables

* Support multiple exports in one command

Also improves the structure of the AST so the variable name and the
assigned expression aren't free-floating

* Allow for multiple declarations in local declarations as well

Simplify the generated nodes.

* Commit generated code

* Consolidate declarations into a single declaration_command

This also adds support for declare, typeset, and readonly

* Rename environment_variable_assignment to variable_assignment
2018-02-27 13:22:28 -08:00
Mads Hartmann 0ed39445d3 Support local variable declarations 2018-02-25 00:02:24 +01:00
Mads Hartmann 741cfce4b4 Handle empty default value during variable expansion (#1)
* Handle empty default value during variable expansion

* Make expression after colon optional

As suggested by @maxbrunsfeld
2018-02-24 13:40:43 -08:00
Max Brunsfeld 145d4e86a4 Add missing array syntax 2017-12-26 14:55:37 -08:00
Max Brunsfeld 52d54bb173 Add missing function definition forms 2017-12-26 14:27:05 -08:00
Max Brunsfeld dce4ee6937 Handle words concatenated with strings and expansions 2017-07-17 10:47:34 -07:00
Max Brunsfeld 403361626d Add length operator in variable expansions 2017-07-15 23:12:22 -07:00
Max Brunsfeld 3abfbbd7bd Handle strings containing command substitutions 2017-07-15 22:41:56 -07:00
Max Brunsfeld 5081293f65 Add process substitutions 2017-07-15 22:22:38 -07:00
Max Brunsfeld 1b5e1557f2 Reorganize, rename a bunch of things 2017-07-15 22:13:55 -07:00
Max Brunsfeld f73de068e7 Add for statements 2017-07-14 17:51:06 -07:00
Max Brunsfeld 66693d7575 Add empty environment variable values 2017-07-14 17:41:14 -07:00
Max Brunsfeld 6d341b8314 Add function definitions 2017-07-14 17:35:51 -07:00
Max Brunsfeld 5446533c20 Add quoted command names, subshells 2017-07-14 17:32:55 -07:00
Max Brunsfeld a0406c8906 Fix distinction between numeric args and redirect file descriptors 2017-07-14 17:14:23 -07:00
Max Brunsfeld 86e67f9403 Add quoted arguments, bracket expressions 2017-07-14 16:47:25 -07:00
Max Brunsfeld 5b26947ca8 Add case statements 2017-07-14 16:29:28 -07:00
Max Brunsfeld 9f38e36bc3 Add if statements 2017-07-14 16:18:46 -07:00
Max Brunsfeld cce4a65d33 Add while statements 2017-07-14 16:11:35 -07:00
Max Brunsfeld d68e65d8f9 Add escaped newlines 2017-07-14 14:39:28 -07:00
Max Brunsfeld 5a9bfe1571 Add comments 2017-07-14 14:34:49 -07:00
Max Brunsfeld a46748839e Add variable expansion inside of heredocs 2017-07-14 14:27:13 -07:00
Max Brunsfeld 6be8857926 Start work on heredocs 2017-07-14 13:54:05 -07:00
Max Brunsfeld d2ac184c81 Add variable expansions 2017-07-14 13:00:41 -07:00
Max Brunsfeld af279907bb Add file redirects 2017-07-14 12:43:42 -07:00
Max Brunsfeld ab1d553e1d Initial commit 2017-07-14 12:28:54 -07:00