renamed decimal to real
This commit is contained in:
1 parent
472942867b
commit
da936e6a48
3 files changed
+15
-15
No files matched your search
@@ -3,7 +3,7 @@ from typing import Optional
|
|||||||
from pdfmajor.streambuffer import BufferStream
|
from pdfmajor.streambuffer import BufferStream
|
||||||
from pdfmajor.lexer.exceptions import InvalidToken, LexerEOF, LexerError
|
from pdfmajor.lexer.exceptions import InvalidToken, LexerEOF, LexerError
|
||||||
from pdfmajor.lexer.token import (
|
from pdfmajor.lexer.token import (
|
||||||
TokenDecimal,
|
TokenReal,
|
||||||
TokenNumber,
|
TokenNumber,
|
||||||
TokenInteger,
|
TokenInteger,
|
||||||
)
|
)
|
||||||
@@ -46,7 +46,7 @@ def parse_number(
|
|||||||
buffer.seek(pos + j)
|
buffer.seek(pos + j)
|
||||||
try:
|
try:
|
||||||
if is_decimal:
|
if is_decimal:
|
||||||
return TokenDecimal(
|
return TokenReal(
|
||||||
initialpos,
|
initialpos,
|
||||||
buffer.tell(),
|
buffer.tell(),
|
||||||
Decimal(curtoken.decode()),
|
Decimal(curtoken.decode()),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ T = TypeVar("T")
|
|||||||
class Token(Generic[T]):
|
class Token(Generic[T]):
|
||||||
"""A generic class representing PDF Token"""
|
"""A generic class representing PDF Token"""
|
||||||
|
|
||||||
__slots__ = ["pos", "size", "value"]
|
__slots__ = ["start_loc", "end_loc", "value"]
|
||||||
|
|
||||||
def __init__(self, start_loc: int, end_loc: int, value: T) -> None:
|
def __init__(self, start_loc: int, end_loc: int, value: T) -> None:
|
||||||
self.start_loc = start_loc
|
self.start_loc = start_loc
|
||||||
@@ -86,21 +86,21 @@ class TokenHexString(Token[bytes]):
|
|||||||
|
|
||||||
class TokenInteger(Token[int]):
|
class TokenInteger(Token[int]):
|
||||||
"""Token representing PDF integers
|
"""Token representing PDF integers
|
||||||
Detection of this type of token can be found in PDF 1.7
|
Detection of this type of token can be found in PDF 1.7 spec section 7.3.3
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TokenDecimal(Token[Decimal]):
|
class TokenReal(Token[Decimal]):
|
||||||
"""Token representing PDF decimals
|
"""Token representing PDF decimals
|
||||||
Detection of this type of token can be found in PDF 1.7
|
Detection of this type of token can be found in PDF 1.7 spec section 7.3.3
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
TokenNumber = Union[TokenInteger, TokenDecimal]
|
TokenNumber = Union[TokenInteger, TokenReal]
|
||||||
|
|
||||||
|
|
||||||
class TDictValue(Enum):
|
class TDictValue(Enum):
|
||||||
|
|||||||
+8
-8
@@ -19,7 +19,7 @@ from pdfmajor.lexer.token import (
|
|||||||
TokenArray,
|
TokenArray,
|
||||||
TokenBoolean,
|
TokenBoolean,
|
||||||
TokenComment,
|
TokenComment,
|
||||||
TokenDecimal,
|
TokenReal,
|
||||||
TokenDictionary,
|
TokenDictionary,
|
||||||
TokenHexString,
|
TokenHexString,
|
||||||
TokenInteger,
|
TokenInteger,
|
||||||
@@ -192,7 +192,7 @@ class Basics(TestCase):
|
|||||||
with self.subTest(buf_end_loc=buf_size):
|
with self.subTest(buf_end_loc=buf_size):
|
||||||
buffer = make_stream_iter(b"0.120 + some invalid text", buf_size)
|
buffer = make_stream_iter(b"0.120 + some invalid text", buf_size)
|
||||||
token = parse_number(buffer)
|
token = parse_number(buffer)
|
||||||
self.assertIsInstance(token, TokenDecimal)
|
self.assertIsInstance(token, TokenReal)
|
||||||
self.assertEqual(token.start_loc, -1)
|
self.assertEqual(token.start_loc, -1)
|
||||||
self.assertEqual(token.value, Decimal("0.12"))
|
self.assertEqual(token.value, Decimal("0.12"))
|
||||||
self.assertEqual(token.end_loc, 5)
|
self.assertEqual(token.end_loc, 5)
|
||||||
@@ -294,8 +294,8 @@ func/a/b{(c)do*}def
|
|||||||
TokenInteger(start_loc=54, end_loc=55, value=0),
|
TokenInteger(start_loc=54, end_loc=55, value=0),
|
||||||
TokenInteger(start_loc=56, end_loc=58, value=1),
|
TokenInteger(start_loc=56, end_loc=58, value=1),
|
||||||
TokenInteger(start_loc=59, end_loc=61, value=-2),
|
TokenInteger(start_loc=59, end_loc=61, value=-2),
|
||||||
TokenDecimal(start_loc=62, end_loc=64, value=Decimal("0.5")),
|
TokenReal(start_loc=62, end_loc=64, value=Decimal("0.5")),
|
||||||
TokenDecimal(start_loc=65, end_loc=70, value=Decimal("1.234")),
|
TokenReal(start_loc=65, end_loc=70, value=Decimal("1.234")),
|
||||||
TokenString(start_loc=71, end_loc=76, value="abc"),
|
TokenString(start_loc=71, end_loc=76, value="abc"),
|
||||||
TokenString(start_loc=77, end_loc=79, value=""),
|
TokenString(start_loc=77, end_loc=79, value=""),
|
||||||
TokenString(start_loc=80, end_loc=97, value="abc ( def ) ghi"),
|
TokenString(start_loc=80, end_loc=97, value="abc ( def ) ghi"),
|
||||||
@@ -339,13 +339,13 @@ func/a/b{(c)do*}def
|
|||||||
0 +1 -2 .5 1.234
|
0 +1 -2 .5 1.234
|
||||||
-1.234 990 """,
|
-1.234 990 """,
|
||||||
expected=[
|
expected=[
|
||||||
TokenDecimal(start_loc=0, end_loc=5, value=Decimal("10.32")),
|
TokenReal(start_loc=0, end_loc=5, value=Decimal("10.32")),
|
||||||
TokenInteger(start_loc=6, end_loc=7, value=0),
|
TokenInteger(start_loc=6, end_loc=7, value=0),
|
||||||
TokenInteger(start_loc=8, end_loc=10, value=1),
|
TokenInteger(start_loc=8, end_loc=10, value=1),
|
||||||
TokenInteger(start_loc=11, end_loc=13, value=-2),
|
TokenInteger(start_loc=11, end_loc=13, value=-2),
|
||||||
TokenDecimal(start_loc=14, end_loc=16, value=Decimal("0.5")),
|
TokenReal(start_loc=14, end_loc=16, value=Decimal("0.5")),
|
||||||
TokenDecimal(start_loc=17, end_loc=22, value=Decimal("1.234")),
|
TokenReal(start_loc=17, end_loc=22, value=Decimal("1.234")),
|
||||||
TokenDecimal(start_loc=23, end_loc=29, value=Decimal("-1.234")),
|
TokenReal(start_loc=23, end_loc=29, value=Decimal("-1.234")),
|
||||||
TokenInteger(start_loc=30, end_loc=33, value=990),
|
TokenInteger(start_loc=30, end_loc=33, value=990),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user