From baa2d50e5a11158ac998dfc0f3c8d5293666f77a Mon Sep 17 00:00:00 2001 From: dos-reis Date: Sun, 6 May 2012 22:02:12 +0000 Subject: * interp/lexing.boot (indentationLocation): New. * interp/macros.lisp (expand-tabs): Use it in lieu of NDENT-POS. * interp/preparse.lisp (PREPARSE1): Likewise. --- src/ChangeLog | 6 ++++++ src/interp/lexing.boot | 16 ++++++++++++++++ src/interp/macros.lisp | 21 +-------------------- src/interp/preparse.lisp | 4 ++-- 4 files changed, 25 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index fdf8f767..f900aac6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2012-05-06 Gabriel Dos Reis + + * interp/lexing.boot (indentationLocation): New. + * interp/macros.lisp (expand-tabs): Use it in lieu of NDENT-POS. + * interp/preparse.lisp (PREPARSE1): Likewise. + 2012-05-06 Gabriel Dos Reis * interp/Makefile.in (OBJS): Include io.$(FASLEXT). diff --git a/src/interp/lexing.boot b/src/interp/lexing.boot index 4b357918..36b54fd5 100644 --- a/src/interp/lexing.boot +++ b/src/interp/lexing.boot @@ -44,6 +44,22 @@ module lexing where matchString: %String -> %Maybe %Short matchAdvanceString: %String -> %Maybe %Short matchAdvanceKeyword: %Symbol -> %Thing + indentationLocation: %String -> %Maybe %Short + +--% + +++ Return the logical indentation position in the `line', after +++ expansion of leading vertical tab characters. +indentationLocation line == + loc := 0 + n := #line + for i in 0.. repeat + i >= n => return nil + spaceChar? line.i => loc := loc + 1 + tabChar? line.i => loc := 8 * (loc quo 8 + 1) + return loc + +--% --% --% Line abstract datatype diff --git a/src/interp/macros.lisp b/src/interp/macros.lisp index 227533d5..c11951cb 100644 --- a/src/interp/macros.lisp +++ b/src/interp/macros.lisp @@ -475,29 +475,10 @@ terminals and empty or at-end files. In Common Lisp, we must assume record size (terpri stream) (finish-output stream))) -;; moved here from preparse.lisp - -(defun NEXT-TAB-LOC (i) (* (1+ (truncate i 8)) 8)) - -(defun INDENT-POS (STR) - (do ((i 0 (1+ i)) - (pos 0)) - ((>= i (length str)) nil) - (case (char str i) - (#\space (incf pos)) - (#\tab (setq pos (next-tab-loc pos))) - (otherwise (return pos))))) - -;;(defun expand-tabs (str) -;; (let ((bpos (nonblankloc str)) -;; (tpos (indent-pos str))) -;; (if (eql bpos tpos) str -;; (concatenate 'string (make-string tpos :initial-element #\space) -;; (subseq str bpos))))) (defun expand-tabs (str) (if (and (stringp str) (> (length str) 0)) (let ((bpos (nonblankloc str)) - (tpos (indent-pos str))) + (tpos (|indentationLocation| str))) (setq str (if (eql bpos tpos) str diff --git a/src/interp/preparse.lisp b/src/interp/preparse.lisp index 0fd7bc3a..120656b1 100644 --- a/src/interp/preparse.lisp +++ b/src/interp/preparse.lisp @@ -133,7 +133,7 @@ (INSTRING) ((= N COMSYM) (setq A (subseq A 0 N)) (GO NOCOMS)) ; discard trailing comment ((= N NCOMSYM) - (setq SLOC (INDENT-POS A)) + (setq SLOC (|indentationLocation| A)) (COND ((= SLOC N) (COND ((AND NCOMBLOCK (NOT (= N (CAR NCOMBLOCK)))) @@ -150,7 +150,7 @@ ((= N CPARSYM) (setq PCOUNT (1- PCOUNT)))) (setq I (1+ N)) (GO STRLOOP) - NOCOMS (setq SLOC (INDENT-POS A)) + NOCOMS (setq SLOC (|indentationLocation| A)) (setq A (DROPTRAILINGBLANKS A)) (cond ((NULL SLOC) (setq SLOC PSLOC) (GO READLOOP))) (cond ((EQ (ELT A (MAXINDEX A)) #\_) -- cgit v1.2.3