From e7ca6c16ffcd716088b6450ae886f2a28bad3e7d Mon Sep 17 00:00:00 2001 From: chris moran Date: Mon, 27 Jul 2020 14:15:38 -0400 Subject: [PATCH] Tweaked PIE (got rid of some parsing conflicts) --- docs/Setup.md | 2 +- src/diagrams/pie/parser/pie.jison | 24 +++++++++++------------- src/diagrams/pie/parser/pie.spec.js | 9 +++++++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/docs/Setup.md b/docs/Setup.md index 962bc4ec3..65df501ab 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -526,7 +526,7 @@ This might need adjustment to match your locale and preferences ## journey -The object containing configurations specific for sequence diagrams +The object containing configurations specific for journey diagrams ### diagramMarginX diff --git a/src/diagrams/pie/parser/pie.jison b/src/diagrams/pie/parser/pie.jison index 344c3dd4c..67de2c562 100644 --- a/src/diagrams/pie/parser/pie.jison +++ b/src/diagrams/pie/parser/pie.jison @@ -24,8 +24,8 @@ [\n\r]+ return 'NEWLINE'; \%\%[^\n]* /* do nothing */ [\s]+ /* ignore */ -title { console.log('starting title');this.begin("title");return 'title'; } -([^(?:\n#;)]*) { this.popState(); return "title_value"; } +title { this.begin("title");return 'title'; } +<title>(?!\n|;|#)*[^\n]* { this.popState(); return "title_value"; } ["] { this.begin("string"); } <string>["] { this.popState(); } <string>[^"]* { return "txt"; } @@ -41,9 +41,9 @@ title { console.log('s %% /* language grammar */ start - : eol start { console.warn('NEWLINE start'); } - | directive start { console.warn('directive start'); } - | PIE document EOF { console.warn('PIE document EOF'); } + : eol start + | directive start + | PIE document ; document @@ -52,14 +52,13 @@ document ; line - : statement { $$ = $1 } - | eol { $$=[]; } + : statement eol { $$ = $1 } ; statement : - | txt value { yy.addSection($1,yy.cleanupValue($2)); } - | title title_value { $$=$2.trim();yy.setTitle($$); } + | txt value { yy.addSection($1,yy.cleanupValue($2)); } + | title title_value { $$=$2.trim();yy.setTitle($$); } | directive ; @@ -69,10 +68,9 @@ directive ; eol - : - | SPACE eol - | NEWLINE eol - | ';' eol + : NEWLINE + | ';' + | EOF ; openDirective diff --git a/src/diagrams/pie/parser/pie.spec.js b/src/diagrams/pie/parser/pie.spec.js index 98f01d67e..3d94fea44 100644 --- a/src/diagrams/pie/parser/pie.spec.js +++ b/src/diagrams/pie/parser/pie.spec.js @@ -12,6 +12,15 @@ describe('when parsing pie', function() { pie.parser.yy = pieDb; pie.parser.yy.clear(); }); + it('should handle very simple pie', function() { + const res = pie.parser.parse(`pie +"ash" : 100 +`); + const sections = pieDb.getSections(); + console.log('sections: ', sections); + const section1 = sections['ash']; + expect(section1).toBe(100); + }); it('should handle simple pie', function() { const res = pie.parser.parse(`pie "ash" : 60