Simplify grammar to more correctly parse bstrings.
authorKim Grasman <kim.grasman@gmail.com>
Sat, 4 Jan 2014 22:01:36 +0000 (23:01 +0100)
committerKim Grasman <kim.grasman@gmail.com>
Sat, 4 Jan 2014 22:01:36 +0000 (23:01 +0100)
asn1ate/parser.py
testdata/bstring.asn

index 262666b..20648e6 100644 (file)
@@ -158,9 +158,8 @@ def _build_asn1_grammar():
     # Literals
     number = Word(nums)
     signed_number = Combine(Optional('-') + number)  # todo: consider defined values from 18.1
-    horizontal_whitespace = White('\t ')
     binary_digit = Literal('0') | Literal('1')
-    binary_string = Combine(ZeroOrMore(Suppress(horizontal_whitespace) | binary_digit))
+    binary_string = Combine(OneOrMore(binary_digit), adjacent=False)  # Use adjacent=False to skip whiteepace
     bstring = Suppress('\'') + binary_string + Suppress('\'B')
     hstring = Literal('\'') + Regex('[0-9A-F]+') + Literal('\'H')
 
index b241273..d243800 100644 (file)
@@ -4,10 +4,4 @@ BEGIN
 
   -- With whitespace
   whitespace OCTET STRING ::= '1 1     0'B
-
-  -- Whitespace only. This should probably be invalid.
-  whitespace-only OCTET STRING ::= '   'B
-
-  -- Empty literal. This should probably be invalid.
-  empty OCTET STRING ::= ''B
 END