From e05ae647c7634c1c3e08157a67ded34ded7a36ce Mon Sep 17 00:00:00 2001 From: WitherFlower Date: Wed, 8 May 2024 15:14:55 +0900 Subject: [PATCH] Add sequence and alternation --- grammar_parser.meta | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/grammar_parser.meta b/grammar_parser.meta index e692d62..004ea28 100644 --- a/grammar_parser.meta +++ b/grammar_parser.meta @@ -226,6 +226,37 @@ Not.match(stream, context, actions) { } } +// Sequence + +Sequence = Object.subtype(#Sequence); + +Sequence.match(stream, context, actions) { + i = 0; + match = 1; + while (i < self.length() && match == 1) { + match = self[i].match(stream, context, actions); + } + match; +} + +// Alternation + +Alternation = Object.subtype(#Alternation); + +Alternation.match(stream, context, actions) { + i = 0; + match = 0; + while(i < self.length() && match == 0){ + initialActionCount = actions.length(); + match = self[i].match(stream, context, actions); + if (match == 0) { + while (actions.length() > initialActionCount) { + actions.pop(); + } + } + } +} + // Action Action = Object.subtype(#Action);