• 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évisiond89d215a0dd2cabf316ed1f1a49a2120a338833e (tree)
l'heure2021-12-20 06:03:53
AuteurAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Message de Log

Another peg.StrTerm test

Change Summary

Modification

diff -r 151697e5fa4e -r d89d215a0dd2 AST/castle/_base.py
--- a/AST/castle/_base.py Tue Dec 14 23:17:36 2021 +0100
+++ b/AST/castle/_base.py Sun Dec 19 22:03:53 2021 +0100
@@ -1,13 +1,15 @@
11 class AST_BASE:
22 """Base class for all Castle ATS nodes"""
33
4- def __init__(self, *, parse_tree=None):
4+ def __init__(self, *, parse_tree=None, **kwargs):
5+ super().__init__(**kwargs)
56 self._parse_tree = parse_tree
67
8+
79 @property
8- def position(self): return self.parse_tree.position
10+ def position(self): return self._parse_tree.position
911 @property
10- def position_end(self): return self.parse_tree.position_end
12+ def position_end(self): return self._parse_tree.position_end
1113
1214
1315 class IDError(ValueError):
diff -r 151697e5fa4e -r d89d215a0dd2 AST/castle/peg.py
--- a/AST/castle/peg.py Tue Dec 14 23:17:36 2021 +0100
+++ b/AST/castle/peg.py Sun Dec 19 22:03:53 2021 +0100
@@ -2,6 +2,9 @@
22
33 class PEG (AST_BASE): # abstract
44 """Base class of all PEG classes"""
5+ def __init__(self, **kwargs):
6+ super().__init__(**kwargs)
7+
58
69 ##
710 ## Note: When using TypeHints with PEG-classes; the clases
@@ -13,6 +16,8 @@
1316 def __init__(self, *, value=None, **kwargs):
1417 super().__init__(**kwargs)
1518 self.value=value
19+
20+
1621 class NonTerminal(PEG): pass # abstract
1722 class Markers(PEG): pass # abstract
1823
@@ -24,7 +29,6 @@
2429 class Expression(NonTerminal): pass # abstract
2530
2631
27-
2832 class Setting(PEG):
2933 def __init__(self, *,
3034 name: ID,
@@ -36,7 +40,6 @@
3640 self.value = value
3741
3842
39-
4043 class Rule(NonTerminal):
4144 def __init__(self, *,
4245 name: ID,
diff -r 151697e5fa4e -r d89d215a0dd2 Arpeggio/pytst/d2_ast/test_1_term.py
--- a/Arpeggio/pytst/d2_ast/test_1_term.py Tue Dec 14 23:17:36 2021 +0100
+++ b/Arpeggio/pytst/d2_ast/test_1_term.py Sun Dec 19 22:03:53 2021 +0100
@@ -21,7 +21,20 @@
2121 return ast
2222
2323 def test_simple_str():
24- ast = parse("'a string'", grammar.term)
24+ txt="'a string'"
25+ ast = parse(txt, grammar.term)
2526 assert isinstance(ast, peg.Terminal), "It should be a term ..."
2627 assert isinstance(ast, peg.StrTerm), "... and a str"
2728 assert ast.value == "a string", "It's correct value should be without quotes"
29+ assert ast.position == 0, "The term's position includes the quotes ..."
30+ assert ast.position_end == len(txt), " ... on both ends."
31+
32+def test_simple_str_2():
33+ txt='"""triple string"""'
34+ ast = parse(txt, grammar.term)
35+ assert isinstance(ast, peg.Terminal), "It should be a term ..."
36+ assert isinstance(ast, peg.StrTerm), "... and a str"
37+ assert ast.value == "triple string", "It's correct value should be without quotes"
38+ assert ast.position == 0, "The term's position includes the quotes ..."
39+ assert ast.position_end == len(txt), " ... on both ends."
40+