aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2012-05-28 14:09:02 +0000
committerdos-reis <gdr@axiomatics.org>2012-05-28 14:09:02 +0000
commit62a125276f6dc3acedaf11af209b7e4c02306128 (patch)
tree81cf15675a49410d21e6277b7e5230b86232fd26 /src
parent7be5c459a3b8d02d87e3a21edabfbf7227df613c (diff)
downloadopen-axiom-62a125276f6dc3acedaf11af209b7e4c02306128.tar.gz
* interp/io.boot (findChar): Do not define here.
* interp/match.boot (charPosition): Likewise. * boot/utility.boot (charPosition): Now return argument string length if no match. (findChar): New. * boot/scanner.boot (lexerCharPosition): Adjust. (shoeAccumulateLines): Use findChar.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/boot/scanner.boot3
-rw-r--r--src/boot/strap/scanner.clisp7
-rw-r--r--src/boot/strap/utility.clisp23
-rw-r--r--src/boot/utility.boot13
-rw-r--r--src/interp/io.boot3
-rw-r--r--src/interp/match.boot9
7 files changed, 41 insertions, 27 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 43a06c68..7a530006 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
+2012-05-28 Gabriel Dos Reis <gdr@cse.tamu.edu>
+
+ * interp/io.boot (findChar): Do not define here.
+ * interp/match.boot (charPosition): Likewise.
+ * boot/utility.boot (charPosition): Now return argument string
+ length if no match.
+ (findChar): New.
+ * boot/scanner.boot (lexerCharPosition): Adjust.
+ (shoeAccumulateLines): Use findChar.
+
2012-05-26 Gabriel Dos Reis <gdr@cs.tamu.edu>
* boot/ast.boot (bfMDef): Simplify.
diff --git a/src/boot/scanner.boot b/src/boot/scanner.boot
index b9272757..8b9a5e5e 100644
--- a/src/boot/scanner.boot
+++ b/src/boot/scanner.boot
@@ -115,7 +115,6 @@ macro lexerCharacterAt(lex,k) ==
++ Return the position of next character `c', or end of line.
lexerCharPosition(lex,c) ==
charPosition(c,lexerLineString lex,lexerCurrentPosition lex)
- or lexerLineLength lex
++ Return true if the current position is at end of line.
lexerEol? lex ==
@@ -179,7 +178,7 @@ shoeAccumulateLines(lex,s,string)==
command and #command > 0 =>
stringChar(command,0) = char ";" =>
shoeAccumulateLines(lex,$r,string)
- a := charPosition(char ";",command,0) =>
+ a := findChar(char ";",command) =>
shoeAccumulateLines(lex,$r,
strconc(string,subString(command,0,a-1)))
shoeAccumulateLines(lex,$r,strconc(string,command))
diff --git a/src/boot/strap/scanner.clisp b/src/boot/strap/scanner.clisp
index e1b8418a..744d4e28 100644
--- a/src/boot/strap/scanner.clisp
+++ b/src/boot/strap/scanner.clisp
@@ -69,10 +69,7 @@
(LIST 'SCHAR (LIST '|lexerLineString| |lex|) |k|))
(DEFUN |lexerCharPosition| (|lex| |c|)
- (OR
- (|charPosition| |c| (|lexerLineString| |lex|)
- (|lexerCurrentPosition| |lex|))
- (|lexerLineLength| |lex|)))
+ (|charPosition| |c| (|lexerLineString| |lex|) (|lexerCurrentPosition| |lex|)))
(DEFUN |lexerEol?| (|lex|)
(NOT (< (|lexerCurrentPosition| |lex|) (|lexerLineLength| |lex|))))
@@ -164,7 +161,7 @@
(COND
((CHAR= (SCHAR |command| 0) (|char| '|;|))
(|shoeAccumulateLines| |lex| |$r| |string|))
- ((SETQ |a| (|charPosition| (|char| '|;|) |command| 0))
+ ((SETQ |a| (|findChar| (|char| '|;|) |command|))
(|shoeAccumulateLines| |lex| |$r|
(CONCAT |string|
(|subString| |command| 0
diff --git a/src/boot/strap/utility.clisp b/src/boot/strap/utility.clisp
index 4de1d345..daec2a91 100644
--- a/src/boot/strap/utility.clisp
+++ b/src/boot/strap/utility.clisp
@@ -22,7 +22,7 @@
|symbolAssoc| |applySubst| |applySubst!| |applySubstNQ|
|objectAssoc| |remove| |removeSymbol| |atomic?| |every?|
|any?| |take| |takeWhile| |drop| |copyTree| |finishLine|
- |stringSuffix?|)))
+ |stringSuffix?| |findChar| |charPosition|)))
(DECLAIM (FTYPE (FUNCTION (|%Thing| |%Thing| |%Thing|) |%Thing|) |substitute|))
@@ -429,14 +429,27 @@
((OR (CHARACTERP |x|) (INTEGERP |x|)) (|removeScalar| |l| |x|))
(T (|removeValue| |l| |x|))))
+(DEFUN |findChar| (|c| |s| &OPTIONAL (|k| 0))
+ (LET ((|bfVar#2| NIL) (|bfVar#1| (|maxIndex| |s|)) (|i| |k|))
+ (LOOP
+ (COND ((> |i| |bfVar#1|) (RETURN |bfVar#2|))
+ (T
+ (AND (CHAR= (SCHAR |s| |i|) |c|)
+ (PROGN
+ (SETQ |bfVar#2| |i|)
+ (COND (|bfVar#2| (RETURN |bfVar#2|)))))))
+ (SETQ |i| (+ |i| 1)))))
+
(DEFUN |charPosition| (|c| |s| |k|)
(LET* (|n|)
(PROGN
(SETQ |n| (LENGTH |s|))
- (LOOP
- (COND ((NOT (< |k| |n|)) (RETURN NIL))
- ((CHAR= (SCHAR |s| |k|) |c|) (RETURN |k|))
- (T (SETQ |k| (+ |k| 1))))))))
+ (COND ((MINUSP |k|) |n|)
+ (T
+ (LOOP
+ (COND ((NOT (< |k| |n|)) (RETURN |k|))
+ ((CHAR= (SCHAR |s| |k|) |c|) (RETURN |k|))
+ (T (SETQ |k| (+ |k| 1))))))))))
(DEFUN |firstNonblankPosition| (|s| |k|)
(LET ((|bfVar#2| NIL) (|bfVar#1| (- (LENGTH |s|) 1)) (|i| |k|))
diff --git a/src/boot/utility.boot b/src/boot/utility.boot
index 42bbbf00..6dfdb668 100644
--- a/src/boot/utility.boot
+++ b/src/boot/utility.boot
@@ -49,7 +49,7 @@ module utility (objectMember?, symbolMember?, stringMember?,
setDifference, setUnion, setIntersection,
symbolAssoc, applySubst, applySubst!, applySubstNQ, objectAssoc,
remove, removeSymbol, atomic?, every?, any?, take, takeWhile, drop,
- copyTree, finishLine, stringSuffix?) where
+ copyTree, finishLine, stringSuffix?, findChar, charPosition) where
substitute: (%Thing,%Thing,%Thing) -> %Thing
substitute!: (%Thing,%Thing,%Thing) -> %Thing
append: (%List %Thing,%List %Thing) -> %List %Thing
@@ -339,12 +339,19 @@ remove(l,x) ==
--% search
+++ Return the index of the first match of character `c' in string `s'
+++ starting from `k', if any. Otherwise return nil.
+findChar(c,s,k == 0) ==
+ or/[i for i in k..maxIndex s | stringChar(s,i) = c]
+
++ Return the index of the character `c' in the string `s', if present.
-++ Otherwise, return nil.
+++ Otherwise return the one-past-the-end index of `s' or k, whichever
+++ is greater.
charPosition(c,s,k) ==
n := # s
+ k < 0 => n
repeat
- k >= n => return nil
+ k >= n => return k
stringChar(s,k) = c => return k
k := k + 1
diff --git a/src/interp/io.boot b/src/interp/io.boot
index 2191c3d8..f7a35617 100644
--- a/src/interp/io.boot
+++ b/src/interp/io.boot
@@ -93,9 +93,6 @@ expandLeadingTabs line ==
nbLoc = indLoc => line
strconc(makeString(indLoc,char " "), subString(line,nbLoc))
-findChar(c,s,k == 0) ==
- or/[i for i in k..maxIndex s | stringChar(s,i) = c]
-
++ Find the position at which `s1' matches a substring of `s2',
++ starting from `k'. Return nil on failure.
findString(s1,s2,k == 0) ==
diff --git a/src/interp/match.boot b/src/interp/match.boot
index 7e8144f9..b8c92e10 100644
--- a/src/interp/match.boot
+++ b/src/interp/match.boot
@@ -56,15 +56,6 @@ anySubstring?(part,whole,startpos) ==
or/[((k := i) and "and"/[CHAR_-EQUAL(part.ip,whole.iw)
for ip in 0..np - 1 for iw in i..]) for i in startpos..nw - np] => k
-charPosition(c,t,startpos) ==
- n := # t
- startpos < 0 or startpos > n => n
- k:= startpos
- for i in startpos .. n-1 repeat
- c = t.i => return nil
- k := k+1
- k
-
rightCharPosition(c,t,startpos) == --startpos often equals maxIndex t (rightmost)
k := startpos
for i in startpos..0 by -1 while c ~= stringChar(t,i) repeat (k := k - 1)