aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/interp/preparse.lisp57
-rw-r--r--src/interp/spad-parser.boot39
3 files changed, 48 insertions, 54 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 02454e9d..e06fbc32 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
2012-05-11 Gabriel Dos Reis <gdr@cs.tamu.edu>
+ * interp/preparse.lisp (ADD-PARENS-AND-SEMIS-TO-LINE): Move to
+ spad-parser.boot Rename as addParensAndSemisToLine.
+ (PARSEPILES): Move spad-parser.boot. Rename as parsePiles.
+
+2012-05-11 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
* interp/preparse.lisp (preparseReadLine1): Move to spad-parser.boot.
2012-05-10 Igor Pashev <pashev.igor@gmail.com>
diff --git a/src/interp/preparse.lisp b/src/interp/preparse.lisp
index 6adf49c6..5909ff5b 100644
--- a/src/interp/preparse.lisp
+++ b/src/interp/preparse.lisp
@@ -92,7 +92,7 @@
(NCOMBLOCK
(|findCommentBlock| NIL NUMS LOCS NCOMBLOCK NIL)))
(RETURN (|pairList| (|reverse!| NUMS)
- (PARSEPILES (|reverse!| LOCS) (|reverse!| LINES))))))
+ (|parsePiles| (|reverse!| LOCS) (|reverse!| LINES))))))
(cond ((and (NULL LINES) (> (LENGTH A) 0) (EQ (CHAR A 0) #\) ))
; this is a command line, don't parse it
(|preparseEcho| LineList)
@@ -154,7 +154,7 @@
(setq |$preparseLastLine|
(|reverse!| |$EchoLineStack|)))
(RETURN (|pairList| (|reverse!| NUMS)
- (PARSEPILES (|reverse!| LOCS) (|reverse!| LINES)))))
+ (|parsePiles| (|reverse!| LOCS) (|reverse!| LINES)))))
(cond ((> PARENLEV 0) (PUSH NIL LOCS) (setq SLOC PSLOC) (GO REREAD)))
(COND (NCOMBLOCK
(|findCommentBlock| NUM NUMS LOCS NCOMBLOCK linelist)
@@ -167,7 +167,7 @@
(when (and (|ioTerminal?| in-stream) (not continue))
(setq |$preparseLastLine| nil)
(RETURN (|pairList| (|reverse!| NUMS)
- (PARSEPILES (|reverse!| LOCS) (|reverse!| LINES)))))
+ (|parsePiles| (|reverse!| LOCS) (|reverse!| LINES)))))
(GO READLOOP)))
@@ -176,54 +176,3 @@
(progn (format t "~&~% *** PREPARSE ***~%~%")
(dolist (X L) (format t "~5d. ~a~%" (car x) (cdr x)))
(format t "~%"))))
-
-(defun PARSEPILES (LOCS LINES)
- "Add parens and semis to lines to aid parsing."
- (mapl #'add-parens-and-semis-to-line
- (|append!| LINES '(" "))
- (|append!| locs '(nil)))
- LINES)
-
-(defun add-parens-and-semis-to-line (slines slocs)
-
- "The line to be worked on is (CAR SLINES).
- It's indentation is (CAR SLOCS).
- There is a notion of current indentation. Then:
-
- A. Add open paren to beginning of following line if following
- line's indentation is greater than current, and add close paren
- to end of last succeeding line with following line's indentation.
- B. Add semicolon to end of line if following line's indentation is
- the same.
- C. If the entire line consists of the single keyword then or else,
- leave it alone."
-
- (let ((start-column (car slocs)))
- (if (and start-column (> start-column 0))
- (let ((count 0)
- (i 0))
- (seq
- (mapl #'(lambda (next-lines nlocs)
- (let ((next-line (car next-lines))
- (next-column (car nlocs)))
- (incf i)
- (if next-column
- (progn
- (setq next-column (abs next-column))
- (if (< next-column start-column)
- (exit nil))
- (cond
- ((and (eq next-column start-column)
- (rplaca nlocs (- (car nlocs)))
- (not (|infixToken?| next-line)))
- (setq next-lines (|drop| (1- i) slines))
- (rplaca next-lines
- (|addClose| (car next-lines) #\;))
- (setq count (1+ count))))))))
- (cdr slines) (cdr slocs)))
- (if (> count 0)
- (progn
- (setf (char (car slines) (1- (|firstNonblankCharPosition| (car slines))))
- #\( )
- (setq slines (|drop| (1- i) slines))
- (rplaca slines (|addClose| (car slines) #\) ))))))))
diff --git a/src/interp/spad-parser.boot b/src/interp/spad-parser.boot
index 3076f91c..3ff71b04 100644
--- a/src/interp/spad-parser.boot
+++ b/src/interp/spad-parser.boot
@@ -161,6 +161,45 @@ preparseEcho lines ==
formatToStream(OUT_-STREAM,'"~&;~A~%",x)
$EchoLineStack := nil
+++ The line to be worked on is (CAR SLINES).
+++ It's indentation is (CAR SLOCS).
+++ There is a notion of current indentation. Then:
+++
+++ A. Add open paren to beginning of following line if following
+++ line's indentation is greater than current, and add close paren
+++ to end of last succeeding line with following line's indentation.
+++ B. Add semicolon to end of line if following line's indentation is
+++ the same.
+++ C. If the entire line consists of the single keyword then or else,
+++ leave it alone.
+addParensAndSemisToLine(lines,locs) ==
+ sc := first locs -- first line column number
+ sc = nil or sc <= 0 => nil
+ count := 0 -- number of semicolons added
+ i := 0 -- running local line number
+ for x in tails rest lines for y in tails rest locs repeat
+ i := i + 1
+ nc := first y
+ nc = nil => nil
+ nc := abs nc
+ nc < sc => leave nil
+ nc = sc and (y.first := -nc) and not infixToken? first x =>
+ z := drop(i - 1,lines)
+ z.first := addClose(first z,char ";")
+ count := count + 1
+ count > 0 =>
+ first(lines).(firstNonblankCharPosition first lines - 1) := char "("
+ lines := drop(i - 1,lines)
+ lines.first := addClose(first lines,char ")")
+ nil
+
+++ Add parens and semis to lines to aid parsing.
+parsePiles(locs,lines) ==
+ for x in tails append!(lines,['" "])
+ for y in tails append!(locs,[nil]) repeat
+ addParensAndSemisToLine(x,y)
+ lines
+
preparse st ==
$COMBLOCKLIST := nil
$SKIPME := false