mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 15:30:03 +02:00
Attributes within strings
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
(?:<<EOF>>|[\n;])+ { return 'EOS'; } // end of statement is ; \n or end of file
|
(?:<<EOF>>|[\n;])+ { return 'EOS'; } // end of statement is ; \n or end of file
|
||||||
\s+ // skip all whitespace
|
\s+ // skip all whitespace
|
||||||
"{" { this.pushState('group'); return 'OPEN_GROUP'; }
|
"{" { this.pushState('group'); return 'OPEN_GROUP'; }
|
||||||
<group>"}" { this.popState('group'); return 'CLOSE_GROUP'; }
|
<group>"}" { this.popState(); return 'CLOSE_GROUP'; }
|
||||||
"[" { this.pushState('attributes'); return 'OPEN_ATTRIBUTES'; }
|
"[" { this.pushState('attributes'); return 'OPEN_ATTRIBUTES'; }
|
||||||
<attributes>"]" { this.popState(); return 'CLOSE_ATTRIBUTES'; }
|
<attributes>"]" { this.popState(); return 'CLOSE_ATTRIBUTES'; }
|
||||||
<attributes>\w+ { return 'ATTRIBUTE'; }
|
<attributes>\w+ { return 'ATTRIBUTE'; }
|
||||||
@@ -30,8 +30,12 @@
|
|||||||
<value>[\w]+ { this.popState(); return 'VALUE';}
|
<value>[\w]+ { this.popState(); return 'VALUE';}
|
||||||
<value>\s+ //skip
|
<value>\s+ //skip
|
||||||
<value>\" { this.pushState('string'); return 'OPEN_STRING'; }
|
<value>\" { this.pushState('string'); return 'OPEN_STRING'; }
|
||||||
<string>\" { this.popState(); return 'CLOSE_STRING'; }
|
<string>(?!\\)\" {
|
||||||
<string>[\w\s]+(?=\") { return 'STRING'; }
|
if(this.topState()==='string') this.popState();
|
||||||
|
if(this.topState()==='value') this.popState();
|
||||||
|
return 'CLOSE_STRING';
|
||||||
|
}
|
||||||
|
<string>([^"\\]|\\\")+ { console.log(this.state); return 'STRING'; }
|
||||||
|
|
||||||
// TODO: check if jison will return 2 separate tokens (for nodes) while ignoring whitespace
|
// TODO: check if jison will return 2 separate tokens (for nodes) while ignoring whitespace
|
||||||
|
|
||||||
@@ -60,12 +64,9 @@ line
|
|||||||
node_with_attributes: NODE OPEN_ATTRIBUTES attributes CLOSE_ATTRIBUTES;
|
node_with_attributes: NODE OPEN_ATTRIBUTES attributes CLOSE_ATTRIBUTES;
|
||||||
|
|
||||||
attributes: attribute attributes | ;
|
attributes: attribute attributes | ;
|
||||||
attribute: ATTRIBUTE EQUAL VALUE | ATTRIBUTE;
|
attribute: ATTRIBUTE EQUAL value | ATTRIBUTE;
|
||||||
|
|
||||||
// flow
|
value: VALUE | OPEN_STRING STRING CLOSE_STRING;
|
||||||
// : NODE ARROW value_or_values_group ARROW flow
|
|
||||||
// | NODE
|
|
||||||
// ;
|
|
||||||
|
|
||||||
flow: n_chain_a;
|
flow: n_chain_a;
|
||||||
|
|
||||||
|
@@ -38,12 +38,12 @@ describe('Sankey diagram', function () {
|
|||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('recognizes a separate node with its attributes', () => {
|
describe('while attributes parsing', () => {
|
||||||
|
it('parses different quotless variations', () => {
|
||||||
const str = `
|
const str = `
|
||||||
sankey
|
sankey
|
||||||
node[]
|
node[]
|
||||||
node[attr=1]
|
node[attr=1]
|
||||||
node[attr=2]
|
|
||||||
a -> 30 -> b
|
a -> 30 -> b
|
||||||
node[attrWithoutValue]
|
node[attrWithoutValue]
|
||||||
node[attr = 3]
|
node[attr = 3]
|
||||||
@@ -54,6 +54,19 @@ describe('Sankey diagram', function () {
|
|||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses strings as values', () => {
|
||||||
|
const str = `
|
||||||
|
sankey
|
||||||
|
node[attr="hello, how are you?"]
|
||||||
|
node[attr="hello\\""]
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it('recognizes grouped values', () => {
|
// it('recognizes grouped values', () => {
|
||||||
// const str = `
|
// const str = `
|
||||||
// sankey
|
// sankey
|
||||||
|
Reference in New Issue
Block a user