User:OrenBochman/ParserNG/Preprocessor

Quick Preprocessor
Here is wikitext preprocessor written in antlr. It is aimed at parsing for search rather than parsing for rendering It supports recursive template and math expressions in template, some parser function and some magic words

based on
 * http://en.wikipedia.org/wiki/Help:Calculation
 * http://en.wikipedia.org/wiki/Help:Calculation

test input
/* basic */ aa cc

/* parametrised */

/* nested */

/* core parser functions */ HEAVENS TO BETSY! heavens to betsy!

/* ext parser functions */

__NEWSECTIONLINK__ __NONEWSECTIONLINK__ __NOGALLERY__ __HIDDENCAT__ __INDEX__ __NOINDEX__

untest input
 //////////////////////////////////////////////////untested ///////////////////////////////////////////////////////////////

/* magic words - behavior switches*/

__NEWSECTIONLINK__ __NONEWSECTIONLINK__ __NOGALLERY__ __HIDDENCAT__ __INDEX__ __NOINDEX__

/* magic words - page variables */

/*Variables: Date and time*/ 2024 August August August 27 Tuesday     {LOCALYEAR}} /*Variables: Stats */ /*Variables: Stats no commas */

/* Parser Functions: Metadata */

/* Parser Functions: Formatting*/ string string STRING String 3,333 00xyz xyz00 1 is 2 iss

=untested on=

Behavior switches
done now

Variables
For documentation, refer to the Variables section of the MediaWiki page.
 * (page title including namespace)
 * (page title excluding namespace)
 * (page title excluding current subpage and namespace - effectively the parent page without the namespace.)
 * (subpage part of title)
 * (associated non-talk page)
 * (associated talk page)
 * (namespace of current page)
 * (associated non-talk namespace)
 * (associated talk namespace)
 * etc. (equivalents encoded for use in MediaWiki URLs)

The above can all take a parameter, to operate on a page other than the current page.


 * (current MediaWiki version)
 * (latest revision to current page)
 * (date, time, editor at last edit)
 * (current MediaWiki version)
 * (latest revision to current page)
 * (date, time, editor at last edit)
 * (date, time, editor at last edit)


 * (current date/time variables)
 * etc. (as above, based on site's local time)


 * (statistics on English Wikipedia; add  to return numbers without commas)

Parser functions
These are documented at the main documentation page unless otherwise stated.

Metadata

 * (size of page in bytes)
 * (protection level for given action on the current page)
 * (number of pages in the given category)
 * (number of users in a specific group)

Add  to return numbers without commas.

Formatting

 * (convert to lower case)
 * (convert first character to lower case)
 * (convert to upper case)
 * (convert first character to upper case)
 * (format a number with comma separators; add  to unformat a number)
 * (formats a date according to user preferences; a default can be given as an optional case-sensitive second parameter for users without date preference; can convert a date from an existing format to any of,  ,   or   formats, with the user's preference overriding the specified format)
 * ,  (pad with zeros to the right or left; an alternative padding string can be given as a third parameter; the alternative padding string may be truncated if its length does not evenly divide the required number of characters)
 * (produces alternative text according to whether n is greater than 1)
 * (for date/time formatting; also  for local time. Covered at the extension documentation page.)
 * (produces alternative text according to the gender specified by the given user in his/her preferences)
 * (equivalent to an HTML tag or pair of tags; can be used for nesting references)

Paths

 * ,  (relative path to the title)
 * ,  (absolute path to the title, without a protocol prefix)
 * ,  (absolute path to the title, with a protocol prefix)
 * (absolute URL to a media file)
 * (input encoded for use in URLs)
 * (input encoded for use in URL section anchors)
 * (name for the namespace with index n; use  for the equivalent encoded for MediaWiki URLs)
 * (converts a relative file path to absolute; see the extension documentation)
 * (splits title into parts; see the extension documentation)

Conditional expressions

 * These are covered at the extension documentation page. Some parameters are optional.

caveats:

 * 1) it is based on identifiers and not general strings
 * 2) tested input is limited.
 * 3) it should support type tags
 * 4) it should support comments  and .
 * 5) math support can be improved to consider precedence