Skip to content

Commit

Permalink
Refined docs; added words; more tests; fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxArt2501 committed Apr 18, 2015
1 parent 4362066 commit 3a94db5
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 51 deletions.
26 changes: 25 additions & 1 deletion doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ var builder = RE.matching.theStart

Other words that work as functions only usually accept other types of arguments.

## Flags

The flags of a builder (and its underlying regular expression) can be set using words starting from the `RE` object. After one of these words, another flag word or `matching` must follow, with the exception of `withFlags` that must be followed by `matching` only.

* **`globally`**

Set the `global` flag on.

* **`anyCase`**

Set the `ignoreCase` flag on.

* **`fullText`**

Set the `multiline` flag on.

* **`stickily`**

Set the `sticky` flag on.

* **`withFlags(flags)`**

Set multiple flags. `flags` is expected to be a string containing letters in the set `"g"`, `"m"`, `"i"` and `"y"`.

## Conjunctions

Conjunctions append additional blocks to the current source. They can follow any open or set block.
Expand Down Expand Up @@ -141,7 +165,7 @@ These words can be used in character sets only:

* **`range(start, end)`**

Adds a character interval into the character set (`[...start-end...]`). `start` and `end` are supposed to be strings of single characters defining the boundaries of the character range.
Adds a character interval into the character set (`[...start-end...]`). `start` and `end` are supposed to be strings of single characters defining the boundaries of the character range; or they can be builders that define one single character, or character class usable in character ranges (which include: `ascii`, `unicode`, `control`, `newLine`, `cReturn`, `tab`, `vTab`, `formFeed`, `null`).

* **`backspace`**

Expand Down
19 changes: 16 additions & 3 deletions re-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
newLine: ["\\n"],
formFeed: ["\\f"],
null: ["\\0"],
slash: ["\\/"],
backslash: ["\\\\"],

theStart: ["^", "", NOQUANTIFY + NOSETS],
theEnd: ["$", "", NOQUANTIFY + NOSETS],
Expand Down Expand Up @@ -264,10 +266,21 @@
+ "\\b" + source.slice(lastBracket)), [ thenable, andCharSet ]);
};
settable.range = function() {
function checkBoundary(bnd) {
if (typeof bnd === "string" && bnd.length === 1)
return parseSets(bnd);

if (bnd instanceof RegExpBuilder) {
bnd = bnd.source;
if (bnd.length === 1 || /^\\(?:[0btnvfr\/\\]|x[\da-fA-F]{2}|u[\da-fA-F]{4}|c[a-zA-Z])$/.test(bnd))
return bnd;
}

throw new RangeError("Incorrect character range");
}
return function(start, end) {
if (typeof start !== "string" || typeof end !== "string"
|| start.length !== 1 || end.length !== 1)
throw new RangeError("Incorrect character range");
start = checkBoundary(start);
end = checkBoundary(end);

var source = this.source,
lastBracket = source.lastIndexOf("]");
Expand Down
2 changes: 1 addition & 1 deletion re-build.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3a94db5

Please sign in to comment.