Handle '$LINENO'.

* geesh/lexer.scm (get-parameter-expansion): Include the current line
number with the variable name if it is 'LINENO'.
(call-with-metered-input-port): Set the line number of the soft port.
* geesh/word.scm (parameter-ref): Unpack the included line number when
the parameter name is 'LINENO'.
This commit is contained in:
Timothy Sample 2018-12-19 01:19:54 -05:00
parent c6a3d13c69
commit 0dc3f63cad
2 changed files with 11 additions and 5 deletions

View File

@ -309,11 +309,15 @@ leading '$')."
(define (get-parameter-expansion port)
"Get a parameter expansion (either '$name' or '${...}') from
@var{port} (excluding the leading '$')."
(match (lookahead-char port)
(#\{ (get-parameter-expression port))
(_ (and=> (get-parameter port)
(lambda (name)
`(<sh-ref> ,name))))))
(let ((result (match (lookahead-char port)
(#\{ (get-parameter-expression port))
(_ (and=> (get-parameter port)
(lambda (name)
`(<sh-ref> ,name)))))))
(match result
((op "LINENO") `(,op ("LINENO" . ,(1+ (port-line port)))))
((op "LINENO" x) `(,op ("LINENO" . ,(1+ (port-line port))) ,x))
(_ result))))
(define (get-bracketed-command port)
"Get a bracketed command ('$(...)') from @var{port} (excluding the
@ -479,6 +483,7 @@ characters read."
;; close-port
#f)
"r"))
(set-port-line! wrapped-port (port-line port))
(let ((result (proc wrapped-port)))
;; The soft port seems to have an independent buffer from the
;; input port. This means that the "lookahead" character on the

View File

@ -231,6 +231,7 @@ the environment. If @var{name} is unset, return @code{#f}."
("#" (number->string (length (cdr (program-arguments)))))
("?" (number->string (get-status)))
("$" (number->string (get-root-pid)))
(("LINENO" . line) (number->string line))
(x (let ((n (string->number x)))
(if (and n (integer? n) (> n 0)
(<= n (length (cdr (program-arguments)))))