Skip to content

Commit

Permalink
Fix printing of quantifiers after \p{...} (#23)
Browse files Browse the repository at this point in the history
* `node tests/update-fixtures.js`

* Fix printing of quantifiers after `\p{...}`
  • Loading branch information
nicolo-ribaudo authored Jan 17, 2022
1 parent 561c458 commit a4f6e0a
Show file tree
Hide file tree
Showing 5 changed files with 428 additions and 20 deletions.
6 changes: 4 additions & 2 deletions regjsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@
}
}

var atomType = 'anchor|characterClass|characterClassEscape|dot|group|reference|unicodePropertyEscape|value';

function generateAtom(node) {
assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
assertType(node.type, atomType);

return generate(node);
}
Expand Down Expand Up @@ -307,7 +309,7 @@
}

function generateTerm(node) {
assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value|dot');
assertType(node.type, atomType + '|empty|quantifier');

return generate(node);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/test-data-lookbehind.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"raw": "\\d"
}
],
"symbol": "+",
"range": [
7,
10
Expand Down Expand Up @@ -81,6 +82,7 @@
"raw": "\\d"
}
],
"symbol": "*",
"range": [
13,
16
Expand All @@ -95,6 +97,7 @@
"raw": "(\\.\\d*)"
}
],
"symbol": "?",
"range": [
10,
18
Expand Down Expand Up @@ -141,6 +144,7 @@
"raw": "\\d"
}
],
"symbol": "+",
"range": [
6,
9
Expand Down Expand Up @@ -180,6 +184,7 @@
"raw": "\\d"
}
],
"symbol": "+",
"range": [
12,
15
Expand Down Expand Up @@ -233,6 +238,7 @@
"raw": "\\d"
}
],
"symbol": "+",
"range": [
7,
10
Expand Down Expand Up @@ -269,6 +275,7 @@
"raw": "\\d"
}
],
"symbol": "*",
"range": [
15,
18
Expand Down
50 changes: 32 additions & 18 deletions tests/test-data-named-groups-unicode.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,53 @@
"message": "Invalid code point 16777215",
"input": "(?<\\u{ffffff})"
},
"(?<$𐒤>a)": {
"(?<$\uD801\uDCA4>a)": {
"type": "group",
"behavior": "normal",
"body": [{
"type": "value",
"kind": "symbol",
"codePoint": 97,
"range": [7, 8],
"raw": "a"
}],
"range": [0, 9],
"raw": "(?<$𐒤>a)",
"body": [
{
"type": "value",
"kind": "symbol",
"codePoint": 97,
"range": [
7,
8
],
"raw": "a"
}
],
"range": [
0,
9
],
"raw": "(?<$\uD801\uDCA4>a)",
"name": {
"type": "identifier",
"value": "$𐒤",
"value": "$\uD801\uDCA4",
"range": [
3,
6
],
"raw": "$𐒤"
"raw": "$\uD801\uDCA4"
}
},
"(?<\\u{102A7}Ƞ>)": {
"(?<\\u{102A7}\u0220>)": {
"type": "group",
"behavior": "normal",
"body": [],
"range": [0, 15],
"raw": "(?<\\u{102A7}Ƞ>)",
"range": [
0,
15
],
"raw": "(?<\\u{102A7}\u0220>)",
"name": {
"type": "identifier",
"value": "𐊧Ƞ",
"range": [3, 13],
"raw": "\\u{102A7}Ƞ"
"value": "\uD800\uDEA7\u0220",
"range": [
3,
13
],
"raw": "\\u{102A7}\u0220"
}
}
}
48 changes: 48 additions & 0 deletions tests/test-data-unicode-properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,54 @@
],
"raw": "foo\\P{ASCII_Hex_Digit}bar"
},
"\\p{ASCII_Hex_Digit}{4}": {
"type": "quantifier",
"min": 4,
"max": 4,
"greedy": true,
"body": [
{
"type": "unicodePropertyEscape",
"negative": false,
"value": "ASCII_Hex_Digit",
"range": [
0,
19
],
"raw": "\\p{ASCII_Hex_Digit}"
}
],
"symbol": null,
"range": [
0,
22
],
"raw": "\\p{ASCII_Hex_Digit}{4}"
},
"\\p{ASCII_Hex_Digit}+": {
"type": "quantifier",
"min": 1,
"max": null,
"greedy": true,
"body": [
{
"type": "unicodePropertyEscape",
"negative": false,
"value": "ASCII_Hex_Digit",
"range": [
0,
19
],
"raw": "\\p{ASCII_Hex_Digit}"
}
],
"symbol": "+",
"range": [
0,
20
],
"raw": "\\p{ASCII_Hex_Digit}+"
},
"\\p{}": {
"type": "error",
"name": "SyntaxError",
Expand Down
Loading

0 comments on commit a4f6e0a

Please sign in to comment.