From 3e0928377fa0ce416be86cfcb4fb68026336ed37 Mon Sep 17 00:00:00 2001 From: ivojawer Date: Wed, 19 Jun 2024 19:22:53 -0300 Subject: [PATCH 1/5] archivos con guin WIP --- src/parser.ts | 4 +++- src/validator/index.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 097e3542..5677c2fd 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -165,8 +165,10 @@ export const Import: Parser = node(ImportNode)(() => export const name: Parser = lazy('identifier', () => regex(/[^\W\d]\w*/)) +export const packageName: Parser = regex(/\W[\W-]*/) + export const FullyQualifiedReference: Parser> = node(ReferenceNode)(() => - obj({ name: name.sepBy1(key('.')).tieWith('.') }) + obj({ name: packageName.or(name).sepBy1(key('.')).tieWith('.') }) ) export const Reference: Parser> = node(ReferenceNode)(() => diff --git a/src/validator/index.ts b/src/validator/index.ts index ee85f7e1..ed2c3c80 100644 --- a/src/validator/index.ts +++ b/src/validator/index.ts @@ -453,7 +453,7 @@ sourceMapForNodeName) export const shouldNotUseSpecialCharactersInName = error(node => !node.fileName || - node.fileName.match(/([A-Za-z._/\d])/g)!.length === node.fileName.length + node.fileName.match(/([A-Za-z.\-_/\d])/g)!.length === node.fileName.length && node.fileName.match(/\./g)!.length === 1 , valuesForFileName, sourceMapForNodeName) From 9395d41f3a11360ef9931dc3364e8fa9f239ae4c Mon Sep 17 00:00:00 2001 From: ivojawer Date: Fri, 21 Jun 2024 17:59:07 -0300 Subject: [PATCH 2/5] filename validation + fqn parser --- src/parser.ts | 2 +- src/validator/index.ts | 2 +- src/wre/game.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 2bded46a..7ad53e69 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -187,7 +187,7 @@ export const Import: Parser = node(ImportNode)(() => export const name: Parser = lazy('identifier', () => regex(/[^\W\d]\w*/)) -export const packageName: Parser = regex(/\W[\W-]*/) +export const packageName: Parser = lazy('package identifier', () => regex(/[^\W\d][\w-]*/)) export const FullyQualifiedReference: Parser> = node(ReferenceNode)(() => obj({ name: packageName.or(name).sepBy1(key('.')).tieWith('.') }) diff --git a/src/validator/index.ts b/src/validator/index.ts index ed2c3c80..ee85f7e1 100644 --- a/src/validator/index.ts +++ b/src/validator/index.ts @@ -453,7 +453,7 @@ sourceMapForNodeName) export const shouldNotUseSpecialCharactersInName = error(node => !node.fileName || - node.fileName.match(/([A-Za-z.\-_/\d])/g)!.length === node.fileName.length + node.fileName.match(/([A-Za-z._/\d])/g)!.length === node.fileName.length && node.fileName.match(/\./g)!.length === 1 , valuesForFileName, sourceMapForNodeName) diff --git a/src/wre/game.ts b/src/wre/game.ts index f54301da..e56f64f2 100644 --- a/src/wre/game.ts +++ b/src/wre/game.ts @@ -181,4 +181,4 @@ const game: Natives = { }, } -export default game +export default game \ No newline at end of file From 4f1e216ce9c4ec9dd00a93c9b08251413a95d90a Mon Sep 17 00:00:00 2001 From: ivojawer Date: Fri, 21 Jun 2024 18:42:06 -0300 Subject: [PATCH 3/5] test: parse fqn with dashes --- test/parser.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/parser.test.ts b/test/parser.test.ts index 3db9911f..a3458c1f 100644 --- a/test/parser.test.ts +++ b/test/parser.test.ts @@ -2167,6 +2167,10 @@ class c {}` 'p.o'.should.be.parsedBy(parser).into(new Reference({ name: 'p.o' })).and.be.tracedTo(0, 3) }) + it ('should parse fully quelified references with -', () => { + 'p-p.C'.should.be.parsedBy(parser) + }) + it('should parse annotated nodes', () => { '@A(x = 1) x'.should.be.parsedBy(parser).into( new Reference({ name: 'x', metadata: [new Annotation('A', { x: 1 })] }) @@ -2208,7 +2212,6 @@ class c {}` it('should not parse fully qualified references with wrong characters', () => { 'p.*'.should.not.be.parsedBy(parser) }) - }) From fb67338451d84a31e0c6aa342f08a75a51dadab9 Mon Sep 17 00:00:00 2001 From: ivojawer Date: Fri, 21 Jun 2024 18:45:11 -0300 Subject: [PATCH 4/5] dash validation --- src/validator/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validator/index.ts b/src/validator/index.ts index ee85f7e1..ed2c3c80 100644 --- a/src/validator/index.ts +++ b/src/validator/index.ts @@ -453,7 +453,7 @@ sourceMapForNodeName) export const shouldNotUseSpecialCharactersInName = error(node => !node.fileName || - node.fileName.match(/([A-Za-z._/\d])/g)!.length === node.fileName.length + node.fileName.match(/([A-Za-z.\-_/\d])/g)!.length === node.fileName.length && node.fileName.match(/\./g)!.length === 1 , valuesForFileName, sourceMapForNodeName) From 196851823726059ba6776885e406f8496bbd26cb Mon Sep 17 00:00:00 2001 From: ivojawer Date: Fri, 28 Jun 2024 00:33:35 -0300 Subject: [PATCH 5/5] should not parse dashed objects --- test/parser.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/parser.test.ts b/test/parser.test.ts index a3458c1f..b100a732 100644 --- a/test/parser.test.ts +++ b/test/parser.test.ts @@ -1099,6 +1099,9 @@ describe('Wollok parser', () => { ) }) + it('should not parse dashed objects', () => { + 'object my-object {}'.should.not.be.parsedBy(parser) + }) it('should recover from member parse error', () => { 'object o {var var1 vr var2 var var3}'.should.be.parsedBy(parser)