Fix for issue with comments

This commit is contained in:
Knut Sveidqvist 2022-08-30 21:35:21 +02:00
parent 4cdc6e4a0d
commit 18d95e479c
2 changed files with 57 additions and 2 deletions

View File

@ -166,6 +166,22 @@ root
`;
// ::class1 class2
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
expect(mm.nodeId).toEqual('root');
expect(mm.descr).toEqual('The root');
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
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 () {
var str = `mindmap
root[The root]
::icon(bomb)
:::m-4 p-8
`;
// ::class1 class2
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
expect(mm.nodeId).toEqual('root');
@ -230,6 +246,45 @@ root
expect(mm.descr).toEqual('Root');
expect(mm.children.length).toEqual(1);
const child = mm.children[0];
expect(child.nodeId).toEqual('Child');
expect(child.children[0].nodeId).toEqual('a');
expect(child.children.length).toEqual(2);
expect(child.children[1].nodeId).toEqual('b');
});
it('should be possible to have comments in a mindmap', function () {
var str = `mindmap
root(Root)
Child(Child)
a(a)
%% This is a comment
b[New Stuff]`;
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
expect(mm.nodeId).toEqual('root');
expect(mm.descr).toEqual('Root');
expect(mm.children.length).toEqual(1);
const child = mm.children[0];
expect(child.nodeId).toEqual('Child');
expect(child.children[0].nodeId).toEqual('a');
expect(child.children.length).toEqual(2);
expect(child.children[1].nodeId).toEqual('b');
});
it('should be possible to have comments at the end of a line', function () {
var str = `mindmap
root(Root)
Child(Child)
a(a) %% This is a comment
b[New Stuff]`;
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
expect(mm.nodeId).toEqual('root');
expect(mm.descr).toEqual('Root');
expect(mm.children.length).toEqual(1);
const child = mm.children[0];
expect(child.nodeId).toEqual('Child');
expect(child.children[0].nodeId).toEqual('a');

View File

@ -17,7 +17,7 @@
%%
\%\%.*\n {console.log('Found comment',yytext);} /* skip comments */
\s*\%\%.*\n {console.log('Found comment',yytext);}
// \%\%[^\n]*\n /* skip comments */
"mindmap" return 'MINDMAP';
":::" { this.begin('CLASS'); }
@ -68,7 +68,7 @@ statement
: SPACELIST node { yy.addNode($1.length, $2.id, $2.descr, $2.type); }
| SPACELIST ICON { yy.decorateNode({icon: $2}); }
| SPACELIST EOF
| SPACELIST NL
| SPACELIST NL
| node { console.log($1.id);yy.addNode(0, $1.id, $1.descr, $1.type); }
| ICON { yy.decorateNode({icon: $1}); }
| SPACELIST CLASS { yy.decorateNode({class: $2}); }