diff options
author | dos-reis <gdr@axiomatics.org> | 2012-06-07 04:02:54 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2012-06-07 04:02:54 +0000 |
commit | d03a3c6cb297be5f5b7726c2f346075d41faad1d (patch) | |
tree | ced95206d3aa122ce08b03c870f584c8be66be69 | |
parent | a4b48cade8c5a9ae034cfd1cfcd21739bcab7ce5 (diff) | |
download | open-axiom-d03a3c6cb297be5f5b7726c2f346075d41faad1d.tar.gz |
* interp/lexing.boot: Move %Line to io.boot.
* interp/debug.lisp (SPAD_LONG_ERROR): Take a reader parameter. Tidy.
-rw-r--r-- | src/ChangeLog | 7 | ||||
-rw-r--r-- | src/interp/debug.lisp | 27 | ||||
-rw-r--r-- | src/interp/io.boot | 77 | ||||
-rw-r--r-- | src/interp/lexing.boot | 54 | ||||
-rw-r--r-- | src/interp/spad-parser.boot | 2 | ||||
-rw-r--r-- | src/interp/spad.lisp | 2 |
6 files changed, 101 insertions, 68 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c955eb68..8a32132b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,9 @@ -2012-06-06 Gabriel Dos Reis <gdr@cse.tamu.edu> +2012-06-06 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * interp/lexing.boot: Move %Line to io.boot. + * interp/debug.lisp (SPAD_LONG_ERROR): Take a reader parameter. Tidy. + +2012-06-06 Gabriel Dos Reis <gdr@cs.tamu.edu> * interp/io.boot (readePendingLines): Rename from readerLines. Adjust callers. diff --git a/src/interp/debug.lisp b/src/interp/debug.lisp index e0231e65..2b3205ab 100644 --- a/src/interp/debug.lisp +++ b/src/interp/debug.lisp @@ -1130,19 +1130,36 @@ EXAMINE (SETQ RECNO (NOTE |$InputStream|)) "Print syntax error indication, underline character, scrub line." (BUMPERRORCOUNT '|syntax|) (COND ((AND (EQ DEBUGMODE 'YES) (NOT(CONSOLEINPUTP IN-STREAM))) - (SPAD_LONG_ERROR)) - ((SPAD_SHORT_ERROR))) + (SPAD_LONG_ERROR rd)) + ((SPAD_SHORT_ERROR rd))) (|ioClear!| rd) (throw |$SpadReaderTag| nil)) -(defun SPAD_LONG_ERROR () +(defun SPAD_LONG_ERROR (rd) (SPAD_ERROR_LOC SPADERRORSTREAM) - (iostat) + (|readerPrintCurrentLine| rd) + (and |$lineStack| (format t "Currently preparsed lines are:~%~%")) + (mapcar #'(lambda (line) + (format t "~&~5D> ~A~%" (car line) (cdr Line))) + |$lineStack|) + (if (= |$validTokens| 0) + (format t "~%There are no valid tokens.~%") + (format t "~%The number of valid tokens is ~S.~%" |$validTokens|)) + (if (> |$validTokens| 0) + (progn (format t "The current token is~%") + (describe |$currentToken|))) + (if (> |$validTokens| 1) + (progn (format t "The next token is~%") + (describe |$nextToken|))) + (if (|tokenType| |$priorToken|) + (progn (format t "The prior token was~%") + (describe |$priorToken|))) (unless (EQUAL OUT-STREAM SPADERRORSTREAM) (SPAD_ERROR_LOC OUT-STREAM) (TERPRI OUT-STREAM))) -(defun SPAD_SHORT_ERROR () (current-line-show)) +(defun SPAD_SHORT_ERROR (rd) + (|readerPrintCurrentLine| rd)) (defun SPAD_ERROR_LOC (STR) (format str "******** Spad Syntax Error detected ********")) diff --git a/src/interp/io.boot b/src/interp/io.boot index 13c26679..006781ac 100644 --- a/src/interp/io.boot +++ b/src/interp/io.boot @@ -101,17 +101,82 @@ findString(s1,s2,k == 0) == and/[stringChar(s1,j) = stringChar(s2,i+j) for j in 0..(n1-1)]] --% +--% Line abstract datatype +--% +structure %Line == + Record(buf: %String, cchar: %Char, cidx: %Short, + lidx: %Short, no: %Short) with + lineBuffer == (.buf) -- input string buffer + lineCurrentChar == (.cchar) -- current character + lineCurrentIndex == (.cidx) -- current index + lineLastIndex == (.lidx) -- last valid index + lineNumber == (.no) -- line number + +makeLine(buf == makeString 0, ch == charByName "Return", + curIdx == 1, lstIdx == 0, no == 0) == + mk%Line(buf,ch,curIdx,lstIdx,no) + +lineClear! l == + lineBuffer(l) := makeString 0 + lineCurrentChar(l) := charByName "Return" + lineCurrentIndex(l) := 1 + lineLastIndex(l) := 0 + lineNumber(l) := 0 + +++ Sets string to be the next line stored in line +lineNewLine!(s,l,no == nil) == + sz := #s + lineLastIndex(l) := sz - 1 + lineCurrentIndex(l) := 0 + lineCurrentChar(l) := sz > 0 and s.0 or charByName '"Return" + lineBuffer(l) := s + lineNumber(l) := no or (lineNumber l + 1) + +++ Tests if line is empty or positioned past the last character +lineAtEnd? l == + lineCurrentIndex l >= lineLastIndex l + +++ Tests if line is empty or positioned past the last character +linePastEnd? l == + lineCurrentIndex l > lineLastIndex l + +++ Buffer from current index to last index +lineCurrentSegment l == + lineAtEnd? l => makeString 0 + subSequence(lineBuffer l,lineCurrentIndex l,lineLastIndex l) + +lineNextChar l == + lineBuffer(l).(1 + lineCurrentIndex l) + +lineAdvanceChar! l == + n := lineCurrentIndex l + 1 + lineCurrentIndex(l) := n + lineCurrentChar(l) := lineBuffer(l).n + +--% --% Reader --% structure %Reader == - Record(ins: %InputStream, lines: %List %String,sline: %Line) with - readerInput == (.ins) - readerPendingLines == (.lines) - readerSourceLine == (.sline) -- current input line + Record(ins: %InputStream,est: %OutputStream, + lines: %List %String,sline: %Line) with + readerInput == (.ins) + readerError == (.ost) -- error output stream + readerPendingLines == (.lines) + readerSourceLine == (.sline) -- current input line -makeReader ist == - mk%Reader(ist,nil,makeLine()) +makeReader(ist,ost == 'T) == + mk%Reader(ist,ost,nil,makeLine()) ++ Add line `l' to the stack of pending lines. readerDeferLine(rd,l) == readerPendingLines(rd) := [l,:readerPendingLines rd] + +++ Print current line into to the reader's error stream. +readerPrintCurrentLine rd == + l := readerSourceLine rd + if linePastEnd? l then + formatToStream(readerError rd,'"~&The current line is empty.~%") + else + formatToStream(readerError rd,'"~&The current line is:~%~%") + formatToStream(readerError rd,'"~&~5D> ~A~%",lineNumber l,lineBuffer l) + formatToStream(readerError rd,'"~v@T^~%",lineCurrentIndex l + 7) diff --git a/src/interp/lexing.boot b/src/interp/lexing.boot index a5d71f15..d5917620 100644 --- a/src/interp/lexing.boot +++ b/src/interp/lexing.boot @@ -42,60 +42,6 @@ namespace BOOT module lexing ---% ---% Line abstract datatype ---% -structure %Line == - Record(buf: %String, cchar: %Char, cidx: %Short, - lidx: %Short, no: %Short) with - lineBuffer == (.buf) -- input string buffer - lineCurrentChar == (.cchar) -- current character - lineCurrentIndex == (.cidx) -- current index - lineLastIndex == (.lidx) -- last valid index - lineNumber == (.no) -- line number - - -makeLine(buf == makeString 0, ch == charByName "Return", - curIdx == 1, lstIdx == 0, no == 0) == - mk%Line(buf,ch,curIdx,lstIdx,no) - -lineClear! l == - lineBuffer(l) := makeString 0 - lineCurrentChar(l) := charByName "Return" - lineCurrentIndex(l) := 1 - lineLastIndex(l) := 0 - lineNumber(l) := 0 - -++ Sets string to be the next line stored in line -lineNewLine!(s,l,no == nil) == - sz := #s - lineLastIndex(l) := sz - 1 - lineCurrentIndex(l) := 0 - lineCurrentChar(l) := sz > 0 and s.0 or charByName '"Return" - lineBuffer(l) := s - lineNumber(l) := no or (lineNumber l + 1) - -++ Tests if line is empty or positioned past the last character -lineAtEnd? l == - lineCurrentIndex l >= lineLastIndex l - -++ Tests if line is empty or positioned past the last character -linePastEnd? l == - lineCurrentIndex l > lineLastIndex l - -++ Buffer from current index to last index -lineCurrentSegment l == - lineAtEnd? l => makeString 0 - subSequence(lineBuffer l,lineCurrentIndex l,lineLastIndex l) - -lineNextChar l == - lineBuffer(l).(1 + lineCurrentIndex l) - -lineAdvanceChar! l == - n := lineCurrentIndex l + 1 - lineCurrentIndex(l) := n - lineCurrentChar(l) := lineBuffer(l).n - ++ List of lines returned from preparse $lineStack := nil diff --git a/src/interp/spad-parser.boot b/src/interp/spad-parser.boot index 88d37080..42cee897 100644 --- a/src/interp/spad-parser.boot +++ b/src/interp/spad-parser.boot @@ -975,7 +975,7 @@ parseSpadFile sourceFile == -- we need to restore the global input stream state after we -- finished messing with it. IN_-STREAM: local := MAKE_-INSTREAM sourceFile - rd := makeReader IN_-STREAM + rd := makeReader(IN_-STREAM,$OutputStream) INIT_-BOOT_/SPAD_-READER rd -- If soureFile cannot be processed for whatever reasons diff --git a/src/interp/spad.lisp b/src/interp/spad.lisp index 13e21e27..804a6f3f 100644 --- a/src/interp/spad.lisp +++ b/src/interp/spad.lisp @@ -86,7 +86,7 @@ (unwind-protect (progn (setq in-stream (open ifile :direction :input)) - (setq rd (|makeReader| in-stream)) + (setq rd (|makeReader| in-stream |$OutputStream|)) (init-boot/spad-reader rd) (initialize-preparse rd) (setq out-stream |$OutputStream|) |