l1 emits TokenKeyword
removed need to Object Keyword which made no sense to have
This commit is contained in:
1 parent
43ed8b4019
commit
cc0f802a10
4 files changed
+28
-21
No files matched your search
@@ -5,12 +5,11 @@ from pdfmajor.parser_v2.objects import (
|
||||
PDFComment,
|
||||
PDFContextualObject,
|
||||
PDFDictionary,
|
||||
PDFKeyword,
|
||||
PDFNull,
|
||||
PDFPrimitive,
|
||||
PDFObject,
|
||||
)
|
||||
from typing import Any, Iterator, List, Optional, Type
|
||||
from typing import Iterator, List, Optional, Type, Union
|
||||
from pdfmajor.lexer.token import (
|
||||
TArrayValue,
|
||||
TDictValue,
|
||||
@@ -96,7 +95,7 @@ class PDFL1Parser:
|
||||
"""
|
||||
return self.lexer.seek(offset)
|
||||
|
||||
def iter_objects(self) -> Iterator[PDFObject]:
|
||||
def iter_objects(self) -> Iterator[Union[PDFObject, TokenKeyword]]:
|
||||
"""Iterates over the objects in the current byte stream using level 1 parsing
|
||||
|
||||
Yields:
|
||||
@@ -114,7 +113,7 @@ class PDFL1Parser:
|
||||
elif isinstance(token, TokenComment):
|
||||
yield PDFComment(token)
|
||||
elif isinstance(token, TokenKeyword):
|
||||
yield PDFKeyword(token)
|
||||
yield token
|
||||
elif isinstance(token, TokenNull):
|
||||
yield PDFNull()
|
||||
elif isinstance(token, TokenArray):
|
||||
|
||||
@@ -3,13 +3,13 @@ from pdfmajor.parser_v2.l1 import PDFL1Parser
|
||||
from pdfmajor.parser_v2.exceptions import ParserError
|
||||
from pdfmajor.parser_v2.objects import (
|
||||
PDFContextualObject,
|
||||
PDFKeyword,
|
||||
PDFPrimitive,
|
||||
PDFObject,
|
||||
)
|
||||
from typing import Iterator, List, Optional, Tuple
|
||||
from typing import Iterator, List, Tuple
|
||||
from pdfmajor.lexer.token import (
|
||||
TokenInteger,
|
||||
TokenKeyword,
|
||||
)
|
||||
from pdfmajor.parser_v2.indirect_objects import IndirectObjectCollection
|
||||
|
||||
@@ -44,7 +44,7 @@ class PDFL2Parser:
|
||||
object_list: List[PDFObject] = []
|
||||
ctx_list: List[PDFContextualObject] = []
|
||||
for obj in self.l1.iter_objects():
|
||||
if isinstance(obj, PDFKeyword):
|
||||
if isinstance(obj, TokenKeyword):
|
||||
if obj.get_value() == b"obj":
|
||||
if len(object_list) < 2:
|
||||
raise ParserError("recieved 'obj' but missing leading tokens")
|
||||
|
||||
@@ -55,19 +55,6 @@ class PDFPrimitive(Generic[TToken], PDFObject):
|
||||
return self.get_value()
|
||||
|
||||
|
||||
class PDFKeyword(PDFObject):
|
||||
"""A class representing a PDF keyword"""
|
||||
|
||||
def __init__(self, token: TokenKeyword) -> None:
|
||||
self.token = token
|
||||
|
||||
def get_value(self):
|
||||
return self.token.value
|
||||
|
||||
def to_python(self):
|
||||
return self.get_value()
|
||||
|
||||
|
||||
class PDFComment(PDFObject):
|
||||
"""A class representing a PDF comment"""
|
||||
|
||||
|
||||
Reference in new issue
Block a user