Skip to content

Commit

Permalink
feat: synchronize elementDeclaration name & alias also stops when a […
Browse files Browse the repository at this point in the history
… is found
  • Loading branch information
Huy-DNA committed Aug 5, 2023
1 parent bcd0127 commit ef73999
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/dbml-core/src/parse/dbml/src/lib/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class Parser {
if (!(e instanceof ParsingError)) {
throw e;
}
if (!(this.isAtEnd())) {
if (!this.isAtEnd()) {
this.invalid.push(this.advance());
} else {
const eof = this.peek();
Expand Down Expand Up @@ -155,7 +155,7 @@ export default class Parser {
) {
synchronizationPoint(
// eslint-disable-next-line no-return-assign
() => name = this.normalFormExpression(),
() => (name = this.normalFormExpression()),
this.synchronizeElementDeclarationName,
);

Expand All @@ -164,7 +164,7 @@ export default class Parser {
as = this.advance();
synchronizationPoint(
// eslint-disable-next-line no-return-assign
() => alias = this.normalFormExpression(),
() => (alias = this.normalFormExpression()),
this.synchronizeElementDeclarationAlias,
);
}
Expand Down Expand Up @@ -204,16 +204,17 @@ export default class Parser {
bodyOpenColon,
body,
});
},
);
},
);

synchronizeElementDeclarationName = () => {
while (!this.isAtEnd()) {
const token = this.peek();
if (
(token.kind === SyntaxTokenKind.IDENTIFIER && token.value === 'as') ||
token.kind === SyntaxTokenKind.LBRACE ||
token.kind === SyntaxTokenKind.COLON
token.kind === SyntaxTokenKind.COLON ||
token.kind === SyntaxTokenKind.LBRACKET
) {
break;
}
Expand All @@ -225,7 +226,11 @@ export default class Parser {
synchronizeElementDeclarationAlias = () => {
while (!this.isAtEnd()) {
const token = this.peek();
if (token.kind === SyntaxTokenKind.LBRACE || token.kind === SyntaxTokenKind.COLON) {
if (
token.kind === SyntaxTokenKind.LBRACE ||
token.kind === SyntaxTokenKind.COLON ||
token.kind === SyntaxTokenKind.LBRACKET
) {
break;
}
this.invalid.push(token);
Expand Down Expand Up @@ -732,8 +737,7 @@ export default class Parser {

private canBeField() {
return (
this.peek().kind === SyntaxTokenKind.IDENTIFIER &&
this.peek(1).kind === SyntaxTokenKind.COLON
this.peek().kind === SyntaxTokenKind.IDENTIFIER && this.peek(1).kind === SyntaxTokenKind.COLON
);
}

Expand Down

0 comments on commit ef73999

Please sign in to comment.