Skip to content

Commit

Permalink
fix(common): fix title and acc multiple times declaration (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: Yokozuna59 <u.yokozuna@gmail.com>
  • Loading branch information
Yokozuna59 authored May 25, 2023
1 parent cc071a2 commit 59fb1d7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 47 deletions.
57 changes: 19 additions & 38 deletions packages/mermaid-parser/src/language/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@8"
"$ref": "#/rules@7"
},
"arguments": [],
"cardinality": "*"
Expand All @@ -61,7 +61,7 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@8"
"$ref": "#/rules@7"
},
"arguments": [],
"cardinality": "*"
Expand All @@ -83,7 +83,7 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@8"
"$ref": "#/rules@7"
},
"arguments": [],
"cardinality": "+"
Expand All @@ -106,7 +106,7 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@8"
"$ref": "#/rules@7"
},
"arguments": [],
"cardinality": "*"
Expand Down Expand Up @@ -135,7 +135,7 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@10"
"$ref": "#/rules@9"
},
"arguments": []
}
Expand All @@ -151,7 +151,7 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@9"
"$ref": "#/rules@8"
},
"arguments": []
}
Expand Down Expand Up @@ -182,7 +182,8 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
"$ref": "#/rules@4"
},
"arguments": []
}
},
"cardinality": "+"
},
{
"$type": "Assignment",
Expand All @@ -194,7 +195,8 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
"$ref": "#/rules@5"
},
"arguments": []
}
},
"cardinality": "+"
},
{
"$type": "Group",
Expand All @@ -206,30 +208,19 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@7"
"$ref": "#/rules@6"
},
"arguments": []
}
},
"cardinality": "+"
},
{
"$type": "Alternatives",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@6"
},
"arguments": []
},
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@8"
},
"arguments": [],
"cardinality": "+"
}
]
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@7"
},
"arguments": [],
"cardinality": "*"
}
]
}
Expand Down Expand Up @@ -261,16 +252,6 @@ export const MermaidGrammar = (): Grammar => loadedMermaidGrammar ?? (loadedMerm
"fragment": false,
"hidden": false
},
{
"$type": "TerminalRule",
"name": "EOF",
"definition": {
"$type": "RegexToken",
"regex": "\\\\z"
},
"fragment": false,
"hidden": false
},
{
"$type": "TerminalRule",
"name": "TITLE",
Expand Down
5 changes: 2 additions & 3 deletions packages/mermaid-parser/src/language/grammars/common.langium
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* fragments */
fragment TITLE_AND_ACCESSIBILITIES:
accDescr=ACC_DESCR & accTitle=ACC_TITLE & title=TITLE
(EOF | NEWLINE+)
accDescr=ACC_DESCR+ & accTitle=ACC_TITLE+ & title=TITLE+
NEWLINE*
;

/* terminals */
// placeholder terminals
terminal ACC_DESCR: /accDescr/;
terminal ACC_TITLE: /accTitle/;
terminal EOF: /\z/;
terminal TITLE: /title/;

terminal NEWLINE: /\n/;
Expand Down
8 changes: 2 additions & 6 deletions packages/mermaid-parser/src/language/mermaid-token-builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EOF, TokenType } from 'chevrotain';
import { TokenType } from 'chevrotain';
import { DefaultTokenBuilder } from 'langium';
import { TerminalRule } from 'langium/lib/grammar/generated/ast';

Expand All @@ -11,17 +11,13 @@ import {

export class MermiadTokenBuilder extends DefaultTokenBuilder {
override buildTerminalToken(terminal: TerminalRule): TokenType {
let tokenType = super.buildTerminalToken(terminal);
const tokenType = super.buildTerminalToken(terminal);
switch (tokenType.name) {
case 'WHITESPACES': {
tokenType.LINE_BREAKS = true;
tokenType.PATTERN = removeWhitespaces;
break;
}
case 'EOF': {
tokenType = EOF;
break;
}
case 'ACC_DESCR': {
tokenType.LINE_BREAKS = true;
tokenType.PATTERN = matchAccessibilityDescr;
Expand Down

0 comments on commit 59fb1d7

Please sign in to comment.