mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Added directive parsing to gannt
Ensured tests pass
This commit is contained in:
parent
e5b22684cd
commit
b9fa2f4125
@ -3,6 +3,7 @@ import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||
import { logger } from '../../logger';
|
||||
import { getConfig } from '../../config';
|
||||
import utils from '../../utils';
|
||||
import mermaidAPI from '../../mermaidAPI';
|
||||
|
||||
let dateFormat = '';
|
||||
let axisFormat = '';
|
||||
@ -19,6 +20,10 @@ let inclusiveEndDates = false;
|
||||
// The serial order of the task in the script
|
||||
let lastOrder = 0;
|
||||
|
||||
export const parseDirective = function(statement, context, type) {
|
||||
mermaidAPI.parseDirective(this, statement, context, type);
|
||||
};
|
||||
|
||||
export const clear = function() {
|
||||
sections = [];
|
||||
tasks = [];
|
||||
@ -582,6 +587,7 @@ export const bindFunctions = function(element) {
|
||||
};
|
||||
|
||||
export default {
|
||||
parseDirective,
|
||||
clear,
|
||||
setDateFormat,
|
||||
getDateFormat,
|
||||
|
@ -11,7 +11,19 @@
|
||||
%x href
|
||||
%x callbackname
|
||||
%x callbackargs
|
||||
%x open_directive
|
||||
%x type_directive
|
||||
%x arg_directive
|
||||
%x close_directive
|
||||
%%
|
||||
\%\%\{ { this.begin('open_directive'); return 'open_directive'; }
|
||||
<open_directive>((?:(?!\}\%\%)[^:.])*) { this.begin('type_directive'); return 'type_directive'; }
|
||||
<type_directive>":" { this.popState(); this.begin('arg_directive'); return ':'; }
|
||||
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
||||
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
||||
\%\%(?!\{)*[^\n]* /* skip comments */
|
||||
[^\}]\%\%*[^\n]* /* skip comments */
|
||||
\%\%*[^\n]*[\n]* /* do nothing */
|
||||
|
||||
[\n]+ return 'NL';
|
||||
\s+ /* skip whitespace */
|
||||
@ -77,7 +89,8 @@ that id.
|
||||
%% /* language grammar */
|
||||
|
||||
start
|
||||
: gantt document 'EOF' { return $2; }
|
||||
: directive start
|
||||
| gantt document 'EOF' { return $2; }
|
||||
;
|
||||
|
||||
document
|
||||
@ -102,8 +115,14 @@ statement
|
||||
| section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
||||
| clickStatement
|
||||
| taskTxt taskData {yy.addTask($1,$2);$$='task';}
|
||||
| directive
|
||||
;
|
||||
|
||||
directive
|
||||
: openDirective typeDirective closeDirective 'NL'
|
||||
| openDirective typeDirective ':' argDirective closeDirective 'NL'
|
||||
;
|
||||
|
||||
/*
|
||||
click allows any combination of href and call.
|
||||
*/
|
||||
@ -131,4 +150,22 @@ clickStatementDebug
|
||||
| click href callbackname callbackargs {$$=$1 + ' ' + $2 + ' ' + $3 + ' ' + $4;}
|
||||
|
||||
| click href {$$=$1 + ' ' + $2;}
|
||||
;%%
|
||||
;
|
||||
|
||||
openDirective
|
||||
: open_directive { yy.parseDirective('%%{', 'open_directive'); }
|
||||
;
|
||||
|
||||
typeDirective
|
||||
: type_directive { yy.parseDirective($1, 'type_directive'); }
|
||||
;
|
||||
|
||||
argDirective
|
||||
: arg_directive { $1 = $1.trim().replace(/'/g, '"'); yy.parseDirective($1, 'arg_directive'); }
|
||||
;
|
||||
|
||||
closeDirective
|
||||
: close_directive { yy.parseDirective('}%%', 'close_directive', 'sequence'); }
|
||||
;
|
||||
|
||||
%%
|
||||
|
Loading…
x
Reference in New Issue
Block a user