Commit Graph

132 Commits

Author SHA1 Message Date
Jan Nieuwenhuizen 7640a09382 Support redirects with empty commands.
* gash/eval.scm (exp->thunk): Return 'noop' if 'exp' is '#f'.
* tests/50-redirect-clobber.sh: New file.
* tests/50-redirect-clobber.stdout: New file.
* Makefile.am (FULL_TESTS): Add tests/50-redirect-clobber.sh.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2019-05-20 01:18:36 -04:00
Jan Nieuwenhuizen 13f43973f5 Do not export unset variables.
* gash/environment.scm (get-environ): Filter out unset variables.
* tests/42-sh-export-new.sh: New file.
* tests/42-sh-export-new.stdout: New file.
* Makefile.am (FULL_TESTS): Add tests/42-sh-export-new.sh.
(XFAIL_TESTS): Remove tests/42-export-new.sh and tests/42-sh-export.sh.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2019-05-20 01:18:22 -04:00
Timothy Sample 50473ac9d4 Add copyright sign to headers.
* gash/built-ins/*, gash/environment.scm, gash/eval.scm,
gash/lexer.scm, gash/parser.scm, gash/repl.scm, gash/word.scm,
tests/unit/*, tools/coverage.in: Add copyright sign to headers.
2019-05-20 01:18:22 -04:00
Jan Nieuwenhuizen 2e4e078975 Fix some environment-dependent tests.
* gash/environment.scm (initial-variables): Add 'SHELL' and 'SHELLOPTS'.
* tests/100-cd.sh, tests/100-cd.stdout: Use '/tmp' instead of '/bin'.
* tests/50-redirect-in-out.sh, tests/50-redirect-space.sh,
tests/50-redirect.sh: Use '/tmp' and PID for temporary files.
* tests/50-redirect-sed.sh: Make sure 'DESTDIR' is unset and use
'/bin/GASH' in place of '/bin/gash'.
* tests/50-redirect-sed.stdout, tests/data/diff.scm: Use '/bin/GASH' in
place of '/bin/gash'.
* Makefile.am (FULL_TESTS): Add tests/50-redirect-sed.sh,
tests/50-redirect-space.sh, and tests/100-cd.sh; remove
tests/50-redirect-merge.sh.
(BROKEN_TESTS): Remove tests/10-if-redirect.sh,
tests/50-redirect-sed.sh, tests/50-redirect-space.sh, and
tests/100-cd.sh; add tests/50-redirect-merge.sh.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2019-05-20 01:18:07 -04:00
Jan Nieuwenhuizen 56610b0669 Add export test.
* tests/42-export-new.sh: New file.
* tests/42-export-new.stdout: New file.
* Makefile.am (FULL_TESTS, XFAIL_TESTS): Add 42-export-new.sh.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2019-05-20 01:17:57 -04:00
Timothy Sample 1bd92e2893 Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.

Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-05-20 01:17:40 -04:00
Timothy Sample 171796317f Remove external commands.
* gash/bournish-commands.scm, gash/commands/*, gash/compress.scm,
gash/guix-utils.scm, gash/lzw.scm, gash/ustar.scm: Delete files.
* gash/builtins.scm, gash/gash.scm, gash/script.scm: Remove references
to deleted modules.
* tests/100-basename-*, tests/100-dirname-*, tests/100-sed-*,
tests/100-tar-*, tests/100-tr-*: Delete files.
* Makefile.am: Remove deleted modules and tests.
2019-05-16 10:49:38 -04:00
Timothy Sample 117a33d18e Use Automake to run Gash tests.
* Makefile.am: Add Gash tests and use test.sh as the log compiler.
* test.sh: Use TEST_SHELL instead of SHELL to parameterize which shell
is being tested.
* tests/06-command-compound-word.sh: Adjust this test so that it works
even if the srcdir variable is set.
* .gitignore: Add tests/*.trs
2019-05-16 10:49:38 -04:00
Timothy Sample 3584866b73 Remove special characters from test names.
* tests/01-script-$0.sh: Rename this...
* tests/01-script-arg-0.sh: ...to this.
* tests/01-script-$#.sh: Rename this...
* tests/01-script-arg-length.sh: ...to this.
* tests/01-script-$#.stdout: Rename this...
* tests/01-script-arg-length.stdout: ...to this.
* tests/01-script-$@.sh: Rename this...
* tests/01-script-arg-list.sh: ...to this.
* tests/01-script-$@.stdout: Rename this...
* tests/01-script-arg-list.stdout: ...to this.
* check.sh: Update test names.
2019-05-16 10:49:38 -04:00
Timothy Sample fe7a322d4e Move test/* to tests.
* test/*: Move these...
* tests: ...to this directory.
* check.sh, test.sh, .gitignore: Update references.
2019-05-16 10:49:38 -04:00
Timothy Sample c5f2f56268 Move test data to tests/data.
* test/data/*: Move these...
* tests/data: ...to this directory.
* test/20-pipe-sed-cat.sh, test/20-pipe-sed-cat.stdout,
test/20-pipe-sed.sh, test/20-pipe-sed.stdout, test/41-dot.sh,
test/42-sh-export.sh, test/42-sh.sh, test/50-redirect-in-out.sh,
test/50-redirect-in.sh, test/50-redirect-sed.sh, test/60-subst.sh,
test/100-sed-autoconf-basename.sh, test/100-sed-file.sh,
test/100-sed-fooRbar.sh, test/100-tar-Z-old.sh,
test/100-tar-Z-old.stdout, test/100-tar-Z-pipe.sh,
test/100-tar-Z-pipe.stdout, test/100-tar-Z.sh, test/100-tar-Z.stdout,
test/100-tar-ro.sh, test/100-tar.sh, test/100-tar.stdout,
test/100-tr.sh: Update references.
2019-05-16 10:49:38 -04:00
Timothy Sample 110167674e Reorganize tests
* tests/bash-without-bash.scm: Move this...
* tests/bootstrap/bash-without-bash.scm: ...here.
* tests/*.scm*: Move these...
* tests/unit: ...into this directory.
* configure.ac: Update paths.
* Makefile.am: Ditto.
* .gitignore: Ditto.
2018-12-12 14:23:09 -05:00
Timothy Sample 15ae84bc58 Add test for bootstrapping Bash
* tests/bash-without-bash.scm: New file.
* Makefile.am (check-bootstrap): New target.
2018-12-05 22:21:30 -05:00
Timothy Sample 118750bb79 Handle here-documents everywhere
This commit fixes a problem with the old method of handling
here-documents.  We used to ignore here-documents in many places where
they are valid (e.g., between Boolean operators).  They are now valid
after any 'NEWLINE' token.  To achieve this, the handling logic was
moved out of the parser and into the lexer.  We now use a hook
mechanism to manage the necessary communication between the parser and
lexer.

* geesh/parser.scm (read-here-docs): Return strings instead of tokens.
(make-lexer): Add here-docs-hook as a keyword argument, and call it
after reading here-documents.
(make-parser): Let command-hooks transform commands, and remove
here-document handling rules.
(parse): Handle merging here-documents into commands.
* tests/parser.scm: Add tests for many less-intuitive here-document
locations.
2018-12-05 16:08:09 -05:00
Timothy Sample 6a68c73a7b Enable a test from the redirect spec. tests
* tests/spec/oil.scm: Enable a redirect test that requires errexit.
2018-12-05 16:08:09 -05:00
Timothy Sample 0ec3ed02a0 Enable the errexit specification test
* tests/spec/Makefile.am (TESTS): Add errexit.
* tests/spec/oil.scm: Filter and modify five of its tests.
2018-12-05 16:08:09 -05:00
Timothy Sample af75931948 Process options passed to the set built-in
* geesh/built-ins/set.scm (option?): New function.
(option-letter?): New function.
(set-option!): New function.
(main): Set or print options as specified by the given arguments.
* tests/spec/oil.scm: Filter out a redirect test that was only passing
because set did not work.
2018-12-05 16:08:09 -05:00
Timothy Sample 8c061471d3 Handle command not found with status 127
* geesh/shell.scm (sh:exec-let): Print a message and set the status to
127 when path search fails.
* tests/shell.scm: Update test.
2018-12-05 16:08:09 -05:00
Timothy Sample 36e4811d22 Pass options through when running spec. tests
tests/spec/Makefile.am (oil/bin/geesh): Pass options through.
2018-12-05 16:08:09 -05:00
Timothy Sample 4ef6907851 Globalize the environment module
Instead of passing around references to the environment, just treat it
as a global.  The old way was just the remains of an idea to make the
environment immutable and keep the interpreter from manipulating any
global state.  By making everything global and mutable, we will have
less impedance mismatch with POSIX going forward.

The following changelog is only a sketch, since nearly every function
has changed.

* geesh/environment.scm: Replace this module with one that treats the
environment as a global resource.
* tests/environment.scm: Delete file.
* Makefile.am: Remove it from the list of tests.
* geesh/shell.scm, geesh/eval.scm, geesh/repl.scm, geesh/word.scm,
geesh/built-ins/break.scm, geesh/built-ins/continue.scm,
geesh/built-ins/echo.scm, geesh/built-ins/export.scm,
geesh/built-ins/false.scm, geesh/built-ins/read.scm,
geesh/built-ins/readonly.scm, geesh/built-ins/set.scm,
geesh/built-ins/true.scm, geesh/built-ins/unset.scm: Remove 'env'
parameters and use the new environment module.
* .dir-locals.el: Update indentation of functions that no longer take
an 'env' parameter and add with-arguments, with-environ, and
with-variables from the new environment module.
* tests/shell.scm, tests/word.scm: Update environment creation and
manipulation in tests.
2018-12-05 16:08:09 -05:00
Timothy Sample dd64f22361 Enable 'loop' specification test
* tests/spec/Makefile.am (TESTS): Add 'loop'.
* tests/spec/oil.scm: Remove one test and patch four others.
2018-12-05 16:08:09 -05:00
Timothy Sample a5a1f85aa7 Enable 'case_' specification test
* tests/spec/Makefile.am (TESTS): Add 'case_'.
* tests/spec/oil.scm: Filter out two Bash-specific tests.
2018-12-05 16:08:09 -05:00
Timothy Sample e1ab2ccd94 Add pattern module
* geesh/pattern.scm: New file.
* tests/pattern.scm: New file.
* Makefile.am: Add them.
2018-12-05 16:08:09 -05:00
Timothy Sample da71aed3e3 Enable 'var-sub' specification test
* tests/spec/Makefile.am (TESTS): Add 'var-sub'.
* tests/spec/oil.scm: Patch three of its tests.
2018-12-05 16:08:09 -05:00
Timothy Sample 420ade9658 Enable 'quote' specification test
* tests/spec/Makefile.am (TESTS): Add 'quote'.
* tests/spec/oil.scm: Patch two of its tests and filter out six
others.
2018-12-05 16:08:09 -05:00
Timothy Sample 06a0b5f885 Set PYTHONIOENCODING before running tests
* tests/spec/check-spec: Set PYTHONIOENCODING to 'utf-8' before
running tests.
2018-12-05 16:08:09 -05:00
Timothy Sample f33669e636 Remove the BusyBox shell from specification tests
* tests/spec/oil.scm: Patch the test suite script to prevent it from
trying to run the BusyBox shell.
2018-12-05 16:08:09 -05:00
Timothy Sample 6805fc37b4 Patch and enable some specification tests
* tests/spec/oil.scm: Patch and enable five tests that were only
failing due to trivialities.
2018-12-05 16:08:09 -05:00
Timothy Sample 8fe509359d Add specification test patching
Sometimes we need to make minor changes to the tests to make them work
for us.  This patch enables doing search and replace on a test-by-test
basis.

* tests/spec/oil.scm: Allow for tests to be modified.
2018-12-05 16:08:09 -05:00
Timothy Sample ab30ebd14e Enable 'redirect' specification test
* tests/spec/Makefile.am (TESTS): Add 'redirect'.
* tests/spec/oil.scm: Filter out nine tests from it.
2018-12-05 16:08:09 -05:00
Timothy Sample 4cff559d1f Fix another shebang in Oil build script
* tests/spec/oil.scm: Add 'spec/bin/printenv.py' to the list of files
that get passed to 'patch-shebang'.
2018-12-05 16:08:09 -05:00
Timothy Sample 0ae52599c4 Preserve input and error ports in substitutions
This was simply a mistake.

* geesh/shell.scm (sh:substitute-command): Leave 'current-input-port'
and 'current-error-port' alone.
* tests/shell.scm: Remove tests that check that input and error gets
ignored during substitutions.
2018-12-05 16:08:09 -05:00
Timothy Sample 9dbf64d740 Enable 'word-split' specification test
* tests/spec/Makefile.am (TESTS): Add 'word-split'.
* tests/spec/oil.scm: Filter out four tests from it that we cannot
support yet.
2018-12-05 16:08:09 -05:00
Timothy Sample f448a57a27 Add filtering for specification tests
* tests/spec/oil.scm: Add code to filter out specific test cases from
a test file.
2018-12-05 16:08:09 -05:00
Timothy Sample 4b7d2404f3 Fix handling of non-whitespace IFS separators
* geesh/word.scm (string-tokenize*): New function.
(split-fields): Use it to handle non-whitespace IFS separators.
* tests/word.scm: Add tests.
2018-12-05 16:08:09 -05:00
Timothy Sample 3e6d7830a9 Fix splitting nested words
* geesh/word.scm (split-fields): Move handling of list words into
'wedge-apart' so that they get handled in recursive calls.
* tests/word.scm: Add a test for this.
2018-12-05 16:08:01 -05:00
Timothy Sample 765e91eb88 Elide unquoted empty and unset variables
* geesh/word.scm (split-fields): Make an empty string yield zero
fields (an empty list).
* tests/word.scm: Update tests and add tests to make sure that quoted
empty strings are preserved.
2018-12-05 16:06:14 -05:00
Timothy Sample f84b6235db Add Oil shell specification tests
tests/spec/oil.scm: New file.
tests/spec/check-spec: New file.
tests/spec/Makefile.am: New file.
configure.ac: Add the new Makefile.
Makefile.am (check-spec): New rule for running Oil shell
specification tests.
(clean-local): New rule that tells Automake how to clean up the
specification tests.
.gitignore: Add tests/spec/oil and tests/spec/oil-link.
2018-12-05 16:06:14 -05:00
Timothy Sample 37f4ce6ea8 Add pipeline semantics
* geesh/shell.scm (swap-and-shift-pairs): New function.
(make-pipes): New function.
(plumb): New function.
(sh:pipeline): New public function.
* tests/shell.scm: Test it.
2018-12-03 20:09:55 -05:00
Timothy Sample 553b8f2b96 Use ports for redirects
Before, we were using raw file descriptors.  This worked okay, but
there was interference caused by port buffering.  Doing everything at
the port level avoids this problem, and has the added benefit of
allowing one to use the 'current-*-port' parameters with the shell
module (in a limited way, but there is room for improvement).

* geesh/shell.scm (*fd-count*): New variable.
(fd->current-port): New function.
(install-current-ports!): New function.
(exec-utility): Use it to set up file descriptors.
(save-and-install-redirect!): Rename this...
(save-and-set-redirect): ...to this and modify the current port
parameters instead of raw file descriptors.
(restore-saved-fdes!): Rename this...
(restore-saved-port): ...to this.
(sh:with-redirects): Adjust to use the renamed functions.
(sh:substitute-command): Parameterize the current ports directly
instead of using redirects.
* tests/shell.scm: Add tests to check if port buffers cause problems.
2018-12-03 20:07:53 -05:00
Timothy Sample 6b6ca11bce Add command substitution semantics
* geesh/shell.scm (%subshell): New function factored out from 'subshell'.
(subshell): Use it.
(substitute-command): New public function.
* tests/shell.scm: Test it.
* .dir-locals.el: Indent it nicely.
2018-12-03 20:06:47 -05:00
Timothy Sample 8739cafad9 Add subshell semantics
* geesh/shell.scm (subshell): New public function.
* tests/shell.scm: Test it.
* .dir-locals.el: Indent it nicely.
2018-11-28 23:07:03 -05:00
Timothy Sample e6f732ada9 Add redirect semantics
* geesh/shell.scm (save-and-install-redirect!): New function.
(restore-saved-fdes!): New function.
(with-redirects): New public function.
* tests/shell.scm: Test it.
* .dir-locals.el: Indent it nicely.
2018-11-28 23:07:03 -05:00
Timothy Sample 737ed6a1b7 Add function for reading an 'environ'
* geesh/environment.scm (environ->alist): New function.
* tests/environment.scm: Test it.
2018-11-28 23:07:03 -05:00
Timothy Sample 549d1e7867 Remove REPL unit tests
In order to test the REPL in isolation, we would have to mock out the
parser and interpreter.  This is possible, but too much work for the
benefit (at least for now).

* tests/repl.scm: Deleted.
* Makefile.am: Remove it.
2018-11-28 23:07:03 -05:00
Timothy Sample e1f139b841 Add support for built-ins, starting with 'echo'
* geesh/built-ins/echo.scm: New file.
* geesh/built-ins.scm: New file.
* Makefile.scm: Add them.
* geesh/shell.scm (exec-let): Include built-ins in command search.
* tests/shell.scm: Add a test for this.
2018-11-28 23:07:03 -05:00
Timothy Sample 7cc94e88e1 Add PATH searching
* geesh/shell.scm (slashless?) New function.
(split-search-path): New function.
(find-utility): New function.
(exec-let): Use them to search PATH for a utility when appropriate.
(exec): Update doc string.
* tests/shell.scm: Test it.
2018-11-28 23:07:03 -05:00
Timothy Sample b9ec924bbe Add shell module
* geesh/shell.scm: New file.
* tests/shell.scm: New file.
* Makefile.am: Add them.
* tests/config.scm.in: New file.
* configure.ac: Add it.
* .gitignore: Add its generated form.
* .dir-locals.el: Add indentation rule for 'make-script'.
2018-11-28 23:07:03 -05:00
Timothy Sample cfb2b5b99b Add function for creating an 'environ'
* geesh/environment.scm (environment->environ): New function.
* tests/environment.scm: Test it.
2018-11-28 23:07:03 -05:00
Timothy Sample 99378697e2 Add missing '(test-end)' to environment tests
* tests/environment.scm: Add '(test-end)'.
2018-11-28 23:07:03 -05:00
Timothy Sample 9d834d0767 Fix parsing of for loops
* geesh/parser.scm (make-parser): When parsing for loops, make all
word-lists actual lists, and make an empty word-list with the 'in'
keyword yield an empty list rather than a reference to '$@'.
* tests/parser.scm: Update tests.
2018-11-28 23:04:30 -05:00
Timothy Sample 48e122c42f Fix AST for redirects and assignments
This should have been in 2b05199562, but
it was overlooked.

* geesh/parser.scm (make-parser): Splice in arguments in the redirect
case (to be consistent with the non-redirect case).
* tests/parser.scm: Add a test for this.
2018-11-28 22:09:34 -05:00
Timothy Sample 73414716bb Fix lexing of empty double quotes
* geesh/lexer.scm (get-double-quotation): Handle empty quotation.
* tests/lexer.scm: Add a test for this and for empty single
quotes (which already worked correctly).
2018-11-09 16:22:11 -05:00
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 4f1e737cdd Make test examples more plausible
* tests/lexer.scm: Replace fake '<sh-cmd>' forms with '<sh-exec>'.
2018-07-18 14:23:01 -04:00
Timothy Sample 5605ea993a Fix AST for quoted words
* geesh/lexer.scm (get-double-quotation): Make sure that '<sh-quote>'
forms only have one sub-word.
(get-unquoted-here-doc): Ditto.
* tests/lexer.scm: Update tests accordingly.
2018-07-18 09:29:33 -04:00
Timothy Sample a2f5403367 Fix field splitting on outside spaces
* geesh/word.scm (split-fields): Make outside spaces in word-parts
count for field splitting.
* tests/word.scm: Test this.
2018-07-18 02:33:08 -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 8b945a77a9 Fix reading multi-line quoted here-documents
* geesh/lexer.scm (get-quoted-here-doc): Use the correct line-reading
procedure when looping.
* tests/lexer.scm: Add test.
2018-07-17 21:59:09 -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 3e0872ee3e Add a function for more accurate here-end lexing
When lexing a here-end word, expansions should be ignored.  That is,
"$x" should be treated as the string "$x" and not a reference to the
parameter named "x".

* geesh/lexer.scm (expansions?): New parameter to enable or disable
treating expansions specially.
(get-double-quotation): Use it.
(get-word): Ditto.
(get-here-end): New public function that reads a token without
treating expansions specially.
* tests/lexer.scm: Test it.
2018-07-15 20:16:27 -04:00
Timothy Sample a43d97dd09 Add here-document support to the lexer
* geesh/lexer.scm (get-quoted-here-doc): New function.
(get-unquoted-here-doc): New function.
(wrap-port-with-tab-trimming): New function.
(get-here-doc): New public function.
* tests/lexer.scm: Test it.
2018-07-15 20:16:17 -04:00
Timothy Sample be5b305de6 Fix dollar sign handling before non-name
If a dollar sign does not precede a name, it gets treated normally.

* geesh/lexer.scm (get-parameter): Return '#f' if the first character
is not a name character.
(get-parameter-expansion): Propagate the '#f' value.
(get-word): Replace the '#f' value with last character read.
(get-parameter-word): Ditto.
(get-double-quotation): Ditto.
* tests/lexer.scm: Test this.
2018-07-15 19:48:20 -04:00
Timothy Sample 01e8a7bf24 Fix line-joining when there are extra spaces
* geesh/lexer.scm (get-token): Add a case to skip an escaped newline.
* tests/lexer.scm: Test it.
2018-07-15 19:48:20 -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 a5773e90eb Add word
* geesh/word.scm: New file.
* tests/word.scm: New file.
* Makefile.am: Add them.
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 6678ae1e59 Add environment
* geesh/environment.scm: New file.
* tests/environment.scm: New file.
* Makefile.am: Add them.
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 0afb2523f7 Make reference operators more consistent
* geesh/lexer.scm (get-parameter-expression): Use '#f' to signal an
omitted optional word instead of just omitting the word in the
resulting form.
* tests/lexer.scm: Add a test for omitted optional words.
2018-07-11 21:54:43 -04:00
Timothy Sample c802fd2fca Make reference operator names more "Scheme-y"
* geesh/lexer.scm (*parameter-operators*): Update the names of the
operators.
* tests/lexer.scm: Fix tests accordingly.
2018-07-11 21:54:35 -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
Timothy Sample 95181a98b5 Add lexer
* geesh/lexer.scm: New file.
* tests/lexer.scm: New file.
* Makefile.am: Add them.
2018-01-31 15:09:51 -05:00
Timothy Sample cdded95d88 Initial commit 2018-01-31 14:52:05 -05:00