Re: Simple Parser Lisp

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Simple Parser Lisp
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 02. Sep 2024, 12:18:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vb46ue$2qq0b$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
If I want to parse a file:
>
stuff
stuff
stuff
stuff
stuff
...
...
//[start]
1. Read This text here
2. Read This text here
3. Read This text here
//[end]
...
...
>
 
One Way,
 
(defun read-//[start]-to-//[end] (file)
   (with-open-file (*standard-input* file :direction :input)
     (loop for line = (read-line)
       while (not (string= "//[start]" line :end2 (min (length line) 9))))
     (loop for line = (read-line)
       while (not (string= "//[end]" line :end2 (min 7 (length line)))) collect
line)))
 
CL-USER 1 > (read-//[start]-to-//[end] "test.txt")
("1. Read This text here" "2. Read This text here" "3. Read This text here")

Gauche Scheme

(use srfi-42)  ;; list-ec

(define (read-start-to-end file)
  (with-input-from-file file (lambda()
    (until (equal? "//[start]" (read-line)))
    (list-ec (:while (:generator line read-line)
               (not (equal? line "//[end]")))
      line))))

Date Sujet#  Auteur
2 Sep 24 o Re: Simple Parser Lisp1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal