TPG error when using 't' as the first letter of a token

Andrew James drew at gremlinhosting.com
Thu Nov 18 23:43:17 CET 2004


Paul,
Thanks for your detailed response. I've read through the PyParsing site
and I'm considering using it for further development of my project -
wish I'd found it before!

I noted your comments about my last test case; the syntax of the
language I'm implementing is closely related to XPath and the [] at the
end of the query are intended to contain metadata criteria. I have since
revised my parsing rules (see below) and they now parse both the
original test queries and arbitrarily complex boolean expressions.

I'm just about to post a new message with a description of what the
language is aimed at doing and asking for any improvements - I would
value your opinion if you have the time.

    # Tokens
    separator space '\s+';
    token Num '\d+(.\d+)?';
    token Ident '[a-zA-Z]\w*';
    token CharList '\'.*\'';
    token CatUnOp '~';
    token CatOp '[/\^]';
    token MetaOp '[=\+\-!]';
    token Date '\d\d-\d\d-\d\d\d\d';
    token FileID '(\w+\.\w+)';
    token EmptyLine '^$';
    
    # Rules
    START -> CatExpr ('\[' MetaExpr '\]')?
    | FileID
    | EmptyLine
    ;
    CatExpr -> CatUnOp CatName
    | CatName (CatOp CatExpr)*
    ;
    CatName -> Ident
    | '\(' CatExpr '\)'
    ;
    MetaExpr -> MetaCrit (',' MetaCrit)*
    ;
    MetaCrit -> Ident MetaOp Value
    ;
    Value -> CharList | Num | Date
    ;

parseTests = (
"simple",
"this/is/a/simple/test",
"a/test/with/metadata[author='drew',date=10]",
"music/mp3/~jackson/michael",
"docs/latex/~(computer^science)",
"media/video/((comedy/action)^thriller)"
)

Regards,
Andrew




More information about the Python-list mailing list