• R/O
  • SSH

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

Révision9480be9594159eb5e13343b2941028be9da36756 (tree)
l'heure2022-01-03 08:01:50
AuteurAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Message de Log

Now, UnorderedGroup also works

Change Summary

Modification

diff -r 96da5581ccbe -r 9480be959415 AST/castle/_base.py
--- a/AST/castle/_base.py Sun Jan 02 23:43:33 2022 +0100
+++ b/AST/castle/_base.py Mon Jan 03 00:01:50 2022 +0100
@@ -2,6 +2,7 @@
22 """Base class for all Castle ATS nodes"""
33
44 def __init__(self, *, parse_tree=None, **kwargs):
5+ assert len(kwargs)==0, "Do not call 'Object' with kwargs (caller is wrong)"
56 super().__init__(**kwargs)
67 self._parse_tree = parse_tree
78
diff -r 96da5581ccbe -r 9480be959415 AST/castle/peg.py
--- a/AST/castle/peg.py Sun Jan 02 23:43:33 2022 +0100
+++ b/AST/castle/peg.py Mon Jan 03 00:01:50 2022 +0100
@@ -62,7 +62,10 @@
6262
6363
6464 class Group(Expression):pass # abstract -- Do not use for a '(' ...')' group, that's a Sequence!!
65-class UnorderedGroup(Group):pass # It looks like a Quantity, but is a group
65+class UnorderedGroup(Group): # It looks like a Quantity, but is a group
66+ def __init__(self, *, expr=None, **kwargs):
67+ super().__init__(**kwargs)
68+ self.expr = expr
6669
6770
6871 class Quantity(Expression): # abstract
@@ -85,7 +88,6 @@
8588
8689 class OrderedChoice(Expression):pass # It a an set of alternatives
8790
88-
8991 class Optional(Quantity):pass
9092 class ZeroOrMore(Quantity):pass
9193 class OneOrMore(Quantity):pass
diff -r 96da5581ccbe -r 9480be959415 Arpeggio/pytst/d2_ast/test_5_group.py
--- a/Arpeggio/pytst/d2_ast/test_5_group.py Sun Jan 02 23:43:33 2022 +0100
+++ b/Arpeggio/pytst/d2_ast/test_5_group.py Mon Jan 03 00:01:50 2022 +0100
@@ -36,3 +36,21 @@
3636 assert_ID(ngrp[0][0], 'A')
3737 assert_ID(ngrp[0][1], 'B')
3838
39+
40+def test_unordered_group():
41+ txt = "R <- ( A B )# ;"
42+
43+ ast = parse(txt, grammar.rule)
44+ assert_ID(ast.name, 'R')
45+
46+ grp = ast.expr
47+ assert len(grp)==1, "There should be only one expr; ..."
48+ assert isinstance(grp[0], peg.UnorderedGroup), " ... the UnorderedGroup"
49+
50+ exp = grp[0].expr
51+ assert len(exp)==2, "The UnorderedGroup should have 2 elements .."
52+ assert isinstance(exp, peg.Sequence), "... in a sequence"
53+
54+ assert_ID(exp[0], 'A')
55+ assert_ID(exp[1], 'B')
56+