Re: pregexp vs. read

From: Jeff (massung_at_gmail.com)
Date: 10/21/04


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")))


Relevant Pages

  • String parsing with VB 6.0 (SP4)
    ... Should I be able to use regular expression scripting for string parsing with ... Most of what I find is oriented towards its Web use for parsing ... I've ticked the Project Components MS Script Control 1.0 and got the Script ... A simple example getting a line, using Line Input, regular expression ...
    (microsoft.public.scripting.vbscript)
  • Re: Syntax highlighting servlet
    ... > highlighting engines use regular expression substitutions, ... Is the extra effort involved in parsing ... Whether it's worth it is, of course, your ...
    (comp.lang.java.help)
  • Re: RE and Jar are hard to Google for!
    ... "Regular Expression" java jar ... Happy Parsing. ... > open-mouthed kitchen vessel. ...
    (comp.lang.java.programmer)
  • Re: RegEx for parsing peoples names?
    ... > I'm trying to create and regular expression for parsing ... > peoples names. ... I simply want to make sure that a firstname and surname, ...
    (microsoft.public.dotnet.languages.csharp)
  • Regular Expressions
    ... I need some tips on going about regular expression: ... parsing through a text file and printing all of the words that - for example - ... Prev by Date: ...
    (perl.beginners)