Class: RegexOverwrite

RegexOverwrite

(protected) new RegexOverwrite()

Source:

Extends

Methods

(protected, static) _generateBody()

Source:

(protected, static) _registerCaptures()

Source:

(protected) _generate(context, termRequiresWrap) → {String}

important: _generate and _generateBody should never modify the term object.

implementation notes:

termRequiresWrap tells fragile term(s) in sub-expression that if protection is required. There are 2 situations: 0.no: If there is only one term, then the terms need not protection at all. 1.maybe: If the sub-expression is composed with more then one term, and the terms will be evaluated in order, i.e., will be concatenated directly, then the terms need not protection, unless it is the "either" expression.

[in traditional chinese]

termRequiresWrap 是要通知元素是否需要使用 group 來保護內容。

有兩種狀況:

0.no: 元素沒有兄弟元素(僅有一個子元素),則元素本身不需要特別保護。 1.maybe: 有兄弟元素,且兄弟元素之間將直接接合(concatenated), 元素應視需要(目前只有 either 運算式有此需要)自我保護。

Parameters:
Name Type Description
context Object

the context object of the regexGen generator.

termRequiresWrap Number

should the term requires wrap. See possible values descripted above.

Inherited From:
Source:
Returns:

the generated regular expression string literal.

Type
String

(protected) _generateBody(context, bodyRequiresWrap) → {String}

Parameters:
Name Type Description
context Object

the context object of the regexGen generator.

bodyRequiresWrap Number

should the body of term requires wrap. See possible values descripted in #_generate.

Inherited From:
Source:
Returns:

the generated regular expression string literal (body part).

Type
String

(protected) _init(body, quantifiers)

Initialize the term object, setup default values.

Parameters:
Name Type Description
body String

the expression string.

quantifiers String

the quantifiers applied on this term.

Inherited From:
Source:

(protected) _warn(msg, values)

Parameters:
Name Type Description
msg String

-

values Object

-

Inherited From:
Source:

any()

Matches the expression generated by the preceding sub-generator 0 or more times. Equivalent to /(.*)/ and /.{0,}/.

Inherited From:
Source:

contains(…terms)

Parameters:
Name Type Attributes Description
terms Object <repeatable>

-

Inherited From:
Source:

followedBy(…terms)

Matches 'x' only if 'x' is followed by 'y'. This is called a lookahead. (x(?=y))

Parameters:
Name Type Attributes Description
terms Object <repeatable>

-

Inherited From:
Source:

greedy()

Makes a quantifier greedy. Note that quantifier are greedy by default.

Inherited From:
Source:
Example
anyChar().any().greedy()       // ==> /.\u002A/
anyChar().many().greedy()      // ==> /.+/
anyChar().maybe().greedy()     // ==> /.?/

lazy()

Makes a quantifier lazy.

Inherited From:
Source:
Example
anyChar().any().lazy()          // ==> /.*?/
anyChar().many().lazy()         // ==> /.+?/
anyChar().maybe().lazy()        // ==> /.??/
anyChar().multiple(5,9).lazy()  // ==> /.{5,9}?/

many()

occurs one or more times (x+)

Inherited From:
Source:

maybe()

occurs zero or one times (x?)

Inherited From:
Source:

multiple()

occurs at least min times and (optional) at most max times (?||+|{min,}|{min,max}) occurs at least min times and (optional) at most max times (?||+|{min,}|{min,max})

Inherited From:
Source:

notContains(…terms)

Parameters:
Name Type Attributes Description
terms Object <repeatable>

-

Inherited From:
Source:

notFollowedBy(…terms)

Matches 'x' only if 'x' is not followed by 'y'. This is called a negated lookahead. (x(?!y))

Parameters:
Name Type Attributes Description
terms Object <repeatable>

-

Inherited From:
Source:

regex(value)

Use the given regex, i.e., trust me, just put the value as is.

Parameters:
Name Type Description
value RegExp | String
Inherited From:
Source:
Example
regex( /\w\d/ )       // ==> /\w\d/
regex( "\\w\\d" )     // ==> /\w\d/

reluctant()

This is an alias of lazy().

Inherited From:
Source:

repeat()

occurs at least once or exactly specified times (+|{n})

Inherited From:
Source: