Skip to content

Commit

Permalink
Merge pull request #254 from uqbar-project/files-with-dash
Browse files Browse the repository at this point in the history
Packages with dashes
  • Loading branch information
PalumboN authored Jul 3, 2024
2 parents 802038e + ccee8db commit ddd7ed3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ export const Import: Parser<ImportNode> = node(ImportNode)(() =>

export const name: Parser<Name> = lazy('identifier', () => regex(/[^\W\d]\w*/))

export const packageName: Parser<Name> = lazy('package identifier', () => regex(/[^\W\d][\w-]*/))

export const FullyQualifiedReference: Parser<ReferenceNode<any>> = node(ReferenceNode)(() =>
obj({ name: name.sepBy1(key('.')).tieWith('.') })
obj({ name: packageName.or(name).sepBy1(key('.')).tieWith('.') })
)

export const Reference: Parser<ReferenceNode<any>> = node(ReferenceNode)(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ sourceMapForNodeName)

export const shouldNotUseSpecialCharactersInName = error<Package>(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)
Expand Down
2 changes: 1 addition & 1 deletion src/wre/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ const game: Natives = {
},
}

export default game
export default game
8 changes: 7 additions & 1 deletion test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2176,6 +2179,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 })] })
Expand Down Expand Up @@ -2217,7 +2224,6 @@ class c {}`
it('should not parse fully qualified references with wrong characters', () => {
'p.*'.should.not.be.parsedBy(parser)
})

})


Expand Down

0 comments on commit ddd7ed3

Please sign in to comment.