home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
ISR
/
isr2parser.lisp
< prev
next >
Wrap
Lisp/Scheme
|
1995-04-11
|
3KB
|
92 lines
;;; -*- Mode:Common-Lisp; Package:ISR2; Base:10 -*-
;;;------------------------------------------------------------------------
;;; ISR2PARSER.LISP - Code to parse token names.
;;; Created: Friday the eighth of April, 1988; 8:39:26 am
;;; Author: Robert Heller
;;;------------------------------------------------------------------------
;;; Copyright (c) University of Massachusetts 1988
;;;------------------------------------------------------------------------
;;
(in-package "ISR2")
(export '(parse-token-name))
(defun parse-token-name (token-thing)
"This function parses TOKEN-THING and returns a flat token path list"
(cond ((null token-thing) nil) ; Null list is an empty path
((symbolp token-thing) ; Symbol - use printname
(parse-token-name (string-upcase token-thing)))
((stringp token-thing) ; Strings - look for delimeters to ckeck
; for further parsing
(setf token-thing (string-upcase token-thing))
(when (= (length token-thing) 0)
(error "Null path elements not allowed: ~S!" token-thing))
(let (($-pos (position '#\$ token-thing))
(<-pos (position '#\< token-thing))
)
(if (or $-pos <-pos)
(parse-token-name-string token-thing) ; peel off at $ and <
(list token-thing))))
((handle-p token-thing) (list token-thing))
((consp token-thing) ; a list - map down and flatten it, parsing sub-pieces
; as we go
(mapcan #'(lambda (old-thing)
(if (integerp old-thing)
(list old-thing)
(parse-token-name old-thing)
))
token-thing))
(t (error "Bad argument to ISR2:PARSE-TOKEN-NAME - ~S is not a legal token thing"
token-thing))
)
)
(defun parse-token-name-string (token-name-string)
"Helper function to peel apart a token name string."
(let (($-pos (position '#\$ token-name-string))
(<-pos (position '#\< token-name-string))
(tns-len (length token-name-string))
)
(cond ((= tns-len 0) nil)
((or (and $-pos <-pos (< $-pos <-pos))
(and $-pos (null <-pos)))
(when (= $-pos 0)
(error "Null path elements not allowed: ~S!" token-name-string))
(cons (subseq token-name-string 0 $-pos)
(parse-token-name-string (subseq token-name-string (1+ $-pos)))))
((or (and $-pos <-pos (> $-pos <-pos))
(and <-pos (null $-pos)))
(let* ((p1 (subseq token-name-string 0 <-pos))
(p2 (subseq token-name-string (1+ <-pos)))
(>-pos (position '#\> p2))
)
(unless >-pos
(error "Syntax error in token name string: ~S, missing \">\""
token-name-string))
(if (and (eql (elt p2 0) '#\?) (= >-pos 1))
(if (> (length p1) 0)
(cons p1 (cons :? (parse-token-name-string
(subseq p2 (1+ >-pos)))))
(cons :? (parse-token-name-string
(subseq p2 (1+ >-pos)))))
(multiple-value-bind (tok-indx end-of-num-pos)
(parse-integer p2 :end >-pos :junk-allowed t :radix #x0A)
(unless (and tok-indx (= end-of-num-pos >-pos)
(>= tok-indx 0))
(error
"Syntax error in token name string: ~S, badly formed token index"
token-name-string))
(if (> (length p1) 0)
(cons p1 (cons tok-indx (parse-token-name-string
(subseq p2 (1+ >-pos)))))
(cons tok-indx (parse-token-name-string
(subseq p2 (1+ >-pos)))))
)
)))
(t (list token-name-string))
)
)
)