mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-17 22:39:56 +02:00
🖋️ Refactor common grammar to avoid unwanted greedy terminals
This commit is contained in:
2
packages/parser/src/language/architecture/arch.langium
Normal file
2
packages/parser/src/language/architecture/arch.langium
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
terminal ARCH_ICON: /\([\w-:]+\)/;
|
||||||
|
terminal ARCH_TITLE: /\[[\w ]+\]/;
|
@@ -1,14 +1,15 @@
|
|||||||
grammar Architecture
|
grammar Architecture
|
||||||
import "../common/common";
|
import "../common/common";
|
||||||
|
import "arch";
|
||||||
|
|
||||||
entry Architecture:
|
entry Architecture:
|
||||||
NEWLINE*
|
NEWLINE*
|
||||||
"architecture-beta"
|
"architecture-beta"
|
||||||
(
|
(
|
||||||
NEWLINE* TitleAndAccessibilities
|
NEWLINE
|
||||||
| NEWLINE* Statement*
|
| TitleAndAccessibilities
|
||||||
| NEWLINE*
|
| Statement
|
||||||
)
|
)*
|
||||||
;
|
;
|
||||||
|
|
||||||
fragment Statement:
|
fragment Statement:
|
||||||
@@ -31,25 +32,21 @@ fragment Arrow:
|
|||||||
;
|
;
|
||||||
|
|
||||||
Group:
|
Group:
|
||||||
'group' id=ARCH_ID icon=ARCH_ICON? title=ARCH_TITLE? ('in' in=ARCH_ID)? EOL
|
'group' id=ID icon=ARCH_ICON? title=ARCH_TITLE? ('in' in=ID)? EOL
|
||||||
;
|
;
|
||||||
|
|
||||||
Service:
|
Service:
|
||||||
'service' id=ARCH_ID (iconText=ARCH_TEXT_ICON | icon=ARCH_ICON)? title=ARCH_TITLE? ('in' in=ARCH_ID)? EOL
|
'service' id=ID (iconText=STRING | icon=ARCH_ICON)? title=ARCH_TITLE? ('in' in=ID)? EOL
|
||||||
;
|
;
|
||||||
|
|
||||||
Junction:
|
Junction:
|
||||||
'junction' id=ARCH_ID ('in' in=ARCH_ID)? EOL
|
'junction' id=ID ('in' in=ID)? EOL
|
||||||
;
|
;
|
||||||
|
|
||||||
Edge:
|
Edge:
|
||||||
lhsId=ARCH_ID lhsGroup?=ARROW_GROUP? Arrow rhsId=ARCH_ID rhsGroup?=ARROW_GROUP? EOL
|
lhsId=ID lhsGroup?=ARROW_GROUP? Arrow rhsId=ID rhsGroup?=ARROW_GROUP? EOL
|
||||||
;
|
;
|
||||||
|
|
||||||
terminal ARROW_DIRECTION: 'L' | 'R' | 'T' | 'B';
|
terminal ARROW_DIRECTION: 'L' | 'R' | 'T' | 'B';
|
||||||
terminal ARCH_ID: /[\w]+/;
|
|
||||||
terminal ARCH_TEXT_ICON: /\("[^"]+"\)/;
|
|
||||||
terminal ARCH_ICON: /\([\w-:]+\)/;
|
|
||||||
terminal ARCH_TITLE: /\[[\w ]+\]/;
|
|
||||||
terminal ARROW_GROUP: /\{group\}/;
|
terminal ARROW_GROUP: /\{group\}/;
|
||||||
terminal ARROW_INTO: /<|>/;
|
terminal ARROW_INTO: /<|>/;
|
||||||
|
@@ -1,22 +1,35 @@
|
|||||||
interface Common {
|
// Base terminals and fragments for common language constructs
|
||||||
accDescr?: string;
|
// Terminal Precedence: Lazy to Greedy
|
||||||
accTitle?: string;
|
// When imported, the terminals are considered after the terminals in the importing grammar
|
||||||
title?: string;
|
// Note: Hence, to add a terminal greedier than the common terminals, import the common grammar first
|
||||||
}
|
|
||||||
|
|
||||||
fragment TitleAndAccessibilities:
|
|
||||||
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
|
||||||
;
|
|
||||||
|
|
||||||
fragment EOL returns string:
|
fragment EOL returns string:
|
||||||
NEWLINE+ | EOF
|
NEWLINE+ | EOF
|
||||||
;
|
;
|
||||||
|
|
||||||
terminal NEWLINE: /\r?\n/;
|
fragment TitleAndAccessibilities:
|
||||||
|
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
||||||
|
;
|
||||||
|
|
||||||
|
terminal BOOLEAN returns boolean: 'true' | 'false';
|
||||||
|
|
||||||
terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/;
|
terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/;
|
||||||
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
|
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
|
||||||
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
|
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
|
||||||
|
|
||||||
|
terminal FLOAT returns number: /[0-9]+\.[0-9]+(?!\.)/;
|
||||||
|
terminal INT returns number: /0|[1-9][0-9]*(?!\.)/;
|
||||||
|
terminal NUMBER returns number: FLOAT | INT;
|
||||||
|
|
||||||
|
terminal STRING returns string: /"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/;
|
||||||
|
|
||||||
|
// Alphanumerics with underscores and dashes
|
||||||
|
// Must start with an alphanumeric or an underscore
|
||||||
|
// Cant end with a dash
|
||||||
|
terminal ID returns string: /[\w]([-\w]*\w)?/;
|
||||||
|
|
||||||
|
terminal NEWLINE: /\r?\n/;
|
||||||
|
|
||||||
hidden terminal WHITESPACE: /[\t ]+/;
|
hidden terminal WHITESPACE: /[\t ]+/;
|
||||||
hidden terminal YAML: /---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/;
|
hidden terminal YAML: /---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/;
|
||||||
hidden terminal DIRECTIVE: /[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/;
|
hidden terminal DIRECTIVE: /[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/;
|
||||||
|
@@ -1,39 +1,15 @@
|
|||||||
grammar GitGraph
|
grammar GitGraph
|
||||||
|
import "../common/common";
|
||||||
interface Common {
|
import "reference";
|
||||||
accDescr?: string;
|
|
||||||
accTitle?: string;
|
|
||||||
title?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment TitleAndAccessibilities:
|
|
||||||
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
|
||||||
;
|
|
||||||
|
|
||||||
fragment EOL returns string:
|
|
||||||
NEWLINE+ | EOF
|
|
||||||
;
|
|
||||||
|
|
||||||
terminal NEWLINE: /\r?\n/;
|
|
||||||
terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/;
|
|
||||||
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
|
|
||||||
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
|
|
||||||
|
|
||||||
hidden terminal WHITESPACE: /[\t ]+/;
|
|
||||||
hidden terminal YAML: /---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/;
|
|
||||||
hidden terminal DIRECTIVE: /[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/;
|
|
||||||
hidden terminal SINGLE_LINE_COMMENT: /[\t ]*%%[^\n\r]*/;
|
|
||||||
|
|
||||||
entry GitGraph:
|
entry GitGraph:
|
||||||
NEWLINE*
|
NEWLINE*
|
||||||
('gitGraph' | 'gitGraph' ':' | 'gitGraph:' | ('gitGraph' Direction ':'))
|
('gitGraph' | 'gitGraph' ':' | 'gitGraph:' | ('gitGraph' Direction ':'))
|
||||||
NEWLINE*
|
|
||||||
(
|
(
|
||||||
NEWLINE*
|
NEWLINE
|
||||||
(TitleAndAccessibilities |
|
| TitleAndAccessibilities
|
||||||
statements+=Statement |
|
| statements+=Statement
|
||||||
NEWLINE)*
|
)*
|
||||||
)
|
|
||||||
;
|
;
|
||||||
|
|
||||||
Statement
|
Statement
|
||||||
@@ -56,12 +32,12 @@ Commit:
|
|||||||
|'type:' type=('NORMAL' | 'REVERSE' | 'HIGHLIGHT')
|
|'type:' type=('NORMAL' | 'REVERSE' | 'HIGHLIGHT')
|
||||||
)* EOL;
|
)* EOL;
|
||||||
Branch:
|
Branch:
|
||||||
'branch' name=(ID|STRING)
|
'branch' name=(REFERENCE|STRING)
|
||||||
('order:' order=INT)?
|
('order:' order=INT)?
|
||||||
EOL;
|
EOL;
|
||||||
|
|
||||||
Merge:
|
Merge:
|
||||||
'merge' branch=(ID|STRING)
|
'merge' branch=(REFERENCE|STRING)
|
||||||
(
|
(
|
||||||
'id:' id=STRING
|
'id:' id=STRING
|
||||||
|'tag:' tags+=STRING
|
|'tag:' tags+=STRING
|
||||||
@@ -69,7 +45,7 @@ Merge:
|
|||||||
)* EOL;
|
)* EOL;
|
||||||
|
|
||||||
Checkout:
|
Checkout:
|
||||||
('checkout'|'switch') branch=(ID|STRING) EOL;
|
('checkout'|'switch') branch=(REFERENCE|STRING) EOL;
|
||||||
|
|
||||||
CherryPicking:
|
CherryPicking:
|
||||||
'cherry-pick'
|
'cherry-pick'
|
||||||
@@ -78,10 +54,3 @@ CherryPicking:
|
|||||||
|'tag:' tags+=STRING
|
|'tag:' tags+=STRING
|
||||||
|'parent:' parent=STRING
|
|'parent:' parent=STRING
|
||||||
)* EOL;
|
)* EOL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
terminal INT returns number: /[0-9]+(?=\s)/;
|
|
||||||
terminal ID returns string: /\w([-\./\w]*[-\w])?/;
|
|
||||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
|
||||||
|
|
||||||
|
4
packages/parser/src/language/gitGraph/reference.langium
Normal file
4
packages/parser/src/language/gitGraph/reference.langium
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// Alphanumerics with underscores, dashes, slashes, and dots
|
||||||
|
// Must start with an alphanumeric or an underscore
|
||||||
|
// Cant end with a dash, slash, or dot
|
||||||
|
terminal REFERENCE returns string: /\w([-\./\w]*[-\w])?/;
|
@@ -12,7 +12,6 @@ export {
|
|||||||
Commit,
|
Commit,
|
||||||
Merge,
|
Merge,
|
||||||
Statement,
|
Statement,
|
||||||
isCommon,
|
|
||||||
isInfo,
|
isInfo,
|
||||||
isPacket,
|
isPacket,
|
||||||
isPacketBlock,
|
isPacketBlock,
|
||||||
|
@@ -5,15 +5,12 @@ entry Packet:
|
|||||||
NEWLINE*
|
NEWLINE*
|
||||||
"packet-beta"
|
"packet-beta"
|
||||||
(
|
(
|
||||||
NEWLINE* TitleAndAccessibilities blocks+=PacketBlock*
|
TitleAndAccessibilities
|
||||||
| NEWLINE+ blocks+=PacketBlock+
|
| blocks+=PacketBlock
|
||||||
| NEWLINE*
|
| NEWLINE
|
||||||
)
|
)*
|
||||||
;
|
;
|
||||||
|
|
||||||
PacketBlock:
|
PacketBlock:
|
||||||
start=INT('-' end=INT)? ':' label=STRING EOL
|
start=INT('-' end=INT)? ':' label=STRING EOL
|
||||||
;
|
;
|
||||||
|
|
||||||
terminal INT returns number: /0|[1-9][0-9]*/;
|
|
||||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
|
@@ -5,15 +5,12 @@ entry Pie:
|
|||||||
NEWLINE*
|
NEWLINE*
|
||||||
"pie" showData?="showData"?
|
"pie" showData?="showData"?
|
||||||
(
|
(
|
||||||
NEWLINE* TitleAndAccessibilities sections+=PieSection*
|
TitleAndAccessibilities
|
||||||
| NEWLINE+ sections+=PieSection+
|
| sections+=PieSection
|
||||||
| NEWLINE*
|
| NEWLINE
|
||||||
)
|
)*
|
||||||
;
|
;
|
||||||
|
|
||||||
PieSection:
|
PieSection:
|
||||||
label=PIE_SECTION_LABEL ":" value=PIE_SECTION_VALUE EOL
|
label=STRING ":" value=NUMBER EOL
|
||||||
;
|
;
|
||||||
|
|
||||||
terminal PIE_SECTION_LABEL: /"[^"]+"/;
|
|
||||||
terminal PIE_SECTION_VALUE returns number: /(0|[1-9][0-9]*)(\.[0-9]+)?/;
|
|
||||||
|
@@ -1,31 +1,5 @@
|
|||||||
grammar Radar
|
grammar Radar
|
||||||
// import "../common/common";
|
import "../common/common";
|
||||||
// Note: The import statement breaks TitleAndAccessibilities probably because of terminal order definition
|
|
||||||
// TODO: May need to change the common.langium to fix this
|
|
||||||
|
|
||||||
interface Common {
|
|
||||||
accDescr?: string;
|
|
||||||
accTitle?: string;
|
|
||||||
title?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment TitleAndAccessibilities:
|
|
||||||
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
|
||||||
;
|
|
||||||
|
|
||||||
fragment EOL returns string:
|
|
||||||
NEWLINE+ | EOF
|
|
||||||
;
|
|
||||||
|
|
||||||
terminal NEWLINE: /\r?\n/;
|
|
||||||
terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/;
|
|
||||||
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
|
|
||||||
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
|
|
||||||
|
|
||||||
hidden terminal WHITESPACE: /[\t ]+/;
|
|
||||||
hidden terminal YAML: /---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/;
|
|
||||||
hidden terminal DIRECTIVE: /[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/;
|
|
||||||
hidden terminal SINGLE_LINE_COMMENT: /[\t ]*%%[^\n\r]*/;
|
|
||||||
|
|
||||||
entry Radar:
|
entry Radar:
|
||||||
NEWLINE*
|
NEWLINE*
|
||||||
@@ -76,14 +50,6 @@ Option:
|
|||||||
| name='min' value=NUMBER
|
| name='min' value=NUMBER
|
||||||
| name='graticule' value=GRATICULE
|
| name='graticule' value=GRATICULE
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
terminal GRATICULE returns string: 'circle' | 'polygon';
|
||||||
terminal NUMBER returns number: /(0|[1-9][0-9]*)(\.[0-9]+)?/;
|
|
||||||
|
|
||||||
terminal BOOLEAN returns boolean: 'true' | 'false';
|
|
||||||
|
|
||||||
terminal GRATICULE returns string: 'circle' | 'polygon';
|
|
||||||
|
|
||||||
terminal ID returns string: /[a-zA-Z_][a-zA-Z0-9\-_]*/;
|
|
||||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
|
Reference in New Issue
Block a user