From 46f13a4822a394c9b77e4fc7f4b050de77cbe8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E6=B1=9D?= Date: Tue, 25 Jun 2024 09:59:49 +0800 Subject: [PATCH] fix: optimize syntax rules --- src/utils/remarkSyntaxDiagram.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils/remarkSyntaxDiagram.js b/src/utils/remarkSyntaxDiagram.js index 822a40c5..e8c50cec 100644 --- a/src/utils/remarkSyntaxDiagram.js +++ b/src/utils/remarkSyntaxDiagram.js @@ -62,14 +62,12 @@ 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 } + / '[' _ c:optional _ ']' _ '[' _ '...' _ ']' { return {type: 'OneOrMore', item: c, repeat: {type: 'Skip'}} } / '[' _ o:optional _ ']' _ '[' _ ',' _ '...' _ ']' { return {type: 'OneOrMore', item: o, repeat: {type: 'Terminal', text: ','}} } / '[' _ o:optional _ ']' { return o } @@ -79,9 +77,9 @@ const ebnfParser = pegjs.generate(` terminal = ('"' [^"]* '"' / "'" [^']* "'") { const t = text(); - return {type: 'Terminal', text: t.substr(1, t.length - 2)}; + return {type: 'NonTerminal', text: text()}; } - nonTerminal = [0-9a-zA-Z_=,*]+ { + nonTerminal = [0-9a-zA-Z_=,*\(\)]+ { return {type: 'NonTerminal', text: text()}; } _ = [ \\n\\r\\t]* -- Gitee