@@map in Enums can not be parsed properly
madflow opened this issue · 1 comments
madflow commented
It seem that the parser/lexer/tokenizer (I dunno) does not support @@map
in Enums. As far as I can tell - this is perfectly valid:
https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#map-1
import { getSchema } from '@mrleebo/prisma-ast'
const source = `
enum MembershipRole {
OWNER
ADMIN
USER
@@map("membership_role")
}
`
const schema = getSchema(source)
throw this.SAVE_ERROR(new exceptions_public_1.NoViableAltException(errMsg, this.LA(1), previousToken));
^
NoViableAltException: Expecting: one of these possible Token sequences:
1. [Comment]
2. [Identifier, '=', StringLiteral]
3. [Identifier, '=', NumberLiteral]
4. [Identifier, '=', '[']
5. [Identifier, '=', Identifier]
6. [Identifier, '=', True]
7. [Identifier, '=', False]
8. [Identifier, '=', Null]
9. ['@@']
10. ['@']
11. [Identifier, StringLiteral]
12. [Identifier, NumberLiteral]
13. [Identifier, '[']
14. [Identifier, Identifier]
15. [Identifier, True]
16. [Identifier, False]
17. [Identifier, Null]
18. [Identifier]
19. [Identifier, '=', StringLiteral]
20. [Identifier, '=', NumberLiteral]
21. [Identifier, '=', '[']
22. [Identifier, '=', Identifier]
23. [Identifier, '=', True]
24. [Identifier, '=', False]
25. [Identifier, '=', Null]
26. [LineBreak, LineBreak]
27. [LineBreak]
but found: '@@'
at PrismaParser.ErrorHandler.raiseNoAltException (/Users/tester/node_modules/chevrotain/lib/src/parse/parser/traits/error_handler.js:80:31)
at PrismaParser.RecognizerEngine.orInternal (/Users//tester/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:402:14)
at PrismaParser.RecognizerApi.OR (/Users/tester/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_api.js:133:21)
at PrismaParser.<anonymous> (/Users/tester/node_modules/@mrleebo/prisma-ast/dist/prisma-ast.cjs.development.js:340:15)
at PrismaParser.RecognizerEngine.doSingleRepetition (/Users/tester/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:385:16)
at PrismaParser.RecognizerEngine.manyInternalLogic (/Users/tester/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:318:29)
at PrismaParser.RecognizerEngine.manyInternal (/Users/tester/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:295:21)
at PrismaParser.RecognizerApi.MANY (/Users/tester/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_api.js:163:14)
at PrismaParser.<anonymous> (/Users/tester/node_modules/@mrleebo/prisma-ast/dist/prisma-ast.cjs.development.js:339:13)
at PrismaParser.invokeRuleWithTry (/Users/tester/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:112:26) {
token: {
image: '@@',
startOffset: 49,
endOffset: 50,
startLine: 7,
endLine: 7,
startColumn: 3,
endColumn: 4,
tokenTypeIdx: 15,
tokenType: {
name: 'ModelAttribute',
PATTERN: /@@/,
CATEGORIES: [
{
name: 'Attribute',
PATTERN: /NOT_APPLICABLE/,
tokenTypeIdx: 14,
CATEGORIES: [],
categoryMatches: [ 15, 16 ],
categoryMatchesMap: { '15': true, '16': true },
isParent: true
}
],
tokenTypeIdx: 15,
categoryMatches: [],
categoryMatchesMap: {},
isParent: false,
LABEL: "'@@'"
}
},
resyncedTokens: [],
previousToken: {
image: '\n',
startOffset: 46,
endOffset: 46,
startLine: 6,
endLine: 6,
startColumn: 1,
endColumn: 1,
tokenTypeIdx: 32,
tokenType: {
name: 'LineBreak',
PATTERN: /\n|\r\n/,
tokenTypeIdx: 32,
CATEGORIES: [],
categoryMatches: [],
categoryMatchesMap: {},
isParent: false,
LABEL: 'LineBreak',
LINE_BREAKS: true
}
},
context: {
ruleStack: [ 'schema', 'component', 'block' ],
ruleOccurrenceStack: [ 0, 0, 0 ]
}
}
MrLeebo commented
Thank you for reporting this, I believe you are right. I'm only parsing @@map
for models, but they can also be applied to enums.