1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-28 14:54:29 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/moduletypes/WikiRuleModules.tid
Jermolene 2261fd4b84 Merge the dev material back into the main tw5.com wiki
It was getting a pain to manage the content in separate places, and I
suspect confusing for end users.

I think the best time to move the dev content out is when we’ve
established the community wiki for TW5, which is a much more natural
home for it.

In the meantime, a feature that I’m interested in exploring is the
ability to hide tiddlers from the UI based on tag. Then the tw5.com
wiki could disable all tiddlers tagged ‘dev’ until explicitly
overridden by the user.
2013-11-28 17:12:18 +00:00

34 lines
2.3 KiB
Plaintext

created: 201308252147
creator: JeremyRuston
modified: 201311011307
modifier: JeremyRuston
tags: dev moduletypes
title: WikiRuleModules
WikiRuleModules cover the module types `wikirunrule`, `wikiblockrule` and `wikipragmarule`. Modules of these types encapsulate the logic of individual parsing rules used by the WikiParser engine. For example, there is a `wikirunrule` module that identifies references to HTML entities by matching the pattern `&<chars>;`.
Pragma rules are applied at the start of a block of text, and cover definitions and declarations that affect the parsing of the rest of the text. Block rules are only applied at the beginning of a block of wikitext, while run rules can appear anywhere. The only current example of a pragma rule is for macro definitions.
Examples of block rules:
* Headings
* Tables
* Lists
Examples of run rules:
* Entities
* HTML tags
* Wiki links
Parser rule modules extend the `$tw.WikiParserRule` class. This is done by instantiating the class and then copying the exports of the rule module onto the instance. In this way, the parser rule can override the base behaviour of the `$tw.WikiParserRule` class. In particular, the base class incorporates logic for using regular expressions to match parse rules but this logic could be overridden by a parse rule that wanted to, say, use `indexOf()` instead of regular expressions.
The standard methods and properties of parser rules are as follows:
* `name`: a string containing the name of this parse rule
* `init(parser)`: initialisation function called immediately after the constructor with a pointer back to the parser containing this rule
* `findNextMatch(pos)`: returns the position of the next match after the specified position
* `parse()`: parses the most recent match, returning an array of the generated parse tree nodes. Pragma rules don't return parse tree nodes but instead modify the parser object directly (for example, to add local macro definitions)
The built in parser rules use regular expression matching. Such rules can take advantage of the implementation of `findNextMatch()` in the base `$tw.WikiRule` class by ensuring that their `init()` method creates a `matchRegExp` property containing the regular expression to match. The `match` property contains the details of the match for use in the `parse()` method.