Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages with dashes #254

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading