Skip to content

Commit

Permalink
0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitrySoshnikov committed May 17, 2019
1 parent b0babb4 commit 4873506
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "regexp-tree",
"version": "0.1.5",
"version": "0.1.6",
"license": "MIT",
"description": "Regular Expressions parser in JavaScript",
"repository": "DmitrySoshnikov/regexp-tree",
Expand Down
24 changes: 16 additions & 8 deletions src/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const generator = {
},

Alternative(node) {
return (node.expressions || [])
.map(gen)
.join('');
return (node.expressions || []).map(gen).join('');
},

Disjunction(node) {
Expand All @@ -34,7 +32,6 @@ const generator = {
const expression = gen(node.expression);

if (node.capturing) {

// A named group.
if (node.name) {
return `(?<${node.name}>${expression})`;
Expand Down Expand Up @@ -91,9 +88,7 @@ const generator = {
},

CharacterClass(node) {
const expressions = node.expressions
.map(gen)
.join('');
const expressions = node.expressions.map(gen).join('');

if (node.negative) {
return `[^${expressions}]`;
Expand Down Expand Up @@ -164,6 +159,19 @@ const generator = {
throw new TypeError(`Unknown Char kind: ${node.kind}`);
}
},

UnicodeProperty(node) {
const escapeChar = node.negative ? 'P' : 'p';
let namePart;

if (!node.shorthand && !node.binary) {
namePart = `${node.name}=`;
} else {
namePart = '';
}

return `\\${escapeChar}{${namePart}${node.value}}`;
},
};

module.exports = {
Expand All @@ -173,4 +181,4 @@ module.exports = {
* @param Object ast - an AST node
*/
generate: gen,
};
};
Loading

0 comments on commit 4873506

Please sign in to comment.