Re: pregexp vs. read
From: Jeff (massung_at_gmail.com)
Date: 10/21/04
- Next message: ws Wang: "Newbie question: how to save file in lisp(cmucl)"
- Previous message: Matthew Danish: "Re: pregexp vs. read"
- In reply to: Philip Haddad: "Re: pregexp vs. read"
- Next in thread: Rahul Jain: "Re: pregexp vs. read"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 20 Oct 2004 23:08:56 GMT
Philip Haddad wrote:
> Matthew Danish <mrd+nospam@cmu.edu> wrote in message
> news:<87y8i2wg54.fsf@mapcar.org>...
> > philip.haddad@gmail.com (Philip Haddad) writes:
> >
> > Regular expression libraries are good at matching. If that's what
> > you need, go for it. If you need a parser, READ might do; or not,
> > since it can only parse a limited subset of grammars. Otherwise
> > you should start looking into things like Zebu which offers an LALR
> > parser-generator.
>
> What I need to do is get patterns from a stream of input and base
> output on the input. This is for a IRC bot I have started to work
> on....
Like an IRC version of Eliza? ;)
Perhaps my regular expression parser (if that's what you decide to use)
might be of help to you. It doesn't have /everything/ that others do,
but it does hit 90%+ of all regular expressions, and is only a few
hundred lines of code -- all self-contained. I use it for program
parsing, so I have a built in macro FLEX that builds a function for
parsing a text string. For example:
(setq token-parser
(regex:flex
(#/\a[_\w]*/ (read-from-string $0))
(#/\d+/ (parse-integer $0))
(#/0x(\x+)/ (parse-integer $1 :radix 16))
(#/'([^']*)'/ $1)
(#/=/ :assign)
(#/\s+/ nil)))
(funcall token-parser "foo_bar=0x1234abcd 12 'Hello, world!'")
==> (FOO_BAR :ASSIGN 305441741 12 "Hello, world!")
T
Not sure if that would be beneficial to your end goal as much as coming
up with a different method of parsing, but if you think it would be,
drop me an email.
--
`(:mail-to ,(concatenate 'string (symbol-name 'massung)
(string (code-char 64))
(string-upcase "gmail.com")))
- Next message: ws Wang: "Newbie question: how to save file in lisp(cmucl)"
- Previous message: Matthew Danish: "Re: pregexp vs. read"
- In reply to: Philip Haddad: "Re: pregexp vs. read"
- Next in thread: Rahul Jain: "Re: pregexp vs. read"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|