New Arg Parser

This should become a new argument parser for parsers, macros and other plugins requiring external parameters. Something like wikiutil.parseAttributes with positional arguments, type conversion, defaults, etc.

When this is finished, it should be recommended to plugin implementors. That should save us stupid parsing bugs like the ones in the Include macro.

Specification

Implementation

A basic working version using tokenize is ready. I will now write the tests to check all options. -- OliverGraf 2004-10-24 21:37:15

FullSearch in my testwiki now uses the new parser, feel free to test: http://fp2.sky.rhein-zeitung.de/moin.cgi/SearchTest -- OliverGraf 2004-10-25 07:37:57

Discussion

I think this could be easily build using tokenize.

Example:

   1 import StringIO, tokenize
   2 def tok(s):
   3   s=StringIO.StringIO(s)
   4   for t in tokenize.generate_tokens(s.readline): 
   5     print tokenize.tok_name[t[0]]+'\t'+t[1]

Output:

>>> tok('FrontPage, -1, "test", from="^----$", 333')
NAME    FrontPage
OP      ,
OP      -
NUMBER  1
OP      ,
STRING  "test"
OP      ,
NAME    from
OP      =
STRING  "^----$"
OP      ,
NUMBER  333
ENDMARKER
>>> tok('start=1 step=22 numbering=on')
NAME    start
OP      =
NUMBER  1
NAME    step
OP      =
NUMBER  22
NAME    numbering
OP      =
NAME    on
ENDMARKER


I already started an argument parser used for the search macros. It is located at MoinMoin/util/parameterparser.py -- FlorianFesti 2004-10-22 06:44:55

More ideas:

I don't think we need python like arguments. We need much simpler and verbose way, just like html attributes.

[[Macro(arg="value" another="value")]]

Looks like easy to use and easy to parse.

How about this?

MoinMoin: OliverGraf/ArgumentParser (last edited 2007-10-29 19:13:47 by localhost)