checkpoint: glob/regex fix, wip: 2nd prompt continuation, cleanups
This commit is contained in:
parent
1a42685197
commit
b35876f4d9
|
@ -0,0 +1,13 @@
|
|||
* setup test driven development: done
|
||||
* execute tests using anguish: done
|
||||
* parsing posix shell: nested "'""'": done
|
||||
* globbing: done
|
||||
* job control: done
|
||||
* readline: prompt2: done?
|
||||
* pipe: almost done: mix built-in with process
|
||||
* compound: case, while, until
|
||||
* expansion
|
||||
* substitution
|
||||
* alias
|
||||
* redirection:
|
||||
* posix compliance:
|
|
@ -1,13 +1,14 @@
|
|||
(define-module (sh anguish)
|
||||
:use-module (statprof)
|
||||
|
||||
;;:use-module (statprof)
|
||||
|
||||
:use-module (srfi srfi-1)
|
||||
:use-module (srfi srfi-26)
|
||||
|
||||
:use-module (ice-9 ftw)
|
||||
:use-module (ice-9 getopt-long)
|
||||
:use-module (ice-9 local-eval)
|
||||
:use-module (ice-9 match)
|
||||
:use-module (ice-9 pretty-print)
|
||||
:use-module (ice-9 rdelim)
|
||||
:use-module (ice-9 readline)
|
||||
:use-module (ice-9 buffered-input)
|
||||
|
@ -84,18 +85,17 @@ copyleft.
|
|||
(quit (every identity status))))
|
||||
(#t (let* ((HOME (string-append (getenv "HOME") "/.anguishistory"))
|
||||
(thunk (lambda ()
|
||||
(set-readline-prompt! (prompt) "...")
|
||||
(let loop ((line (readline (prompt))))
|
||||
(if (not (eof-object? line))
|
||||
(begin
|
||||
(let ((ast (string-to-ast line)))
|
||||
(when ast
|
||||
(if (not (string-null? line))
|
||||
(add-history line))
|
||||
(run ast))
|
||||
(loop (string-append
|
||||
(if ast "" (string-append line ";"))
|
||||
(readline (if ast (prompt) "> ")))))))))))
|
||||
(when (not (eof-object? line))
|
||||
(let ((ast (string-to-ast line)))
|
||||
(when ast
|
||||
(if (not (string-null? line))
|
||||
(add-history line))
|
||||
(run ast))
|
||||
(loop (let ((previous (if ast "" (string-append line "\n")))
|
||||
(next (readline (if ast (prompt) "> "))))
|
||||
(if (eof-object? next) next
|
||||
(string-append previous next))))))))))
|
||||
(clear-history)
|
||||
(read-history HOME)
|
||||
(with-readline-completion-function completion thunk)
|
||||
|
@ -124,17 +124,16 @@ copyleft.
|
|||
|
||||
|
||||
;; TODO: add braces
|
||||
|
||||
(define (glob pattern) ;; pattern -> list of path
|
||||
|
||||
(define (glob? pattern)
|
||||
(string-match "\\?|\\*" pattern))
|
||||
|
||||
(define (glob2regex pattern)
|
||||
(let* ((regex (regexp-substitute/global #f "\\." pattern 'pre "\\." 'post))
|
||||
(regex (regexp-substitute/global #f "\\?" pattern 'pre "." 'post))
|
||||
(regex (regexp-substitute/global #f "\\*" pattern 'pre ".*" 'post)))
|
||||
(make-regexp (string-append "^" regex "$"))))
|
||||
(let* ((pattern (regexp-substitute/global #f "\\." pattern 'pre "\\." 'post))
|
||||
(pattern (regexp-substitute/global #f "\\?" pattern 'pre "." 'post))
|
||||
(pattern (regexp-substitute/global #f "\\*" pattern 'pre ".*" 'post)))
|
||||
(make-regexp (string-append "^" pattern "$"))))
|
||||
|
||||
(define (glob-match regex path) ;; pattern path -> bool
|
||||
(regexp-match? (regexp-exec regex path)))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(define-module (sh peg)
|
||||
:use-module (ice-9 peg)
|
||||
:use-module (ice-9 peg codegen)
|
||||
:use-module (ice-9 pretty-print)
|
||||
|
||||
:export (parse))
|
||||
|
||||
(define (error? x)
|
||||
|
@ -56,7 +56,7 @@
|
|||
pattern <-- sp* word (sp* '|' sp* word)* sp* ')' sp*
|
||||
for-clause <-- 'for' (sp+ identifier ws+ ('in' expression sequential-sep)? do-group / error)
|
||||
expression <-- sp+ substitution sp* / (sp+ word)* sp*
|
||||
do-group <-- 'do' (ne-compound-list 'done' / error)
|
||||
do-group <-- 'do' ws* (ne-compound-list 'done' / error)
|
||||
if-clause <-- 'if' (ne-compound-list 'then' ne-compound-list else-part? 'fi' / error)
|
||||
else-part <-- 'elif' (ne-compound-list 'then' ne-compound-list else-part? / error) / 'else' (ne-compound-list / error)
|
||||
while-clause <-- 'while' (ne-compound-list do-group / error)
|
||||
|
|
Loading…
Reference in New Issue