mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-15 13:29:40 +02:00
1378-accept multiple parameters with methods
sec
This commit is contained in:
@@ -59,6 +59,7 @@
|
|||||||
"he": "^1.2.0",
|
"he": "^1.2.0",
|
||||||
"minify": "^4.1.1",
|
"minify": "^4.1.1",
|
||||||
"moment-mini": "^2.22.1",
|
"moment-mini": "^2.22.1",
|
||||||
|
"node": "^14.3.0",
|
||||||
"scope-css": "^1.2.1"
|
"scope-css": "^1.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@@ -10,15 +10,15 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
\%\%[^\n]*\n* /* do nothing */
|
\%\%[^\n]*\n* /* do nothing */
|
||||||
\n+ return 'NEWLINE';
|
\n+ return 'NEWLINE';
|
||||||
\s+ /* skip whitespace */
|
\s+ /* skip whitespace */
|
||||||
"classDiagram" return 'CLASS_DIAGRAM';
|
"classDiagram" return 'CLASS_DIAGRAM';
|
||||||
[\{] { this.begin("struct"); /*console.log('Starting struct');*/return 'STRUCT_START';}
|
[\{] { this.begin("struct"); /*console.log('Starting struct');*/return 'STRUCT_START';}
|
||||||
<struct><<EOF>> return "EOF_IN_STRUCT";
|
<struct><<EOF>> return "EOF_IN_STRUCT";
|
||||||
<struct>[\{] return "OPEN_IN_STRUCT";
|
<struct>[\{] return "OPEN_IN_STRUCT";
|
||||||
<struct>\} { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}}
|
<struct>\} { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}}
|
||||||
<struct>[\n] /* nothing */
|
<struct>[\n] /* nothing */
|
||||||
<struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
<struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
\s*\|\> return 'EXTENSION';
|
\s*\|\> return 'EXTENSION';
|
||||||
\s*\> return 'DEPENDENCY';
|
\s*\> return 'DEPENDENCY';
|
||||||
\s*\< return 'DEPENDENCY';
|
\s*\< return 'DEPENDENCY';
|
||||||
\s*\* return 'COMPOSITION';
|
\s*\* return 'COMPOSITION';
|
||||||
\s*o return 'AGGREGATION';
|
\s*o return 'AGGREGATION';
|
||||||
\-\- return 'LINE';
|
\-\- return 'LINE';
|
||||||
\.\. return 'DOTTED_LINE';
|
\.\. return 'DOTTED_LINE';
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
\= return 'EQUALS';
|
\= return 'EQUALS';
|
||||||
\w+ return 'ALPHA';
|
\w+ return 'ALPHA';
|
||||||
[!"#$%&'*+,-.`?\\/] return 'PUNCTUATION';
|
[!"#$%&'*+,-.`?\\/] return 'PUNCTUATION';
|
||||||
[0-9]+ return 'NUM';
|
[0-9]+ return 'NUM';
|
||||||
[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|
|
[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|
|
||||||
[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|
|
[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|
|
||||||
[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|
|
[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|
|
||||||
|
@@ -278,8 +278,8 @@ export const drawClass = function(elem, classDef, conf) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const parseMember = function(text) {
|
export const parseMember = function(text) {
|
||||||
const fieldRegEx = /^(\+|-|~|#)?(\w+)(~\w+~|\[\])?\s+(\w+)$/;
|
const fieldRegEx = /^(\+|-|~|#)?(\w+)(~\w+~|\[\])?\s+(\w+)/;
|
||||||
const methodRegEx = /^(\+|-|~|#)?(\w+)\s?\(\s*(\w+(~\w+~|\[\])?\s*(\w+)?)?\s*\)\s?([*|$])?\s?(\w+(~\w+~|\[\])?)?\s*$/;
|
const methodRegEx = /^(\+|-|~|#)?(\w+)\((.*)\)(\*|\$)?\s?(.*)?/;
|
||||||
|
|
||||||
let fieldMatch = text.match(fieldRegEx);
|
let fieldMatch = text.match(fieldRegEx);
|
||||||
let methodMatch = text.match(methodRegEx);
|
let methodMatch = text.match(methodRegEx);
|
||||||
@@ -294,43 +294,53 @@ export const parseMember = function(text) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buildFieldDisplay = function(parsedText) {
|
const buildFieldDisplay = function(parsedText) {
|
||||||
let visibility = parsedText[1] ? parsedText[1].trim() : '';
|
let displayText = '';
|
||||||
let fieldType = parsedText[2] ? parsedText[2].trim() : '';
|
|
||||||
let genericType = parsedText[3] ? parseGenericTypes(parsedText[3]) : '';
|
try {
|
||||||
let fieldName = parsedText[4] ? parsedText[4].trim() : '';
|
let visibility = parsedText[1] ? parsedText[1].trim() : '';
|
||||||
|
let fieldType = parsedText[2] ? parseGenericTypes(parsedText[2]) : '';
|
||||||
|
let fieldName = parsedText[3] ? parsedText[3].trim() : '';
|
||||||
|
|
||||||
|
displayText = visibility + fieldType + ' ' + fieldName;
|
||||||
|
} catch (err) {
|
||||||
|
displayText = parsedText;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
displayText: visibility + fieldType + genericType + ' ' + fieldName,
|
displayText: displayText,
|
||||||
cssStyle: ''
|
cssStyle: ''
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildMethodDisplay = function(parsedText) {
|
const buildMethodDisplay = function(parsedText) {
|
||||||
let cssStyle = '';
|
let cssStyle = '';
|
||||||
let displayText = parsedText;
|
let displayText = '';
|
||||||
|
|
||||||
let visibility = parsedText[1] ? parsedText[1].trim() : '';
|
try {
|
||||||
let methodName = parsedText[2] ? parsedText[2].trim() : '';
|
let visibility = parsedText[1] ? parsedText[1].trim() : '';
|
||||||
let parameters = parsedText[3] ? parseGenericTypes(parsedText[3]) : '';
|
let methodName = parsedText[2] ? parsedText[2].trim() : '';
|
||||||
let classifier = parsedText[6] ? parsedText[6].trim() : '';
|
let parameters = parsedText[3] ? parseGenericTypes(parsedText[3]) : '';
|
||||||
let returnType = parsedText[7] ? ' : ' + parseGenericTypes(parsedText[7]).trim() : '';
|
let classifier = parsedText[4] ? parsedText[4].trim() : '';
|
||||||
|
let returnType = parsedText[5] ? ' : ' + parseGenericTypes(parsedText[5]).trim() : '';
|
||||||
|
|
||||||
displayText = visibility + methodName + '(' + parameters + ')' + returnType;
|
displayText = visibility + methodName + '(' + parameters + ')' + returnType;
|
||||||
|
|
||||||
cssStyle = parseClassifier(classifier);
|
cssStyle = parseClassifier(classifier);
|
||||||
|
} catch (err) {
|
||||||
|
displayText = parsedText;
|
||||||
|
}
|
||||||
|
|
||||||
let member = {
|
return {
|
||||||
displayText: displayText,
|
displayText: displayText,
|
||||||
cssStyle: cssStyle
|
cssStyle: cssStyle
|
||||||
};
|
};
|
||||||
|
|
||||||
return member;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildLegacyDisplay = function(text) {
|
const buildLegacyDisplay = function(text) {
|
||||||
// if for some reason we dont have any match, use old format to parse text
|
// if for some reason we dont have any match, use old format to parse text
|
||||||
let memberText = '';
|
let displayText = '';
|
||||||
let cssStyle = '';
|
let cssStyle = '';
|
||||||
|
let memberText = '';
|
||||||
let returnType = '';
|
let returnType = '';
|
||||||
let methodStart = text.indexOf('(');
|
let methodStart = text.indexOf('(');
|
||||||
let methodEnd = text.indexOf(')');
|
let methodEnd = text.indexOf(')');
|
||||||
@@ -338,12 +348,12 @@ const buildLegacyDisplay = function(text) {
|
|||||||
if (methodStart > 1 && methodEnd > methodStart && methodEnd <= text.length) {
|
if (methodStart > 1 && methodEnd > methodStart && methodEnd <= text.length) {
|
||||||
let parsedText = text.match(/(\+|-|~|#)?(\w+)/);
|
let parsedText = text.match(/(\+|-|~|#)?(\w+)/);
|
||||||
let visibility = parsedText[1] ? parsedText[1].trim() : '';
|
let visibility = parsedText[1] ? parsedText[1].trim() : '';
|
||||||
let methodName = parsedText[2];
|
let methodName = text.substring(0, methodStart);
|
||||||
let parameters = text.substring(methodStart + 1, methodEnd);
|
let parameters = text.substring(methodStart + 1, methodEnd);
|
||||||
let classifier = text.substring(methodEnd, methodEnd + 1);
|
let classifier = text.substring(methodEnd, methodEnd + 1);
|
||||||
cssStyle = parseClassifier(classifier);
|
cssStyle = parseClassifier(classifier);
|
||||||
|
|
||||||
memberText = visibility + methodName + '(' + parseGenericTypes(parameters.trim()) + ')';
|
displayText = visibility + methodName + '(' + parseGenericTypes(parameters.trim()) + ')';
|
||||||
|
|
||||||
if (methodEnd < memberText.length) {
|
if (methodEnd < memberText.length) {
|
||||||
returnType = text.substring(methodEnd + 2).trim();
|
returnType = text.substring(methodEnd + 2).trim();
|
||||||
@@ -353,15 +363,13 @@ const buildLegacyDisplay = function(text) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// finally - if all else fails, just send the text back as written (other than parsing for generic types)
|
// finally - if all else fails, just send the text back as written (other than parsing for generic types)
|
||||||
memberText = parseGenericTypes(text);
|
displayText = parseGenericTypes(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
let member = {
|
return {
|
||||||
displayText: memberText + returnType,
|
displayText: displayText,
|
||||||
cssStyle: cssStyle
|
cssStyle: cssStyle
|
||||||
};
|
};
|
||||||
|
|
||||||
return member;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const addTspan = function(textEl, txt, isFirst, conf) {
|
const addTspan = function(textEl, txt, isFirst, conf) {
|
||||||
|
12
yarn.lock
12
yarn.lock
@@ -7548,6 +7548,11 @@ no-case@^2.2.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
lower-case "^1.1.1"
|
lower-case "^1.1.1"
|
||||||
|
|
||||||
|
node-bin-setup@^1.0.0:
|
||||||
|
version "1.0.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/node-bin-setup/-/node-bin-setup-1.0.6.tgz#4b5c9bb937ece702d7069b36ca78af4684677528"
|
||||||
|
integrity sha512-uPIxXNis1CRbv1DwqAxkgBk5NFV3s7cMN/Gf556jSw6jBvV7ca4F9lRL/8cALcZecRibeqU+5dFYqFFmzv5a0Q==
|
||||||
|
|
||||||
node-forge@0.9.0:
|
node-forge@0.9.0:
|
||||||
version "0.9.0"
|
version "0.9.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579"
|
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579"
|
||||||
@@ -7651,6 +7656,13 @@ node-sass@^4.12.0:
|
|||||||
stdout-stream "^1.4.0"
|
stdout-stream "^1.4.0"
|
||||||
"true-case-path" "^1.0.2"
|
"true-case-path" "^1.0.2"
|
||||||
|
|
||||||
|
node@^14.3.0:
|
||||||
|
version "14.3.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/node/-/node-14.3.0.tgz#a0aa79f74add23cf84a2d3ac9d631bbed3ca496a"
|
||||||
|
integrity sha512-wYdyAhpzQ+iaXnDby6JUok/efke+TW2VJk8lOFc4B6F1omIiBG6gt/xVG074btcliY9Sw49D2veah8bZ20lGEA==
|
||||||
|
dependencies:
|
||||||
|
node-bin-setup "^1.0.0"
|
||||||
|
|
||||||
nomnom@1.5.2:
|
nomnom@1.5.2:
|
||||||
version "1.5.2"
|
version "1.5.2"
|
||||||
resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.5.2.tgz#f4345448a853cfbd5c0d26320f2477ab0526fe2f"
|
resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.5.2.tgz#f4345448a853cfbd5c0d26320f2477ab0526fe2f"
|
||||||
|
Reference in New Issue
Block a user