OSDN Git Service

Minor cleanup.
authorSimon Forman <sforman@hushmail.com>
Wed, 23 Mar 2022 04:24:07 +0000 (21:24 -0700)
committerSimon Forman <sforman@hushmail.com>
Wed, 23 Mar 2022 04:24:07 +0000 (21:24 -0700)
implementations/Python/joy/library.py
implementations/Python/joy/parser.py
implementations/Python/joy/utils/snippets.py

index 5094068..b343c9b 100644 (file)
@@ -61,7 +61,7 @@ HELP_TEMPLATE = '''\
 
 %s
 
----- end (%s)
+---- end ( %s )
 '''
 
 
@@ -331,12 +331,12 @@ def choice(stack):
     Use a Boolean value to select one of two items.
     ::
 
-           A B False choice
+           A B false choice
         ----------------------
            A
 
 
-           A B True choice
+           A B true choice
         ---------------------
              B
 
@@ -354,12 +354,12 @@ def select(stack):
     Use a Boolean value to select one of two items from a sequence.
     ::
 
-           [A B] False select
+           [A B] false select
         ------------------------
             A
 
 
-           [A B] True select
+           [A B] true select
         -----------------------
               B
 
index 33a5be9..2c3ae53 100644 (file)
@@ -111,20 +111,14 @@ def _parse(tokens):
             v = frame
             try: frame = stack.pop()
             except IndexError:
-                raise ParseError('Extra closing bracket.')
+                raise ParseError('Extra closing bracket.') from None
             frame.append(list_to_stack(v))
-        elif tok == 'true':
-            frame.append(True)
-        elif tok == 'false':
-            frame.append(False)
-        elif isinstance(tok, Snippet):
-            frame.append(tok)
+        elif tok == 'true': frame.append(True)
+        elif tok == 'false': frame.append(False)
+        elif isinstance(tok, Snippet): frame.append(tok)
         else:
-            try:
-                thing = int(tok)
-            except ValueError:
-                thing = Symbol(tok)
+            try: thing = int(tok)
+            except ValueError: thing = Symbol(tok)
             frame.append(thing)
-    if stack:
-        raise ParseError('Unclosed bracket.')
+    if stack: raise ParseError('Unclosed bracket.')
     return list_to_stack(frame)
index 803b88b..a7ea247 100644 (file)
@@ -1,8 +1,10 @@
 from collections import namedtuple
 from re import compile as RE
 
+
 Snippet = namedtuple('Snippet', 'sha offset length')
-_fmt = '{%s %i %i}'
+
+
 pat = (
     '{'
     '\s*'
@@ -14,14 +16,18 @@ pat = (
     '\s*'
     '}'
     )
+
+
 _PAT = RE(pat)
 
 
 def to_string(snip):
-    return _fmt % _ts(*snip)
+    return _ts(*snip)
+
 
 def _ts(sha, offset, length):
-    return sha.decode('ascii'), offset, length
+    return f'{{{sha.decode("ascii")} {offset} {length}}}'
+
 
 def from_string(text):
     m = _PAT.match(text)
@@ -29,5 +35,6 @@ def from_string(text):
         raise ValueError
     return _fs(**m.groupdict())
 
+
 def _fs(sha, offset, length):
     return Snippet(sha.encode('ascii'), int(offset), int(length))