1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-08-04 18:20:37 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/filters/FilterSyntax.tid
2015-01-11 19:09:35 +00:00

95 lines
3.0 KiB
Plaintext

created: 20140210141217955
modified: 20150102174633890
tags: Filters
title: Filter Syntax
type: text/vnd.tiddlywiki
[[Filters]] follow a grammar that is presented here, using [[RailroadDiagrams]], for those who find formal syntax descriptions helpful. However, [[you can learn to write filters|Introduction to filter notation]] without needing to understand this tiddler.
When a filter is evaluated, it generates a <<doc-def result>>, which is an ordered set of items. No item can appear more than once in the result. The items are usually tiddler titles, but certain specialised filters generate other items, such as Node.js command words.
---
;filter
: <$railroad text="""
{ [:whitespace] ("+" | :- | "-") run }
"""/>
A <<doc-def filter>> is a sequence of runs, evaluated from left to right.
Each run receives an <<doc-def "input set">>, which it modifies to produce a result. The first run in a sequence receives `[all[tiddlers]]` as its input, i.e. the set of all non-missing tiddlers. The second run receives the result of the first run as its input, and so on.
|!Run |!Interpretation |!Result |
|`run` |union of sets|input OR run |
|`+run` |intersection of sets |input AND run |
|`-run` |difference of sets|input AND NOT run |
---
;run
: <$railroad text="""
( "[" {step} "]"
|
[:{/"anything but [ ] or whitespace"/}]
)
"""/>
<!-- The following has been removed from the diagram until issue #1346 is addressed:
'"' [:{/'anything but "'/}] '"'
|
"'" [:{/"anything but '"/}] '"'
|
-->
The lower option, e.g. matching `HelloThere`, is short for `[title[HelloThere]]`.
A <<doc-def run>> is a sequence of steps, evaluated from left to right.
The run's result is basically the intersection of the step results. In other words, the run's result contains the items that are found in <<doc-em all>> of the step results.
However, a few operators (known as <<doc-def selectors>>) ignore any preceding steps in the same run, and completely replace the result so far. Examples of this are <<doc-clink "commands" "FilterOperator: commands">> and <<doc-clink "title" "FilterOperator: title">>, but not <<doc-clink "field:title" "FilterOperator: field">>.
---
;step
: <$railroad text="""
[:"!"] [:method] parameter
"""/>
If the method is omitted, it defaults to `title`.
---
;method
: <$railroad text="""
operator [:":" suffix]
"""/>
The operator is drawn from a list of [[predefined names|FilterOperators]].
The suffix is additional information, usually the name of a [[field|TiddlerFields]], that extends the meaning of certain operators.
An unrecognised operator name is is treated as the suffix to the <<doc-clink "field" "FilterOperator: field">> operator.
---
;parameter
: <$railroad text="""
( "[" [:{/"anything but ]"/}] "]"
|
"{" [:{/"anything but }"/}] "}"
|
"<" [:{/"anything but >"/}] ">"
)
"""/>
* `[`...`]` encloses a literal parameter
* `{`...`}` encloses a TextReference parameter
* `<`...`>` encloses a [[variable|Variables]] parameter
---
;whitespace
: <$railroad text="""
{( "space" | "tab" | "linefeed" | "return" | "vertical tab" | "formfeed" )}
"""/>