Commit Graph

651 Commits

Author SHA1 Message Date
Jan Nieuwenhuizen 8aad645152 ls: Support -l.
* gash/bournish-commands.scm (ls-command-implementation): Support -l.
2018-10-29 14:51:00 +01:00
Jan Nieuwenhuizen 4e671558e5 tar: Nicer verbose listing of files.
* gash/guix-build-utils.scm (display-file): New function.
* gash/ustar.scm (display-header): Use it.
(ustar-header->stat): New function.
2018-10-29 14:51:00 +01:00
Jan Nieuwenhuizen 28d62b6169 tar: Support --list and --verbose.
* gash/ustar.scm (extract-ustar-file): Add keyword argument: extract?
(extract-ustar-archive): Add keyword arguments: extract?, verbose?:
(display-rwx, display-header, list-ustar-archive): New function
* gash/bournish-commands.scm (tar-command): Support --list, --verbose.
2018-10-29 14:51:00 +01:00
Jan Nieuwenhuizen 463b71acc9 tar: Support creation of deterministic archives.
* gash/ustar.scm (write-ustar-header, write-ustar-file): Accept
keyword arguments: group mtime numeric-owner? owner.
(create-ustar-archive): Likewise.  Rename from write-ustar-archive.
* gash/bournish-commands.scm (tar-command): Support --group, --mtime,
--numeric-owner, --owner and --sort.
2018-10-29 14:51:00 +01:00
Jan Nieuwenhuizen 92d2896134 tar: Support extraction.
* gash/ustar.scm (extract-ustar-file):
* gash/ustar.scm (<ustar-header>): New record type.
(bv->ustar-string, bv->ustar-number, bv->ustar-0string,
sub-bytevector, read-ustar-header, extract-ustar-file): New function.
Implement extraction.
2018-10-29 14:51:00 +01:00
Jan Nieuwenhuizen 03fc5c928a Add mkdir-p.
* gash/guix-build-utils.scm (mkdir-p): New function, import from Guix.
2018-10-27 11:31:22 +02:00
Jan Nieuwenhuizen 3c57272971 Add delete-file-recursively.
* gash/guix-build-utils.scm (delete-file-recursively): New function,
import from Guix.
2018-10-27 11:31:22 +02:00
Jan Nieuwenhuizen 904eecbb2c Expose all bournish commands as external command.
* bin/builtin.in: New file.
* bin/tar.in: Remove.
* configure: Generate bin/<builtin> for all bournish-commands.
* build-aux/build-guile.sh: Compile them.
* .gitignore: Ignore them.
2018-10-27 11:31:22 +02:00
Jan Nieuwenhuizen 70d28ea480 Make tar a bournish-command.
* bin/gash.in: Make Scheme script.
* bin/tar.in: Likewise.
* gash/bournish-commands (tar-command): New command, move from
tar.scm.
(%bournish-commands): Add it.
* gash/tar.scm: Remove.
2018-10-27 11:31:22 +02:00
Jan Nieuwenhuizen b8b170530c bournish: Add tar, from Guile100 challenge by Mark Weaver.
See https://github.com/spk121/guile100

* bin/tar.in: New file.
* configure: Produce bin/tar.
* .gitignore: Ignore it.
* makefile (bin/tar): New target.
* gash/tar.scm: New file.
* gash/ustar.scm: New file.
* build-aux/build-guile.sh: Compile new files.
2018-10-27 11:30:45 +02:00
Jan Nieuwenhuizen 019464acf6 fix: set -e. 2018-10-21 16:13:29 +02:00
Jan Nieuwenhuizen 13cb50af60 gash: resurrect. 2018-10-21 15:24:24 +02:00
Jan Nieuwenhuizen 0f5b538c3a geesh: initial integration.
GUILE_LOAD_PATH=$HOME/src/geesh:$GUILE_LOAD_PATH
    GUILE_LOAD_COMPILED_PATH=$HOME/src/geesh:$GUILE_LOAD_COMPILED_PATH

    bin/gash --parse -c 'echo boo | sed s,o,O, | grep .'
    bin/gash --geesh --parse -c 'echo boo | sed s,o,O, | grep .'
2018-10-21 12:45:51 +02: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 f149d42b82 Add '<sh-not>' to syntax document
* doc/syntax.txt: Add '<sh-not>'.
2018-07-19 01:04:28 -04:00
Timothy Sample 12b0354233 Rename '<sh-bang>' to '<sh-not>'
* geesh/parser.scm (make-parser): Rename '<sh-bang>' to '<sh-not>'.
2018-07-19 01:02:08 -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 48ee11a6fb Add syntax specification document
* doc/syntax.txt: New file.
2018-07-16 13:59:40 -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 3ec520596c Fix 'read-sh' to default to current input port
* geesh/parser.scm (read-sh): Make the 'port' argument optional and
default to using 'current-input-port'.
2018-07-16 10:03:58 -04:00
Jan Nieuwenhuizen 9462aaa163 checkpoint 2018-07-16 07:50:28 +02: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
Jan Nieuwenhuizen 292fbc5ecb test/if.sh, test/if2.sh -- weird 2018-07-15 23:27:58 +02:00
Jan Nieuwenhuizen 6468b04791 refactor WORD...bummer: word-for-test-assign-sh word-for-test-if-sh 2018-07-15 23:01:52 +02:00
Jan Nieuwenhuizen 24c35cc5d9 checkpoint 2018-07-15 21:44:15 +02:00
Jan Nieuwenhuizen 1f5c82ecae word! test/if.sh, test/assign.sh 2018-07-15 21:35:42 +02:00
Jan Nieuwenhuizen cbd13fdc88 checkpoint 2018-07-15 20:49:52 +02:00
Jan Nieuwenhuizen e7bfd347fa checkpoint 2018-07-15 20:47:09 +02:00
Jan Nieuwenhuizen 83f20d1ff8 flatten-fu 2018-07-15 20:06:19 +02:00
Jan Nieuwenhuizen e9a57a899c more for-progress 2018-07-15 18:39:17 +02:00
Jan Nieuwenhuizen bfc39b1a18 test: implement -n, -z, !=. 2018-07-15 18:19:56 +02:00
Jan Nieuwenhuizen 8f8ba68c54 resurrect set -x 2018-07-15 18:18:34 +02:00