From: ramza2
Subject: Simple Parser Lisp
Date: 
Message-ID: <1105052657.781934.87770@z14g2000cwz.googlegroups.com>
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]
...
...

If I want to read those 3 lines, what is a lisp way of doing that.


Using the basic file reader form:

(with-open-file (strm fval
:direction :input)
(do ((line (read-line strm nil)
(read-line strm nil)))
((null line))
			    (null line))
			  )))

From: ramza2
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <1105065839.447900.254380@f14g2000cwb.googlegroups.com>
This is what I came up with, it works, but this will probably make you
gurus irk a little.

;;;
;;; This function recursively looks for [start] [end] tags in a
document
;;; and prints all the stuff in the middle
;;;
(defun find-doc-tag (strm the-line tag-data srctype)
;;;
;;; Recursive call, if the line is null return the tag-data structure
;;; This is longer than it should be, but I needed to get this over
with
;;;
(if (null the-line)
tag-data
(if
;;;; ---------------------------------------------- [ True Value ]
(> (length
(string-trim '(#\Space #\Tab) the-line)) 4)
(let ((str
(subseq
(string-trim '(#\Space #\Tab) the-line) 0 5)))
(cond ((string-equal str (if (string= str "lisp") ····@a" ····@a"))
(print "[Starting tag processing]")
(setf new-tag (make-save-tags
:atag-list nil
:xtag-list nil
:mode "ATAG"
))
;;; clear the data in the a-tag
(setf (slot-value new-tag 'xtag-list) '())
;;; recurse back with the next line
(find-doc-tag
strm (read-line strm nil) new-tag srctype))
((string-equal str (if (string= str "lisp") ····@b" ····@b"))
(find-doc-tag
strm (read-line strm nil) tag-data srctype)
)
((string-equal str (if (string= str "lisp") ····@x" ····@x"))
;;; clear the data in the x-tag
(if tag-data
(setf (slot-value tag-data 'xtag-list) nil))
(if tag-data
(setf (slot-value tag-data 'mode) "XTAG"))
(find-doc-tag
strm (read-line strm nil) tag-data srctype)
)
((string-equal str (if (string= str "lisp") ····@y" ····@y"))
(print "Processing tag")
;;; process all the tags and exit out
(if tag-data
(with-slots (mode atag-list xtag-list) tag-data
(print tag-data))
))
(t
(if tag-data
(with-slots (mode atag-list xtag-list)
tag-data
(cond ((string-equal mode "ATAG")
(setf atag-list (format nil "~A~A~%" (if atag-list atag-list "")
the-line)))
((string-equal mode "XTAG")
(setf xtag-list (format nil "~A~A~%" (if xtag-list xtag-list "")
(subseq the-line 3 (length the-line)))))
)
(find-doc-tag
strm (read-line strm nil) tag-data srctype)
)))
))
;;;; ---------------------------------------------- [ Else Value
]
(if tag-data (find-doc-tag
strm (read-line strm nil) tag-data srcype))
    )))
From: Edi Weitz
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <u8y75frvx.fsf@agharta.de>
On 6 Jan 2005 18:43:59 -0800, "ramza2" <············@gmail.com> wrote:

> This is what I came up with, it works, but this will probably make
> you gurus irk a little.

If there's one thing that annoys me then it's the fact that Google
Groups prevents you from properly indenting the code.  (I'll give you
the benefit of the doubt that /you/ actually indented correctly.)

This is so ugly I won't even look at it.  If you want to post Lisp
code longer than two or three lines to c.l.l you should use a decent
Usenet reader like Gnus.

Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: ramza2
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <1105111389.410078.258620@f14g2000cwb.googlegroups.com>
Sorry about that, food for thought
From: ramza2
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <1105111444.270876.270340@z14g2000cwz.googlegroups.com>
Sorry about that, food for thought
From: Jeff M.
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <1105110295.394362.174820@f14g2000cwb.googlegroups.com>
I've sent numerous emails to Google about this. They say that they are
working on something to fix this. It should be incredibly easy to
fix... However, until that day comes, for Win32 users, I can't
recommend XanaNews enough:
http://www.wilsonc.demon.co.uk/d9xananews.htm.

Jeff M.
From: Jens Axel Søgaard
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <41deb266$0$217$edfadb0f@dread12.news.tele.dk>
Edi Weitz wrote:

> If there's one thing that annoys me then it's the fact that Google
> Groups prevents you from properly indenting the code.  (I'll give you
> the benefit of the doubt that /you/ actually indented correctly.)

At the bottom of each help page in Google Groups is a link "Contact Us".
I just wrote in to say I want an option to keep indentation. The more
that does the same, the more likely it is that they add the feature.

-- 
Jens Axel Søgaard
From: Peter Seibel
Subject: New Google Groups oddities [was Re: Simple Parser Lisp]
Date: 
Message-ID: <m3u0ptp0a5.fsf_-_@javamonkey.com>
Jens Axel S�gaard <······@soegaard.net> writes:

> Edi Weitz wrote:
>
>> If there's one thing that annoys me then it's the fact that Google
>> Groups prevents you from properly indenting the code.  (I'll give you
>> the benefit of the doubt that /you/ actually indented correctly.)
>
> At the bottom of each help page in Google Groups is a link "Contact Us".
> I just wrote in to say I want an option to keep indentation. The more
> that does the same, the more likely it is that they add the feature.

Another annoying thing I noticed about the new Google Groups is that
they intentionally mangle email addresses (and anything that looks
like an email address). Presumably this is to prevent spam. But it
does mean that information is lost. I noticed this when looking back
at some threads about FORMAT directives. Directives with at-signs in
them got mangled and the posts didn't make any sense. It also means
that you can't refer to other posts by Message ID because they get
mangled too. To say nothing of removing email addresses that the
authors intentionally included in their posts, such as the address in
my .sig which I include because I *want* people to be able to contact
me.

Moreover, it seems like a bad precedent to me for Google to be mucking
with the content they archive. In fact you could probably make an
argument that they have no right to do this--I'm fine with the
argument that by posting something to Usenet I'm implicitly giving the
right for it to be archived since someone could run a news server that
never deleted anything. But to muck with what I write seems like it's
encroaching on my rights as copyright holder of my words.

Anyway, I wrote to the support email about thit and got a
non-responsive response. Feel free to send them your own mail if you
care about this.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Cameron MacKinnon
Subject: Re: New Google Groups oddities [was Re: Simple Parser Lisp]
Date: 
Message-ID: <4-6dnX3nmriLfkPcRVn-sA@golden.net>
Peter Seibel wrote:
> Another annoying thing I noticed about the new Google Groups is that
> they intentionally mangle email addresses (and anything that looks
> like an email address).
...
> Moreover, it seems like a bad precedent to me for Google to be mucking
> with the content they archive. In fact you could probably make an
> argument that they have no right to do this--I'm fine with the
> argument that by posting something to Usenet I'm implicitly giving the
> right for it to be archived since someone could run a news server that
> never deleted anything. But to muck with what I write seems like it's
> encroaching on my rights as copyright holder of my words.

I agree with you. What's more, I believe copyright law would agree with 
you, were a competent court in an English speaking country consulted.
From: =?iso-8859-1?B?VG9taSBI5HPk?=
Subject: Re: New Google Groups oddities [was Re: Simple Parser Lisp]
Date: 
Message-ID: <1105367223.871169.226220@c13g2000cwb.googlegroups.com>
Peter Seibel wrote:
>
> Another annoying thing I noticed about the new Google Groups is that
> they intentionally mangle email addresses (and anything that looks
> like an email address). Presumably this is to prevent spam. But it
> does mean that information is lost. I noticed this when looking back
> at some threads about FORMAT directives. Directives with at-signs in
> them got mangled and the posts didn't make any sense. It also means
> that you can't refer to other posts by Message ID because they get
> mangled too.

Munging text around @ character discussed here also:

http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/ed84773373b9a5ab?tvc=2
http://tinyurl.com/6m4wh
http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/df06b12dec243ece/83e60a59b4749a1a?_done=%2Fgroup%2Fgoogle-labs-groups2%3F&_doneTitle=Back+to+topics&_doneTitle=Back&&d#83e60a59b4749a1a
http://tinyurl.com/63mtd
http://groups-beta.google.com/group/google-labs-groups2/msg/b54c12517c75eb24
http://tinyurl.com/3khmj

> Anyway, I wrote to the support email about thit and got a
> non-responsive response.

And the email address for Google Groups Beta is:

············@google.com  (labs-groups2 @ google.com)

You can also give feedback in the Google Groups Beta discussion group /
mailing list:

http://groups-beta.google.com/group/google-labs-groups2

More info in the FAQ:
http://www.geocities.com/googlepubsupgenfaq/#groupsproblems
From: Jens Axel Søgaard
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <41e7f05d$0$305$edfadb0f@dread12.news.tele.dk>
Jens Axel Søgaard wrote:

> Edi Weitz wrote:
> 
>> If there's one thing that annoys me then it's the fact that Google
>> Groups prevents you from properly indenting the code.  (I'll give you
>> the benefit of the doubt that /you/ actually indented correctly.)

I fell over this message by "Fuzzyman":

   Google strips leading whitespace. Putting *anything* before indentation
   stops the formatting getting messed up. It doesn't stop long lines
   being wrapped of course.

-- 
Jens Axel Søgaard
From: Wade Humeniuk
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <QTjDd.2010$06.1023@clgrps12>
ramza2 wrote:
> 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")

CL-USER 2 >

Wade
From: ramza2
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <1105056331.255343.57470@z14g2000cwz.googlegroups.com>
I think that is what I wanted, I need to learn how to write compilers
and this would be simple stuff, I have always want to write a simple
config file reader, never got a chance to write it.  I could even gone
one step further and embedded some basic code in there or something
REM --
REM --
blah
blah
IF
From: ramza2
Subject: Re: Simple Parser Lisp
Date: 
Message-ID: <1105056333.261622.166720@f14g2000cwb.googlegroups.com>
I think that is what I wanted, I need to learn how to write compilers
and this would be simple stuff, I have always want to write a simple
config file reader, never got a chance to write it.  I could even gone
one step further and embedded some basic code in there or something
REM --
REM --
blah
blah
IF