模組:TextPredicate/doc
此頁面為 Module:TextPredicate 的說明文件
簡介
TextPredicate用於解析一個text文本構成的布爾表達式。能夠解析一段滿足格式要求的文本作為表達式。可以進行與或非操作,可以進行判斷。供其他模塊調用。如textPredicate=require("Moudle:TextPredicate")。
屬性
符號
為避免與維基文本使用的特殊字符重複,允許符號重定義。
symbolOr:表示「或」的符號。默認為|。symbolAnd:表示「與」的符號。默認為&。symbolNot:表示「非」的符號。默認為-。symbolBrackets:表示「括號」的兩個符號。默認為()。
一般而言匹配文本時需要更改symbolOr符號,避免衝突。
值
_true:絕對為真的表達式。_false:絕對為假的表達式。
函數
生成
textPredicate.createExpress(text)
識別文本並生成表達式。規則與通常的布爾表達式相同,除規定符號外文本皆視為變量。
在不改變符號的情況下,表達式可以表示如:a&-b|(a&c)。也可以表示如变量1|这个&(那个|-变量b)。
判斷
textPredicate:__call(names)
即textPredicate(names)對一組變量表進行判斷,判別表達式下是否成立。該表內應為变量名或symbolNot变量名,表示真或假。
textPredicate:__eq(other)
即textPredicate==other,判斷表達式內容實質是否相同。
textPredicate:__le(other)
即textPredicate<=other,判斷表達式內容實質是否被後者包含。即該表達式成立時後者必然成立。
textPredicate:isReal(bool)
判斷表達式是否恆為真/假。與textPredicate==textPredicate._truetextPredicate==textPredicate._false等效。
留空則判斷表達式是否為真值。
計算
由於元方法支持有限,符號比較錯亂。 自身運算表示並不返回值,而是將值賦值到第一個參數中。
textPredicate:__concat(other)
即textPredicate..other,計算表達式的「與」。
自身運算為textPredicate:concat(other)。
textPredicate:__add(other)
即textPredicate+other,計算表達式的「或」。
自身運算為textPredicate:add(other)。
textPredicate:__unm()
即-textPredicate,計算表達式的「非」。
自身運算為textPredicate:unm(other)。
textPredicate:__sub(other)
即textPredicate-other,計算表達式的「差」。但如果調用方法則會同時返回表達式的「與」,
自身運算為textPredicate:sub(other)。返回表達式的「與」。
textPredicate:changeListClone(list)
list為一組變量文本。
計算表達式改變使用的變量組後的情況。默認不在list中的變量值均為true。
自身運算為textPredicate:changeList(other)。
textPredicate:limitTo(list)
list為一組變量文本。
限制表達式使用的變量組,默認不在list中的變量值均為false。
迭代器
textPredicate:gAllowNames()
依次返回表達式允許情況的bits值以及與之對應的一個變量文本的表。該表內容與#textPredicate:__call(names)一致。