From 4f138f5e4c9034fdf76cddc7c7071cd4f4e0fea7 Mon Sep 17 00:00:00 2001 From: nmigueles Date: Sun, 24 Nov 2024 18:52:24 -0300 Subject: [PATCH 1/3] poc --- src/parser.ts | 2 +- test/parser.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index 6fb97650..372b6eae 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -194,7 +194,7 @@ export const Import: Parser = node(ImportNode)(() => // COMMON // ────────────────────────────────────────────────────────────────────────────────────────────────────────────────── -export const name: Parser = lazy('identifier', () => regex(/[^\W\d]\w*/)) +export const name: Parser = lazy('identifier', () => regex(/^[\p{L}_][\p{L}\p{N}_]*/u)) export const packageName: Parser = lazy('package identifier', () => regex(/[^\W\d][\w-]*/)) diff --git a/test/parser.test.ts b/test/parser.test.ts index 5a92c349..5058973a 100644 --- a/test/parser.test.ts +++ b/test/parser.test.ts @@ -311,6 +311,10 @@ describe('Wollok parser', () => { '_foo123'.should.be.be.parsedBy(parser).into('_foo123') }) + it('should parse names that contains unicode chars', () => { + '_foö123_and_bár'.should.be.be.parsedBy(parser).into('_foö123_and_bár') + }) + it('should not parse names with spaces', () => { 'foo bar'.should.not.be.parsedBy(parser) }) @@ -327,6 +331,9 @@ describe('Wollok parser', () => { '"foo"'.should.not.be.parsedBy(parser) }) + it('should not parse strings containing unicode as names', () => { + '"foö"'.should.not.be.parsedBy(parser) + }) }) @@ -1871,6 +1878,10 @@ class c {}` 'var v'.should.be.parsedBy(parser).into(new Variable({ name: 'v', isConstant: false })).and.be.tracedTo(0, 5) }) + it('should parse var declaration with non-ascii caracter in identifier', () => { + 'var ñ'.should.be.parsedBy(parser).into(new Variable({ name: 'ñ', isConstant: false })).and.be.tracedTo(0, 5) + }) + it('should parse var asignation', () => { 'var v = 5'.should.be.parsedBy(parser).into( new Variable({ @@ -2197,6 +2208,18 @@ class c {}` ) }) + it('should parse references starting with unicode letter', () => { + 'ñ'.should.be.parsedBy(parser).into(new Reference({ name: 'ñ' })).and.be.tracedTo(0, 1) + }) + + it('should parse references containing unicode letter', () => { + 'some_ñandu'.should.be.parsedBy(parser).into(new Reference({ name: 'some_ñandu' })).and.be.tracedTo(0, 10) + }) + + it('should not parse references starting with numbers that contain unicode letters', () => { + '4ñandu'.should.not.be.parsedBy(parser) + }) + it('should not parse references with spaces', () => { 'foo bar'.should.not.be.parsedBy(parser) }) From 3355f94bda3c2dcb4716ab9320c062ddf48f9fc2 Mon Sep 17 00:00:00 2001 From: Fernando Dodino Date: Sun, 15 Dec 2024 22:31:22 -0300 Subject: [PATCH 2/3] Fix validator --- src/validator/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/validator/index.ts b/src/validator/index.ts index f8e4c44b..a734fa9d 100644 --- a/src/validator/index.ts +++ b/src/validator/index.ts @@ -75,9 +75,9 @@ export const nameMatches = (regex: RegExp): (node: Node & { name: string }, code sourceMapForNodeName, ) -export const nameShouldBeginWithUppercase = nameMatches(/^[A-Z]/) +export const nameShouldBeginWithUppercase = nameMatches(/^[A-ZÑÁÉÍÓÚ]/) -export const nameShouldBeginWithLowercase = nameMatches(/^[a-z_<]/) +export const nameShouldBeginWithLowercase = nameMatches(/^[a-z_<ñáéíóú]/) export const nameShouldNotBeKeyword = error(node => !RESERVED_WORDS.includes(node.name || ''), From d71ceca060a048b4d633a936bc376bab3d25ede6 Mon Sep 17 00:00:00 2001 From: Fernando Dodino Date: Thu, 19 Dec 2024 22:12:20 -0300 Subject: [PATCH 3/3] Fix for new reference --- src/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index 9f545b22..0ffabf50 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -198,7 +198,7 @@ export const Import: Parser = node(ImportNode)(() => export const name: Parser = lazy('identifier', () => regex(/^[\p{L}_][\p{L}\p{N}_]*/u)) -export const packageName: Parser = lazy('package identifier', () => regex(/[^\W\d][\w-]*/)) +export const packageName: Parser = lazy('package identifier', () => regex(/[^\W\d][\w\p{L}-]*/u)) export const FullyQualifiedReference: Parser> = node(ReferenceNode)(() => obj({ name: packageName.or(name).sepBy1(key('.')).tieWith('.') })