From b9fa2f412508efe2d00061f52840bca0e5ded74b Mon Sep 17 00:00:00 2001 From: chris moran Date: Mon, 27 Jul 2020 10:16:41 -0400 Subject: [PATCH] Added directive parsing to gannt Ensured tests pass --- src/diagrams/gantt/ganttDb.js | 6 ++++ src/diagrams/gantt/parser/gantt.jison | 41 +++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index b13f02e07..a565a8789 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -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, diff --git a/src/diagrams/gantt/parser/gantt.jison b/src/diagrams/gantt/parser/gantt.jison index 4a0a0e889..f7fcd0879 100644 --- a/src/diagrams/gantt/parser/gantt.jison +++ b/src/diagrams/gantt/parser/gantt.jison @@ -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'; } +((?:(?!\}\%\%)[^:.])*) { this.begin('type_directive'); return 'type_directive'; } +":" { this.popState(); this.begin('arg_directive'); return ':'; } +\}\%\% { this.popState(); this.popState(); return 'close_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'); } + ; + +%%