Commit Graph

15 Commits

Author SHA1 Message Date
Timothy Sample ff14ea0097 Rename '<sh-define>' to '<sh-defun>' and simplify
This change is already in the syntax document.

* geesh/parser.scm (make-parser): Rename '<sh-define>' to '<sh-defun>'
and use the function name directly instead of making it a singleton
list.
* tests/parser.scm: Update tests.
* .dir-locals.el: Update indentation.
2018-11-02 14:35:34 -04:00
Timothy Sample 2d61e91b27 Flatten AST form for pipelines
* geesh/parser.scm (make-parser): Splice in commands to keep
'<sh-pipeline>' flat.
* tests/parser.scm: Adjust and add tests accordingly.
2018-07-19 01:28:43 -04:00
Timothy Sample c79cea756d Rename '<sh-pipe>' to '<sh-pipeline>'
* doc/syntax.txt: Rename '<sh-pipe>' to '<sh-pipeline>'.
* geesh/parser.scm (make-parser): Ditto.
* tests/parser.scm: Fix test accordingly.
2018-07-19 01:19:00 -04:00
Timothy Sample 2aa8615f9e Update AST for command substitutions
The AST generated by the parser did not match the syntax document.
However, neither were right.  This commit updates the syntax document
to describe a more consistent form, and fixes the code to follow it.

* doc/syntax.txt (word): Make the children of '<sh-cmd-sub>' a
possibly empty list of 'list's.
* geesh/lexer.scm (get-bracketed-command): Splice in children for
'<sh-cmd-sub>'.
(get-backquoted-command): Ditto.
* geesh/parser.scm (read-sh/bracketed): Make sure that result is
always a list.
(read-sh/backquoted): Ditto.
* tests/lexer.scm: Update tests accordingly.
* tests/parser.scm: Ditto.
2018-07-18 14:27:11 -04:00
Timothy Sample da1d561f22 Fix AST to prevent empty '<sh-exec-let>' bindings
Commands with prefix redirects and no arguments or assignments would
generate '<sh-exec-let>' forms with an empty list for bindings.

* geesh/parser.scm (make-parser): Check for and handle an empty
assignment list.
* tests/parser.scm: Add test.
2018-07-17 22:27:10 -04:00
Timothy Sample a711daefa8 Fix an accidental AST format change
Commit b807b72a7c changed the AST format
when reading single commands by mistake.  It caused 'read-sh' to
return a singleton list.

* geesh/parser.scm (make-parser): Restore old behaviour.
(read-sh-all): Convert the output from the parser into a list.
* tests/parser.scm: Add tests to make sure 'read-sh-all' always
returns a list.
2018-07-16 13:09:51 -04:00
Timothy Sample b807b72a7c Add function for reading whole files
* geesh/parser.scm (read-sh-all): New public function for reading all
commands from a port.
(make-parser): Simplify AST forms when reading multiple commands.
* tests/parser.scm: Test it.
2018-07-16 10:18:59 -04:00
Timothy Sample aabfd76beb Add parser support for here-documents
* geesh/parser.scm (map+fold): New function.
(merge-here-docs): New function.
(remove-quotes): New function.
(read-here-docs): New function.
(make-lexer): Handle newlines and here-document operators specially,
and emit special 'HERE-DOC' and 'HERE-DOC-SEP' tokens.
(make-parser): Use new tokens to support here-documents.
* tests/parser.scm: Add tests for here-documents.
2018-07-15 20:28:04 -04:00
Timothy Sample faf89ad173 Delay processing of dup redirect words
The right-hand side of a dup redirect ("<&" and ">&") may contain
expansions, so we cannot process it during parsing.

* geesh/parser.scm (process-dup-or-close-word): Remove function.
(make-parser): Return the raw word from a dup redirect instead of
trying to convert it into a number or a symbol.
* tests/parser.scm: Fix tests accordingly.
2018-07-15 19:47:10 -04:00
Timothy Sample 7cf2c3d806 Fix handling of reserved words in commands
A reserved word should not be special when it is an argument to a
command.  This commit makes the parser treat reserved words as normal
arguments.  Note that this change exposed problems in many of the
parser tests, which relied on reserved words delimiting commands where
they should not.  Those are now fixed.

* geesh/parser.scm (make-parser): Add reserved words to the default
'WORD*' rule, and use a new rule without reserved words for command
names.
* tests/parser.scm: Add a test for reserved words as arguments, and
fix old tests that relied on the old, incorrect behaviour.
2018-07-15 19:46:14 -04:00
Timothy Sample 7d27433a32 Use '<sh-begin>' for lists of commands
* geesh/parser.scm (make-parser): Put '<sh-begin>' at the beginning of
lists of commands.
* tests/parser.scm: Update tests accordingly.
2018-07-15 19:46:14 -04:00
Timothy Sample e410d1eac3 Add missing license prefix
* tests/parser.scm: Add missing license prefix.
2018-07-15 19:46:14 -04:00
Timothy Sample 2b05199562 Flatten AST form for multiple assignments
* geesh/parser.scm (make-parser): Instead of using a nested list for
assignments, use a flat list.
* tests/parser.scm: Adjust existing test for this (which checks a
single assignment) and add a second test which checks multiple
assignments.
2018-07-15 19:45:31 -04:00
Timothy Sample 2f5d074ca3 Add a parser test for redirects without commands
* tests/parser.scm: Add the test.
2018-07-11 21:54:43 -04:00
Timothy Sample 69c3f9e6ad Add parser
* geesh/parser.scm: New file.
* tests/parser.scm: New file.
* Makefile.am: Add them.
* .dir-locals.el: New file. Include indenting rules for Shell AST
forms and 'call-with-backquoted-input-port'.
2018-02-01 00:14:12 -05:00