From 85f3055c6058c9a99ead63d4648f50d94208d203 Mon Sep 17 00:00:00 2001 From: Hirokazu Chiba Date: Mon, 9 Dec 2024 20:37:03 +0900 Subject: [PATCH] Refactor using a new Peggy operator --- lib/parser.js | 28 ++++++---------------------- lib/spang.pegjs | 20 ++++---------------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 67e9f5e..f78d51e 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1233,13 +1233,7 @@ function peg$parse(input, options) { } }; var peg$f84 = function(o, os) { - let ret = [o]; - - os.forEach((oi) => { - ret.push(oi[3]); - }); - - return ret; + return [o, ...os]; }; var peg$f85 = function(s, list) { return { @@ -1265,13 +1259,7 @@ function peg$parse(input, options) { return pairs; }; var peg$f88 = function(o, os) { - let ret = [o]; - - os.forEach((oi) => { - ret.push(oi[3]); - }); - - return ret; + return [o, ...os]; }; var peg$f89 = function(first, rest) { if (rest.length) { @@ -7026,8 +7014,7 @@ function peg$parse(input, options) { } s7 = peg$parseGraphNode(); if (s7 !== peg$FAILED) { - s4 = [s4, s5, s6, s7]; - s3 = s4; + s3 = s7; } else { peg$currPos = s3; s3 = peg$FAILED; @@ -7061,8 +7048,7 @@ function peg$parse(input, options) { } s7 = peg$parseGraphNode(); if (s7 !== peg$FAILED) { - s4 = [s4, s5, s6, s7]; - s3 = s4; + s3 = s7; } else { peg$currPos = s3; s3 = peg$FAILED; @@ -7318,8 +7304,7 @@ function peg$parse(input, options) { } s7 = peg$parseGraphNodePath(); if (s7 !== peg$FAILED) { - s4 = [s4, s5, s6, s7]; - s3 = s4; + s3 = s7; } else { peg$currPos = s3; s3 = peg$FAILED; @@ -7353,8 +7338,7 @@ function peg$parse(input, options) { } s7 = peg$parseGraphNodePath(); if (s7 !== peg$FAILED) { - s4 = [s4, s5, s6, s7]; - s3 = s4; + s3 = s7; } else { peg$currPos = s3; s3 = peg$FAILED; diff --git a/lib/spang.pegjs b/lib/spang.pegjs index 6191ea6..df22afe 100644 --- a/lib/spang.pegjs +++ b/lib/spang.pegjs @@ -940,15 +940,9 @@ Verb = VarOrIri } // [79] ObjectList ::= Object ( ',' Object )* -ObjectList = o:Object os:( WS* ',' WS* Object )* +ObjectList = o:Object os:( WS* ',' WS* @Object )* { - let ret = [o]; - - os.forEach((oi) => { - ret.push(oi[3]); - }); - - return ret; + return [o, ...os]; } // [80] Object ::= GraphNode @@ -994,15 +988,9 @@ VerbPath = Path VerbSimple = Var // [86] ObjectListPath ::= ObjectPath ( ',' ObjectPath )* -ObjectListPath = o:ObjectPath os:( WS* ',' WS* ObjectPath )* +ObjectListPath = o:ObjectPath os:( WS* ',' WS* @ObjectPath )* { - let ret = [o]; - - os.forEach((oi) => { - ret.push(oi[3]); - }); - - return ret; + return [o, ...os]; } // [87] ObjectPath ::= GraphNodePath