mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Attributes within strings
This commit is contained in:
parent
b4b535f997
commit
f71769e07b
@ -20,7 +20,7 @@
|
||||
(?:<<EOF>>|[\n;])+ { return 'EOS'; } // end of statement is ; \n or end of file
|
||||
\s+ // skip all whitespace
|
||||
"{" { 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'; }
|
||||
<attributes>"]" { this.popState(); return 'CLOSE_ATTRIBUTES'; }
|
||||
<attributes>\w+ { return 'ATTRIBUTE'; }
|
||||
@ -30,8 +30,12 @@
|
||||
<value>[\w]+ { this.popState(); return 'VALUE';}
|
||||
<value>\s+ //skip
|
||||
<value>\" { this.pushState('string'); return 'OPEN_STRING'; }
|
||||
<string>\" { this.popState(); return 'CLOSE_STRING'; }
|
||||
<string>[\w\s]+(?=\") { return 'STRING'; }
|
||||
<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
|
||||
|
||||
@ -60,12 +64,9 @@ line
|
||||
node_with_attributes: NODE OPEN_ATTRIBUTES attributes CLOSE_ATTRIBUTES;
|
||||
|
||||
attributes: attribute attributes | ;
|
||||
attribute: ATTRIBUTE EQUAL VALUE | ATTRIBUTE;
|
||||
attribute: ATTRIBUTE EQUAL value | ATTRIBUTE;
|
||||
|
||||
// flow
|
||||
// : NODE ARROW value_or_values_group ARROW flow
|
||||
// | NODE
|
||||
// ;
|
||||
value: VALUE | OPEN_STRING STRING CLOSE_STRING;
|
||||
|
||||
flow: n_chain_a;
|
||||
|
||||
|
@ -38,22 +38,35 @@ describe('Sankey diagram', function () {
|
||||
parser.parse(str);
|
||||
});
|
||||
|
||||
it('recognizes a separate node with its attributes', () => {
|
||||
const str = `
|
||||
sankey
|
||||
node[]
|
||||
node[attr=1]
|
||||
node[attr=2]
|
||||
a -> 30 -> b
|
||||
node[attrWithoutValue]
|
||||
node[attr = 3]
|
||||
node[attr1 = 23413 attr2=1234]
|
||||
node[x1dfqowie attr1 = 23413 attr2]
|
||||
`;
|
||||
|
||||
parser.parse(str);
|
||||
describe('while attributes parsing', () => {
|
||||
it('parses different quotless variations', () => {
|
||||
const str = `
|
||||
sankey
|
||||
node[]
|
||||
node[attr=1]
|
||||
a -> 30 -> b
|
||||
node[attrWithoutValue]
|
||||
node[attr = 3]
|
||||
node[attr1 = 23413 attr2=1234]
|
||||
node[x1dfqowie attr1 = 23413 attr2]
|
||||
`;
|
||||
|
||||
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', () => {
|
||||
// const str = `
|
||||
// sankey
|
||||
|
Loading…
x
Reference in New Issue
Block a user