From 0dca4d3393fcbea357522e037f00cee2ea186c0d Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Thu, 1 Sep 2022 17:20:36 +0100 Subject: [PATCH 1/3] fix(git): support numeric branch names gitGraph does not support branch names that start with a number, because the gitGraph.jison file parses these as NUM (number) instead. To fix this, I've changed the NUM parser to only accept strings that end with whitespace (e.g 1234 is a NUM, but 1234abc is not a NUM). To do this, I had to move the "skip all whitespace" step to the end of the parser, but this doesn't seem to have caused any issues, so it's probably fine. --- src/diagrams/git/gitGraphParserV2.spec.js | 15 +++++++++++++++ src/diagrams/git/parser/gitGraph.jison | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/diagrams/git/gitGraphParserV2.spec.js b/src/diagrams/git/gitGraphParserV2.spec.js index 9a5cc59f1..9a33e288f 100644 --- a/src/diagrams/git/gitGraphParserV2.spec.js +++ b/src/diagrams/git/gitGraphParserV2.spec.js @@ -348,6 +348,21 @@ describe('when parsing a gitGraph', function () { expect(Object.keys(parser.yy.getBranches()).length).toBe(2); }); + it('should allow branch names starting with numbers', function () { + const str = `gitGraph: + commit + %% branch names starting with numbers are not recommended, but are supported by git + branch 1.0.1 + `; + + parser.parse(str); + const commits = parser.yy.getCommits(); + expect(Object.keys(commits).length).toBe(1); + expect(parser.yy.getCurrentBranch()).toBe('1.0.1'); + expect(parser.yy.getDirection()).toBe('LR'); + expect(Object.keys(parser.yy.getBranches()).length).toBe(2); + }); + it('should handle new branch checkout', function () { const str = `gitGraph: commit diff --git a/src/diagrams/git/parser/gitGraph.jison b/src/diagrams/git/parser/gitGraph.jison index 937a7192a..29edec808 100644 --- a/src/diagrams/git/parser/gitGraph.jison +++ b/src/diagrams/git/parser/gitGraph.jison @@ -33,7 +33,6 @@ accDescr\s*"{"\s* { this.begin("ac [\}] { this.popState(); } [^\}]* return "acc_descr_multiline_value"; (\r?\n)+ /*{console.log('New line');return 'NL';}*/ return 'NL'; -\s+ /* skip all whitespace */ \#[^\n]* /* skip comments */ \%%[^\n]* /* skip comments */ "gitGraph" return 'GG'; @@ -61,9 +60,10 @@ accDescr\s*"{"\s* { this.begin("ac ["] this.begin("string"); ["] this.popState(); [^"]* return 'STR'; -[0-9]+ return 'NUM'; -[a-zA-Z][-_\./a-zA-Z0-9]*[-_a-zA-Z0-9] return 'ID'; +[0-9]+(?=\s|$) return 'NUM'; +\w[-\./\w]*[-\w] return 'ID'; // only a subset of https://git-scm.com/docs/git-check-ref-format <> return 'EOF'; +\s+ /* skip all whitespace */ // lowest priority so we can use lookaheads in earlier regex /lex From 91363f7aed049f550866d91bf9c1852bca6e9bb1 Mon Sep 17 00:00:00 2001 From: "Ashley Engelund (weedySeaDragon @ github)" Date: Mon, 5 Sep 2022 19:45:33 -0700 Subject: [PATCH 2/3] fix JSDOC @param, @returns; fixed a few minor typos in comments --- src/assignWithDepth.js | 9 --------- src/dagre-wrapper/mermaid-graphlib.js | 6 +++--- src/diagrams/c4/c4Renderer.js | 5 ++--- src/diagrams/class/classRenderer.js | 3 +-- src/diagrams/er/erRenderer.js | 5 ++--- src/diagrams/flowchart/flowRenderer.js | 1 - src/diagrams/git/gitGraphRenderer.js | 16 +++++----------- src/diagrams/mindmap/mindmapRenderer.js | 4 ---- src/diagrams/sequence/sequenceRenderer.js | 5 ++--- src/diagrams/state/shapes.js | 4 ++-- src/setupGraphViewbox.js | 2 -- 11 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/assignWithDepth.js b/src/assignWithDepth.js index a74c47945..9f44b01ee 100644 --- a/src/assignWithDepth.js +++ b/src/assignWithDepth.js @@ -17,15 +17,6 @@ * Traditional Object.assign would have clobbered foo in config_0 with foo in config_1. If src is a * destructured array of objects and dst is not an array, assignWithDepth will apply each element * of src to dst in order. - * @param dst - * @param src - * @param config - * @param dst - * @param src - * @param config - * @param dst - * @param src - * @param config * @param {any} dst - The destination of the merge * @param {any} src - The source object(s) to merge into destination * @param {{ depth: number; clobber: boolean }} [config={ depth: 2, clobber: false }] - Depth: depth diff --git a/src/dagre-wrapper/mermaid-graphlib.js b/src/dagre-wrapper/mermaid-graphlib.js index aa7414ff7..fd9e40925 100644 --- a/src/dagre-wrapper/mermaid-graphlib.js +++ b/src/dagre-wrapper/mermaid-graphlib.js @@ -163,9 +163,9 @@ export const validate = (graph) => { }; /** - * Finds a child that is not a cluster. When faking a edge between a node and a cluster. + * Finds a child that is not a cluster. When faking an edge between a node and a cluster. * - * @param {Finds a} id + * @param id * @param {any} graph */ export const findNonClusterChild = (id, graph) => { @@ -235,7 +235,7 @@ export const adjustClustersAndEdges = (graph, depth) => { edges.forEach((edge) => { // log.debug('Edge, decendants: ', edge, decendants[id]); - // Check if any edge leaves the cluster (not the actual cluster, thats a link from the box) + // Check if any edge leaves the cluster (not the actual cluster, that's a link from the box) if (edge.v !== id && edge.w !== id) { // Any edge where either the one of the nodes is decending to the cluster but not the other // if (decendants[id].indexOf(edge.v) < 0 && decendants[id].indexOf(edge.w) < 0) { diff --git a/src/diagrams/c4/c4Renderer.js b/src/diagrams/c4/c4Renderer.js index 5ecc8aea2..137b89b89 100644 --- a/src/diagrams/c4/c4Renderer.js +++ b/src/diagrams/c4/c4Renderer.js @@ -568,10 +568,9 @@ function drawInsideBoundary(diagram, parentBoundaryAlias, parentBounds, currentB /** * Draws a sequenceDiagram in the tag with id: id based on the graph definition in text. * - * @param {any} text - * @param _text + * @param {any} _text * @param {any} id - * @param _version + * @param {any} _version * @param diagObj */ export const draw = function (_text, id, _version, diagObj) { diff --git a/src/diagrams/class/classRenderer.js b/src/diagrams/class/classRenderer.js index 9e9859fd6..6536cb5a1 100644 --- a/src/diagrams/class/classRenderer.js +++ b/src/diagrams/class/classRenderer.js @@ -142,8 +142,7 @@ const insertMarkers = function (elem) { * * @param {string} text * @param {string} id - * @param version - * @param _version + * @param {any} _version * @param diagObj */ export const draw = function (text, id, _version, diagObj) { diff --git a/src/diagrams/er/erRenderer.js b/src/diagrams/er/erRenderer.js index a7601f03f..d1258a547 100644 --- a/src/diagrams/er/erRenderer.js +++ b/src/diagrams/er/erRenderer.js @@ -32,7 +32,7 @@ export const setConf = function (cnf) { * @param groupNode The svg group node for the entity * @param entityTextNode The svg node for the entity label text * @param attributes An array of attributes defined for the entity (each attribute has a type and a name) - * @returns The bounding box of the entity, after attributes have been added + * @returns {object} The bounding box of the entity, after attributes have been added. The bounding box has a .width and .height */ const drawAttributes = (groupNode, entityTextNode, attributes) => { const heightPadding = conf.entityPadding / 3; // Padding internal to attribute boxes @@ -307,7 +307,7 @@ const drawAttributes = (groupNode, entityTextNode, attributes) => { * @param svgNode The svg node that contains the diagram * @param entities The entities to be drawn * @param graph The graph that contains the vertex and edge definitions post-layout - * @returns The first entity that was inserted + * @returns {object} The first entity that was inserted */ const drawEntities = function (svgNode, entities, graph) { const keys = Object.keys(entities); @@ -545,7 +545,6 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) { * @param text The text of the diagram * @param id The unique id of the DOM node that contains the diagram * @param _version - * @param diag * @param diagObj */ export const draw = function (text, id, _version, diagObj) { diff --git a/src/diagrams/flowchart/flowRenderer.js b/src/diagrams/flowchart/flowRenderer.js index f715019d8..5b14330dd 100644 --- a/src/diagrams/flowchart/flowRenderer.js +++ b/src/diagrams/flowchart/flowRenderer.js @@ -25,7 +25,6 @@ export const setConf = function (cnf) { * @param g The graph that is to be drawn. * @param svgId * @param root - * @param doc * @param _doc * @param diagObj */ diff --git a/src/diagrams/git/gitGraphRenderer.js b/src/diagrams/git/gitGraphRenderer.js index 97f8be5d5..5a9036b88 100644 --- a/src/diagrams/git/gitGraphRenderer.js +++ b/src/diagrams/git/gitGraphRenderer.js @@ -290,13 +290,13 @@ const drawCommits = (svg, commits, modifyGraph) => { }; /** - * Detect if there are other commits between commit1s x-position and commit2s x-position on the same + * Detect if there are other commits between commit1's x-position and commit2's x-position on the same * branch as commit2. * * @param {any} commit1 * @param {any} commit2 * @param allCommits - * @returns + * @returns {boolean} if there are commits between commit1's x-position and commit2's x-position */ const hasOverlappingCommits = (commit1, commit2, allCommits) => { const commit1Pos = commitPos[commit2.id]; @@ -322,7 +322,7 @@ const hasOverlappingCommits = (commit1, commit2, allCommits) => { * @param {any} y1 * @param {any} y2 * @param {any} _depth - * @returns + * @returns {number} y value between y1 and y2 */ const findLane = (y1, y2, _depth) => { const depth = _depth || 0; @@ -347,7 +347,7 @@ const findLane = (y1, y2, _depth) => { }; /** - * This function draw the lines between the commits. They were arrows initially. + * Draw the lines between the commits. They were arrows initially. * * @param {any} svg * @param {any} commit1 @@ -453,12 +453,10 @@ const drawArrows = (svg, commits) => { }; /** - * This function adds the branches and the branches' labels to the svg. + * Adds the branches and the branches' labels to the svg. * * @param svg - * @param commitid * @param branches - * @param direction */ const drawBranches = (svg, branches) => { const gitGraphConfig = getConfig().gitGraph; @@ -510,10 +508,6 @@ const drawBranches = (svg, branches) => { }; /** - * @param svg - * @param commit - * @param direction - * @param branchColor * @param txt * @param id * @param ver diff --git a/src/diagrams/mindmap/mindmapRenderer.js b/src/diagrams/mindmap/mindmapRenderer.js index f3c6011b8..caa8baedb 100644 --- a/src/diagrams/mindmap/mindmapRenderer.js +++ b/src/diagrams/mindmap/mindmapRenderer.js @@ -22,7 +22,6 @@ function drawNodes(svg, mindmap, section, conf) { } /** - * @param {any} svg The svg element to draw the diagram onto * @param edgesElem * @param mindmap * @param parent @@ -149,8 +148,6 @@ const mergeTrees = (node, trees) => { /** * @param node - * @param isRoot - * @param parent * @param conf */ function layoutMindmap(node, conf) { @@ -201,7 +198,6 @@ function layoutMindmap(node, conf) { } /** * @param node - * @param isRoot * @param conf */ function positionNodes(node, conf) { diff --git a/src/diagrams/sequence/sequenceRenderer.js b/src/diagrams/sequence/sequenceRenderer.js index 7bdc5958f..ac1edd9e3 100644 --- a/src/diagrams/sequence/sequenceRenderer.js +++ b/src/diagrams/sequence/sequenceRenderer.js @@ -326,7 +326,7 @@ const boundMessage = function (diagram, msgModel) { * * @param {any} diagram - The parent of the message element * @param {any} msgModel - The model containing fields describing a message - * @param {float} lineStarty - The Y coordinate at which the message line starts + * @param {number} lineStarty - The Y coordinate at which the message line starts * @param diagObj */ const drawMessage = function (diagram, msgModel, lineStarty, diagObj) { @@ -582,8 +582,7 @@ function adjustLoopHeightForWrap(loopWidths, msg, preMargin, postMargin, addLoop /** * Draws a sequenceDiagram in the tag with id: id based on the graph definition in text. * - * @param {any} text The text of the diagram - * @param _text + * @param {any} _text The text of the diagram * @param {any} id The id of the diagram which will be used as a DOM element id¨ * @param {any} _version Mermaid version from package.json * @param {any} diagObj A stanard diagram containing the db and the text and type etc of the diagram diff --git a/src/diagrams/state/shapes.js b/src/diagrams/state/shapes.js index c3826856e..e2286bb51 100644 --- a/src/diagrams/state/shapes.js +++ b/src/diagrams/state/shapes.js @@ -66,9 +66,9 @@ export const drawSimpleState = (g, stateDef) => { /** * Draws a state with descriptions * - * @param {any} g + * @param {any} g The d3 svg object to add the state to * @param {any} stateDef - * @returns + * @returns {any} The d3 svg state */ export const drawDescrState = (g, stateDef) => { const addTspan = function (textEl, txt, isFirst) { diff --git a/src/setupGraphViewbox.js b/src/setupGraphViewbox.js index 79dcbfd5c..8ffdab5e7 100644 --- a/src/setupGraphViewbox.js +++ b/src/setupGraphViewbox.js @@ -37,8 +37,6 @@ export const calculateSvgSizeAttrs = function (height, width, useMaxWidth) { * @param {SVGSVGElement} svgElem The SVG Element to configure * @param {number} height The height of the SVG * @param {number} width The width of the SVG - * @param tx - * @param ty * @param {boolean} useMaxWidth Whether or not to use max-width and set width to 100% */ export const configureSvgSize = function (svgElem, height, width, useMaxWidth) { From c50a7533f648ddeb991d2ebe947a4aea9a2bc48e Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 7 Sep 2022 12:38:26 +0200 Subject: [PATCH 3/3] Removed warnings in the grammar oand some console logging --- src/diagrams/mindmap/mindmap.spec.js | 48 ++++++++------- src/diagrams/mindmap/mindmapDb.js | 7 ++- src/diagrams/mindmap/parser/mindmap.jison | 75 ++++++++++++----------- 3 files changed, 69 insertions(+), 61 deletions(-) diff --git a/src/diagrams/mindmap/mindmap.spec.js b/src/diagrams/mindmap/mindmap.spec.js index 2b88a579d..4e11dbd8b 100644 --- a/src/diagrams/mindmap/mindmap.spec.js +++ b/src/diagrams/mindmap/mindmap.spec.js @@ -1,4 +1,5 @@ import * as mindmapDB from './mindmapDb'; +import { setLogLevel } from '../../logger'; describe('when parsing a mindmap ', function () { let mindmap; @@ -6,9 +7,10 @@ describe('when parsing a mindmap ', function () { mindmap = require('./parser/mindmap').parser; mindmap.yy = require('./mindmapDb'); mindmap.yy.clear(); + setLogLevel('trace'); }); describe('hiearchy', function () { - it('should handle a simple root definition', function () { + it('MMP-1 should handle a simple root definition abc122', function () { let str = `mindmap root`; @@ -16,7 +18,7 @@ describe('when parsing a mindmap ', function () { // console.log('Time for checks', mindmap.yy.getMindmap().descr); expect(mindmap.yy.getMindmap().descr).toEqual('root'); }); - it('should handle a hierachial mindmap definition', function () { + it('MMP-2 should handle a hierachial mindmap definition', function () { let str = `mindmap root child1 @@ -31,7 +33,7 @@ describe('when parsing a mindmap ', function () { expect(mm.children[1].descr).toEqual('child2'); }); - it('should handle a simple root definition with a shape and without an id abc123', function () { + it('3 should handle a simple root definition with a shape and without an id abc123', function () { let str = `mindmap (root)`; @@ -40,7 +42,7 @@ describe('when parsing a mindmap ', function () { expect(mindmap.yy.getMindmap().descr).toEqual('root'); }); - it('should handle a deeper hierachial mindmap definition', function () { + it('MMP-4 should handle a deeper hierachial mindmap definition', function () { let str = `mindmap root child1 @@ -55,7 +57,7 @@ describe('when parsing a mindmap ', function () { expect(mm.children[0].children[0].descr).toEqual('leaf1'); expect(mm.children[1].descr).toEqual('child2'); }); - it('Multiple roots are illegal', function () { + it('5 Multiple roots are illegal', function () { let str = `mindmap root fakeRoot`; @@ -70,7 +72,7 @@ describe('when parsing a mindmap ', function () { ); } }); - it('real root in wrong place', function () { + it('MMP-6 real root in wrong place', function () { let str = `mindmap root fakeRoot @@ -88,7 +90,7 @@ describe('when parsing a mindmap ', function () { }); }); describe('nodes', function () { - it('should handle an id and type for a node definition', function () { + it('MMP-7 should handle an id and type for a node definition', function () { let str = `mindmap root[The root] `; @@ -99,7 +101,7 @@ describe('when parsing a mindmap ', function () { expect(mm.descr).toEqual('The root'); expect(mm.type).toEqual(mindmap.yy.nodeType.RECT); }); - it('should handle an id and type for a node definition', function () { + it('MMP-8 should handle an id and type for a node definition', function () { let str = `mindmap root theId(child1)`; @@ -113,7 +115,7 @@ describe('when parsing a mindmap ', function () { expect(child.nodeId).toEqual('theId'); expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT); }); - it('should handle an id and type for a node definition', function () { + it('MMP-9 should handle an id and type for a node definition', function () { let str = `mindmap root theId(child1)`; @@ -127,10 +129,10 @@ root expect(child.nodeId).toEqual('theId'); expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT); }); - it('mutiple types (circle)', function () { + it('MMP-10 mutiple types (circle)', function () { let str = `mindmap root((the root)) -`; + `; mindmap.parse(str); const mm = mindmap.yy.getMindmap(); @@ -139,7 +141,7 @@ root expect(mm.type).toEqual(mindmap.yy.nodeType.CIRCLE); }); - it('mutiple types (cloud)', function () { + it('MMP-11 mutiple types (cloud)', function () { let str = `mindmap root)the root( `; @@ -150,7 +152,7 @@ root expect(mm.children.length).toEqual(0); expect(mm.type).toEqual(mindmap.yy.nodeType.CLOUD); }); - it('mutiple types (bang)', function () { + it('MMP-12 mutiple types (bang)', function () { let str = `mindmap root))the root(( `; @@ -163,7 +165,7 @@ root }); }); describe('decorations', function () { - it('should be possible to set an icon for the node', function () { + it('MMP-13 should be possible to set an icon for the node', function () { let str = `mindmap root[The root] ::icon(bomb) @@ -177,7 +179,7 @@ root expect(mm.type).toEqual(mindmap.yy.nodeType.RECT); expect(mm.icon).toEqual('bomb'); }); - it('should be possible to set classes for the node', function () { + it('MMP-14 should be possible to set classes for the node', function () { let str = `mindmap root[The root] :::m-4 p-8 @@ -191,7 +193,7 @@ root expect(mm.type).toEqual(mindmap.yy.nodeType.RECT); expect(mm.class).toEqual('m-4 p-8'); }); - it('should be possible to set both classes and icon for the node', function () { + it('MMP-15 should be possible to set both classes and icon for the node', function () { let str = `mindmap root[The root] :::m-4 p-8 @@ -207,7 +209,7 @@ root expect(mm.class).toEqual('m-4 p-8'); expect(mm.icon).toEqual('bomb'); }); - it('should be possible to set both classes and icon for the node', function () { + it('MMP-16 should be possible to set both classes and icon for the node', function () { let str = `mindmap root[The root] ::icon(bomb) @@ -225,7 +227,7 @@ root }); }); describe('descriptions', function () { - it('should be possible to use node syntax in the descriptions', function () { + it('MMP-17 should be possible to use node syntax in the descriptions', function () { let str = `mindmap root["String containing []"] `; @@ -234,7 +236,7 @@ root expect(mm.nodeId).toEqual('root'); expect(mm.descr).toEqual('String containing []'); }); - it('should be possible to use node syntax in the descriptions in children', function () { + it('MMP-18 should be possible to use node syntax in the descriptions in children', function () { let str = `mindmap root["String containing []"] child1["String containing ()"] @@ -246,7 +248,7 @@ root expect(mm.children.length).toEqual(1); expect(mm.children[0].descr).toEqual('String containing ()'); }); - it('should be possible to have a child after a class assignment', function () { + it('MMP-19 should be possible to have a child after a class assignment', function () { let str = `mindmap root(Root) Child(Child) @@ -266,7 +268,7 @@ root expect(child.children[1].nodeId).toEqual('b'); }); }); - it('should be possible to have meaningless empty rows in a mindmap abc124', function () { + it('MMP-20 should be possible to have meaningless empty rows in a mindmap abc124', function () { let str = `mindmap root(Root) Child(Child) @@ -285,7 +287,7 @@ root expect(child.children.length).toEqual(2); expect(child.children[1].nodeId).toEqual('b'); }); - it('should be possible to have comments in a mindmap', function () { + it('MMP-21 should be possible to have comments in a mindmap', function () { let str = `mindmap root(Root) Child(Child) @@ -306,7 +308,7 @@ root expect(child.children[1].nodeId).toEqual('b'); }); - it('should be possible to have comments at the end of a line', function () { + it('MMP-22 should be possible to have comments at the end of a line', function () { let str = `mindmap root(Root) Child(Child) diff --git a/src/diagrams/mindmap/mindmapDb.js b/src/diagrams/mindmap/mindmapDb.js index 370b3f7d9..48b242c9e 100644 --- a/src/diagrams/mindmap/mindmapDb.js +++ b/src/diagrams/mindmap/mindmapDb.js @@ -1,6 +1,6 @@ /** Created by knut on 15-01-14. */ import { sanitizeText, getConfig } from '../../diagram-api/diagramAPI'; -import { log } from '../../logger'; +import { log as _log } from '../../logger'; let nodes = []; let cnt = 0; @@ -25,7 +25,7 @@ export const getMindmap = () => { return nodes.length > 0 ? nodes[0] : null; }; export const addNode = (level, id, descr, type) => { - console.info('addNode', level, id, descr, type); + log.info('addNode', level, id, descr, type); const conf = getConfig(); const node = { id: cnt++, @@ -132,7 +132,8 @@ export const type2Str = (type) => { return 'no-border'; } }; - +// Expose logger to grammar +export const log = _log; export const getNodeById = (id) => nodes[id]; export const getElementById = (id) => elements[id]; // export default { diff --git a/src/diagrams/mindmap/parser/mindmap.jison b/src/diagrams/mindmap/parser/mindmap.jison index d84c09495..f8c72787c 100644 --- a/src/diagrams/mindmap/parser/mindmap.jison +++ b/src/diagrams/mindmap/parser/mindmap.jison @@ -17,20 +17,21 @@ %% -\s*\%\%.*\n {console.log('Found comment',yytext);} +\s*\%\%.* {yy.log.trace('Found comment',yytext);} // \%\%[^\n]*\n /* skip comments */ "mindmap" return 'MINDMAP'; ":::" { this.begin('CLASS'); } .+ { this.popState();return 'CLASS'; } \n { this.popState();} -[\n\s]*"::icon(" { this.begin('ICON'); } -[\n]+ /* return 'NL'; */ +// [\s]*"::icon(" { this.begin('ICON'); } +"::icon(" { yy.log.trace('Begin icon');this.begin('ICON'); } +[\n]+ return 'NL'; [^\)]+ { return 'ICON'; } -\) {this.popState();} -"-)" { console.log('Exploding node'); this.begin('NODE');return 'NODE_DSTART'; } -"(-" { console.log('Cloud'); this.begin('NODE');return 'NODE_DSTART'; } -"))" { console.log('Explosion Bang'); this.begin('NODE');return 'NODE_DSTART'; } -")" { console.log('Cloud Bang'); this.begin('NODE');return 'NODE_DSTART'; } +\) {yy.log.trace('end icon');this.popState();} +"-)" { yy.log.trace('Exploding node'); this.begin('NODE');return 'NODE_DSTART'; } +"(-" { yy.log.trace('Cloud'); this.begin('NODE');return 'NODE_DSTART'; } +"))" { yy.log.trace('Explosion Bang'); this.begin('NODE');return 'NODE_DSTART'; } +")" { yy.log.trace('Cloud Bang'); this.begin('NODE');return 'NODE_DSTART'; } "((" { this.begin('NODE');return 'NODE_DSTART'; } "(" { this.begin('NODE');return 'NODE_DSTART'; } "[" { this.begin('NODE');return 'NODE_DSTART'; } @@ -38,18 +39,18 @@ // !(-\() return 'NODE_ID'; [^\(\[\n\-\)]+ return 'NODE_ID'; <> return 'EOF'; -["] { console.log('Starting NSTR');this.begin("NSTR");} -[^"]+ { console.log('description:', yytext); return "NODE_DESCR";} +["] { yy.log.trace('Starting NSTR');this.begin("NSTR");} +[^"]+ { yy.log.trace('description:', yytext); return "NODE_DESCR";} ["] {this.popState();} -[\)]\) {this.popState();console.log('node end ))');return "NODE_DEND";} -[\)] {this.popState();console.log('node end )');return "NODE_DEND";} -[\]] {this.popState();console.log('node end ...');return "NODE_DEND";} -"(-" {this.popState();console.log('node end (-');return "NODE_DEND";} -"-)" {this.popState();console.log('node end (-');return "NODE_DEND";} -"((" {this.popState();console.log('node end ((');return "NODE_DEND";} -"(" {this.popState();console.log('node end ((');return "NODE_DEND";} -[^\)\]\(]+ { console.log('Long description:', yytext); return 'NODE_DESCR';} -.+(?!\(\() { console.log('Long description:', yytext); return 'NODE_DESCR';} +[\)]\) {this.popState();yy.log.trace('node end ))');return "NODE_DEND";} +[\)] {this.popState();yy.log.trace('node end )');return "NODE_DEND";} +[\]] {this.popState();yy.log.trace('node end ...',yytext);return "NODE_DEND";} +"(-" {this.popState();yy.log.trace('node end (-');return "NODE_DEND";} +"-)" {this.popState();yy.log.trace('node end (-');return "NODE_DEND";} +"((" {this.popState();yy.log.trace('node end ((');return "NODE_DEND";} +"(" {this.popState();yy.log.trace('node end ((');return "NODE_DEND";} +[^\)\]\(]+ { yy.log.trace('Long description:', yytext); return 'NODE_DESCR';} +.+(?!\(\() { yy.log.trace('Long description:', yytext); return 'NODE_DESCR';} // [\[] return 'NODE_START'; // .+ return 'TXT' ; @@ -62,29 +63,33 @@ start // %{ : info document 'EOF' { return yy; } } : MINDMAP document { return yy; } + | MINDMAP NL document { return yy; } | SPACELIST MINDMAP document { return yy; } ; +stop + : NL {yy.log.trace('Stop NL ');} + | EOF {yy.log.trace('Stop EOF ');} + | stop NL {yy.log.trace('Stop NL2 ');} + | stop EOF {yy.log.trace('Stop EOF2 ');} + ; document - : document line - | line - ; - -line - : statement { } + : document statement stop + | statement stop ; statement - : SPACELIST node { yy.addNode($1.length, $2.id, $2.descr, $2.type); } - | SPACELIST ICON { yy.decorateNode({icon: $2}); } - | SPACELIST EOF - | SPACELIST NL - | node { console.log($1.id);yy.addNode(0, $1.id, $1.descr, $1.type); } + : SPACELIST node { yy.log.trace('Node: ',$2.id);yy.addNode($1.length, $2.id, $2.descr, $2.type); } + | SPACELIST ICON { yy.log.trace('Icon: ',$2);yy.decorateNode({icon: $2}); } + | SPACELIST CLASS { yy.decorateNode({class: $2}); } + | node { yy.log.trace('Node: ',$1.id);yy.addNode(0, $1.id, $1.descr, $1.type); } | ICON { yy.decorateNode({icon: $1}); } - | SPACELIST CLASS { yy.decorateNode({class: $2}); } - | CLASS { yy.decorateNode({class: $1}); } - | EOF + | CLASS { yy.decorateNode({class: $1}); } + | SPACELIST ; + + + node :nodeWithId |nodeWithoutId @@ -92,12 +97,12 @@ node nodeWithoutId : NODE_DSTART NODE_DESCR NODE_DEND - { console.log("node found ..", $1); $$ = { id: $2, descr: $2, type: yy.getType($1, $3) }; } + { yy.log.trace("node found ..", $1); $$ = { id: $2, descr: $2, type: yy.getType($1, $3) }; } ; nodeWithId : NODE_ID { $$ = { id: $1, descr: $1, type: yy.nodeType.DEFAULT }; } | NODE_ID NODE_DSTART NODE_DESCR NODE_DEND - { console.log("node found ..", $1); $$ = { id: $1, descr: $3, type: yy.getType($2, $4) }; } + { yy.log.trace("node found ..", $1); $$ = { id: $1, descr: $3, type: yy.getType($2, $4) }; } ; %%