From f31af02cf540b0aa9d86dd043991fd5c014b2c61 Mon Sep 17 00:00:00 2001 From: Maruf Rasully Date: Fri, 27 Dec 2024 14:06:58 +0300 Subject: [PATCH] fix: consider longer alt for null --- packages/binding-parser/src/lexer/token.ts | 6 +- .../test/unit/data/issues/735/ast.json | 54 ++++++++++++ .../test/unit/data/issues/735/cst.json | 82 +++++++++++++++++++ .../test/unit/data/issues/735/input.txt | 1 + .../unit/data/issues/735/lexer-errors.json | 1 + .../unit/data/issues/735/parse-errors.json | 1 + 6 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 packages/binding-parser/test/unit/data/issues/735/ast.json create mode 100644 packages/binding-parser/test/unit/data/issues/735/cst.json create mode 100644 packages/binding-parser/test/unit/data/issues/735/input.txt create mode 100644 packages/binding-parser/test/unit/data/issues/735/lexer-errors.json create mode 100644 packages/binding-parser/test/unit/data/issues/735/parse-errors.json diff --git a/packages/binding-parser/src/lexer/token.ts b/packages/binding-parser/src/lexer/token.ts index 40ab94e14..f46a560a7 100644 --- a/packages/binding-parser/src/lexer/token.ts +++ b/packages/binding-parser/src/lexer/token.ts @@ -86,7 +86,11 @@ const numberValue = createToken({ pattern: /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/, }); -const nullValue = createToken({ name: NULL_VALUE, pattern: /null/ }); +const nullValue = createToken({ + name: NULL_VALUE, + pattern: /null/, + longer_alt: key, +}); const comma = createToken({ name: COMMA, diff --git a/packages/binding-parser/test/unit/data/issues/735/ast.json b/packages/binding-parser/test/unit/data/issues/735/ast.json new file mode 100644 index 000000000..433b358ce --- /dev/null +++ b/packages/binding-parser/test/unit/data/issues/735/ast.json @@ -0,0 +1,54 @@ +{ + "bindings": [ + { + "leftCurly": { + "type": "left-curly", + "text": "{", + "range": "[(0,0)..(0,1)]" + }, + "elements": [ + { + "key": { + "type": "key", + "text": "nullable", + "range": "[(0,1)..(0,9)]", + "originalText": "nullable" + }, + "colon": { + "type": "colon", + "text": ":", + "range": "[(0,9)..(0,10)]" + }, + "value": { + "type": "boolean-value", + "text": "false", + "range": "[(0,11)..(0,16)]" + }, + "range": "[(0,1)..(0,16)]", + "type": "structure-element" + } + ], + "rightCurly": { + "type": "right-curly", + "text": "}", + "range": "[(0,17)..(0,18)]" + }, + "range": "[(0,0)..(0,18)]", + "commas": [], + "type": "structure-value" + } + ], + "spaces": [ + { + "type": "white-space", + "text": " ", + "range": "[(0,10)..(0,11)]" + }, + { + "type": "white-space", + "text": " ", + "range": "[(0,16)..(0,17)]" + } + ], + "type": "template" +} diff --git a/packages/binding-parser/test/unit/data/issues/735/cst.json b/packages/binding-parser/test/unit/data/issues/735/cst.json new file mode 100644 index 000000000..f810e996e --- /dev/null +++ b/packages/binding-parser/test/unit/data/issues/735/cst.json @@ -0,0 +1,82 @@ +{ + "name": "template", + "children": { + "object": [ + { + "name": "object", + "children": { + "left-curly": [ + { + "image": "{", + "startColumn": 1, + "endColumn": 1, + "tokenTypeName": "left-curly" + } + ], + "object-item": [ + { + "name": "object-item", + "children": { + "key": [ + { + "image": "nullable", + "startColumn": 2, + "endColumn": 9, + "tokenTypeName": "key" + } + ], + "colon": [ + { + "image": ":", + "startColumn": 10, + "endColumn": 10, + "tokenTypeName": "colon" + } + ], + "value": [ + { + "name": "value", + "children": { + "boolean-value": [ + { + "image": "false", + "startColumn": 12, + "endColumn": 16, + "tokenTypeName": "boolean-value" + } + ] + }, + "location": { + "startColumn": 12, + "endColumn": 16 + } + } + ] + }, + "location": { + "startColumn": 2, + "endColumn": 16 + } + } + ], + "right-curly": [ + { + "image": "}", + "startColumn": 18, + "endColumn": 18, + "tokenTypeName": "right-curly" + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 18 + } + } + ] + }, + "location": { + "startColumn": 1, + "endColumn": 18 + } +} diff --git a/packages/binding-parser/test/unit/data/issues/735/input.txt b/packages/binding-parser/test/unit/data/issues/735/input.txt new file mode 100644 index 000000000..a384d4580 --- /dev/null +++ b/packages/binding-parser/test/unit/data/issues/735/input.txt @@ -0,0 +1 @@ +{nullable: false } \ No newline at end of file diff --git a/packages/binding-parser/test/unit/data/issues/735/lexer-errors.json b/packages/binding-parser/test/unit/data/issues/735/lexer-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/issues/735/lexer-errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/binding-parser/test/unit/data/issues/735/parse-errors.json b/packages/binding-parser/test/unit/data/issues/735/parse-errors.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/packages/binding-parser/test/unit/data/issues/735/parse-errors.json @@ -0,0 +1 @@ +[]