mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Add class name literals.
This commit is contained in:
parent
15e412bd4e
commit
b974b3df3e
@ -8,6 +8,14 @@ describe('class diagram, ', function () {
|
|||||||
parser.yy = classDb;
|
parser.yy = classDb;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle backquoted class names', function() {
|
||||||
|
const str =
|
||||||
|
'classDiagram\n' +
|
||||||
|
'class `Car`';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle relation definitions', function () {
|
it('should handle relation definitions', function () {
|
||||||
const str =
|
const str =
|
||||||
'classDiagram\n' +
|
'classDiagram\n' +
|
||||||
@ -20,6 +28,18 @@ describe('class diagram, ', function () {
|
|||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle backquoted relation definitions', function () {
|
||||||
|
const str =
|
||||||
|
'classDiagram\n' +
|
||||||
|
'`Class01` <|-- Class02\n' +
|
||||||
|
'Class03 *-- Class04\n' +
|
||||||
|
'Class05 o-- Class06\n' +
|
||||||
|
'Class07 .. Class08\n' +
|
||||||
|
'Class09 -- Class1';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle relation definition of different types and directions', function () {
|
it('should handle relation definition of different types and directions', function () {
|
||||||
const str =
|
const str =
|
||||||
'classDiagram\n' +
|
'classDiagram\n' +
|
||||||
@ -67,6 +87,17 @@ describe('class diagram, ', function () {
|
|||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle generic class with a literal name', function() {
|
||||||
|
const str =
|
||||||
|
'classDiagram\n' +
|
||||||
|
'class `Car`~T~\n' +
|
||||||
|
'Driver -- `Car` : drives >\n' +
|
||||||
|
'`Car` *-- Wheel : have 4 >\n' +
|
||||||
|
'`Car` -- Person : < owns';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
});
|
||||||
|
|
||||||
it('should break when another `{`is encountered before closing the first one while defining generic class with brackets', function() {
|
it('should break when another `{`is encountered before closing the first one while defining generic class with brackets', function() {
|
||||||
const str =
|
const str =
|
||||||
'classDiagram\n' +
|
'classDiagram\n' +
|
||||||
@ -125,6 +156,22 @@ describe('class diagram, ', function () {
|
|||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle generic class with brackets and a literal name', function() {
|
||||||
|
const str =
|
||||||
|
'classDiagram\n' +
|
||||||
|
'class `Dummy_Class`~T~ {\n' +
|
||||||
|
'String data\n' +
|
||||||
|
' void methods()\n' +
|
||||||
|
'}\n' +
|
||||||
|
'\n' +
|
||||||
|
'class Flight {\n' +
|
||||||
|
' flightNumber : Integer\n' +
|
||||||
|
' departureTime : Date\n' +
|
||||||
|
'}';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle class definitions', function() {
|
it('should handle class definitions', function() {
|
||||||
const str =
|
const str =
|
||||||
'classDiagram\n' +
|
'classDiagram\n' +
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
/* lexical grammar */
|
/* lexical grammar */
|
||||||
%lex
|
%lex
|
||||||
%x string
|
%x string
|
||||||
|
%x bqstring
|
||||||
%x generic
|
%x generic
|
||||||
%x struct
|
%x struct
|
||||||
%x href
|
%x href
|
||||||
@ -49,6 +50,10 @@
|
|||||||
<string>["] this.popState();
|
<string>["] this.popState();
|
||||||
<string>[^"]* return "STR";
|
<string>[^"]* return "STR";
|
||||||
|
|
||||||
|
[`] this.begin("bqstring");
|
||||||
|
<bqstring>[`] this.popState();
|
||||||
|
<bqstring>[^`]+ return "BQUOTE_STR";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
---interactivity command---
|
---interactivity command---
|
||||||
'href' adds a link to the specified node. 'href' can only be specified when the
|
'href' adds a link to the specified node. 'href' can only be specified when the
|
||||||
@ -214,10 +219,15 @@ statements
|
|||||||
;
|
;
|
||||||
|
|
||||||
className
|
className
|
||||||
: alphaNumToken { $$=$1; }
|
:
|
||||||
|
| alphaNumToken { $$=$1; }
|
||||||
|
| classLiteralName { $$=$1; }
|
||||||
| alphaNumToken className { $$=$1+$2; }
|
| alphaNumToken className { $$=$1+$2; }
|
||||||
|
| classLiteralName className { $$=$1+$2; }
|
||||||
| alphaNumToken GENERICTYPE className { $$=$1+'~'+$2+$3; }
|
| alphaNumToken GENERICTYPE className { $$=$1+'~'+$2+$3; }
|
||||||
|
| classLiteralName GENERICTYPE className { $$=$1+'~'+$2+$3; }
|
||||||
| alphaNumToken GENERICTYPE { $$=$1+'~'+$2; }
|
| alphaNumToken GENERICTYPE { $$=$1+'~'+$2; }
|
||||||
|
| classLiteralName GENERICTYPE { $$=$1+'~'+$2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
statement
|
statement
|
||||||
@ -309,4 +319,6 @@ textNoTagsToken: alphaNumToken | SPACE | MINUS | keywords ;
|
|||||||
|
|
||||||
alphaNumToken : UNICODE_TEXT | NUM | ALPHA;
|
alphaNumToken : UNICODE_TEXT | NUM | ALPHA;
|
||||||
|
|
||||||
|
classLiteralName : BQUOTE_STR;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
Loading…
x
Reference in New Issue
Block a user