diff --git a/src/utils/remarkSyntaxDiagram.js b/src/utils/remarkSyntaxDiagram.js index 822a40c5589de08add5315ee06b8f17e63b24296..b2c67dade291ce1984a8a1cabe112a7034e7e648 100644 --- a/src/utils/remarkSyntaxDiagram.js +++ b/src/utils/remarkSyntaxDiagram.js @@ -16,8 +16,12 @@ const NON_TERMINAL_WIDTH_FACTOR = 12 / 110 */ const TERMINAL_WIDTH_FACTOR = NON_TERMINAL_WIDTH_FACTOR * 1.2 +// 隐藏括号匹配 +// / '(' _ c:choice _ ')' _ '[' _ '...' _ ']' { return {type: 'OneOrMore', item: c, repeat: {type: 'Skip'}} } +// / '(' _ c:choice _ ')' _ '[' _ ',' _ '...' _ ']' { return {type: 'OneOrMore', item: c, repeat: {type: 'Terminal', text: ','}} } +// / '(' _ c:choice _ ')' { return c } -// TODO: 匹配注释有问题 /** */ 内部的*无法匹配 +// 匹配注释有问题 /** */ 内部的*无法匹配 const ebnfParser = pegjs.generate(` grammar = p:(_ production _)+ { return p.map(d => d[1]); @@ -62,10 +66,6 @@ const ebnfParser = pegjs.generate(` / n:nonTerminal _ '[' _ ',' _ '...' _ ']' { return {type: 'OneOrMore', item: n, repeat: {type: 'Terminal', text: ','}} } / n:nonTerminal !(_ '::=') { return n } - / '(' _ c:choice _ ')' _ '[' _ '...' _ ']' { return {type: 'OneOrMore', item: c, repeat: {type: 'Skip'}} } - / '(' _ c:choice _ ')' _ '[' _ ',' _ '...' _ ']' { return {type: 'OneOrMore', item: c, repeat: {type: 'Terminal', text: ','}} } - / '(' _ c:choice _ ')' { return c } - / '{' _ c:choice _ '}' _ '[' _ '...' _ ']' { return {type: 'OneOrMore', item: c, repeat: {type: 'Skip'}} } / '{' _ c:choice _ '}' _ '[' _ ',' _ '...' _ ']' { return {type: 'OneOrMore', item: c, repeat: {type: 'Terminal', text: ','}} } / '{' _ c:choice _ '}' { return c } @@ -81,7 +81,7 @@ const ebnfParser = pegjs.generate(` const t = text(); return {type: 'Terminal', text: t.substr(1, t.length - 2)}; } - nonTerminal = [0-9a-zA-Z_=,*]+ { + nonTerminal = [0-9a-zA-Z_=,*\(\)]+ { return {type: 'NonTerminal', text: text()}; } _ = [ \\n\\r\\t]*