changeset 65:c4d5d0fe5a4c draft

Add EndOfInput parser
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 25 May 2019 14:45:49 +0200
parents 35f55688363a
children b9ed614fc42f
files pcombinators/primitives.py
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pcombinators/primitives.py	Sat May 25 00:00:25 2019 +0200
+++ b/pcombinators/primitives.py	Sat May 25 14:45:49 2019 +0200
@@ -92,6 +92,12 @@
     """Inverse of CharSet (parse as long as character is not in set). Result is string."""
     return ConcatenateResults(Repeat(NoneOf(s), -1))
 
+class EndOfInput(Parser):
+    def parse(self, st):
+        if st.finished():
+            return '', st
+        return None, st
+
 # See section below for optimized versions of the following parsers.
 
 def CanonicalInteger():