mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-09 17:19:45 +02:00
Recognizing attributes
This commit is contained in:
@@ -2,30 +2,36 @@
|
|||||||
%lex
|
%lex
|
||||||
|
|
||||||
%options case-insensitive
|
%options case-insensitive
|
||||||
|
%options easy_keyword_rules
|
||||||
|
|
||||||
%s group
|
%s group
|
||||||
|
// when we are inside [] section we are defining attrubutes
|
||||||
%x attributes
|
%x attributes
|
||||||
%x attribute
|
// after attr= we are expecting a value without quotes
|
||||||
%x value
|
%x value
|
||||||
|
// or if we use "" we are expecting a string containing value
|
||||||
|
%x string
|
||||||
|
|
||||||
%%
|
%%
|
||||||
"sankey" return 'SANKEY'
|
"sankey" { return 'SANKEY'; }
|
||||||
\d+ return 'AMOUNT'
|
\d+ { return 'AMOUNT'; }
|
||||||
"->" return 'ARROW'
|
"->" { return 'ARROW'; }
|
||||||
\w+ return 'NODE'
|
\w+ { return 'NODE'; }
|
||||||
(?:<<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('group'); 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'; } // string followed by = sign is "attrName"
|
<attributes>\w+ { return 'ATTRIBUTE'; }
|
||||||
<attributes>(?=\=s*)[\s\w] {return 'VALUE';}
|
<attributes>(?=\=s*)[\s\w] { return 'VALUE';}
|
||||||
<attributes>\= { this.pushState('attribute'); return 'EQUAL'; }
|
<attributes>\= { this.pushState('value'); return 'EQUAL'; }
|
||||||
<attributes>\s+ // skip all whitespace
|
<attributes>\s+ // skip all whitespace
|
||||||
<attribute>[\w]+ {this.popState(); return 'VALUE';}
|
<value>[\w]+ { this.popState(); return 'VALUE';}
|
||||||
<attribute>\s+ //skip
|
<value>\s+ //skip
|
||||||
<attribute>\" { this.pushState('value'); return 'OPEN_VALUE'; }
|
<value>\" { this.pushState('string'); return 'OPEN_STRING'; }
|
||||||
<value>\" { this.popState(); return 'CLOSE_VALUE'; }
|
<string>\" { this.popState(); return 'CLOSE_STRING'; }
|
||||||
|
<string>[\w\s]+(?=\") { 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
|
||||||
|
|
||||||
|
@@ -41,11 +41,14 @@ describe('Sankey diagram', function () {
|
|||||||
it('recognizes a separate node with its attributes', () => {
|
it('recognizes a separate node with its attributes', () => {
|
||||||
const str = `
|
const str = `
|
||||||
sankey
|
sankey
|
||||||
a[]
|
node[]
|
||||||
b[attr=1]
|
node[attr=1]
|
||||||
c[attr=2]
|
node[attr=2]
|
||||||
d[attrWithoutValue]
|
a -> 30 -> b
|
||||||
d[attr = 3]
|
node[attrWithoutValue]
|
||||||
|
node[attr = 3]
|
||||||
|
node[attr1 = 23413 attr2=1234]
|
||||||
|
node[x1dfqowie attr1 = 23413 attr2]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
|
Reference in New Issue
Block a user