exceptions

This commit is contained in:
AF 2021-08-20 06:12:04 +03:00
parent e3ca0d396d
commit 874fb84957
12 changed files with 101 additions and 7 deletions

View File

@ -0,0 +1,17 @@
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
from bu4.evaluation.constructs.evaluable import Evaluable
from bu4.evaluation.constructs.evalue import EValue
__all__ = ('EException',)
class EException(EValue):
def __init__(self, name: bytes):
self.name = name
def call(self, argument: Evaluable) -> Evaluable:
return self
def __str__(self):
return f'«{self.name.decode()}»'

View File

@ -0,0 +1,20 @@
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
from bu4.evaluation.av.envtype import envtype
from bu4.evaluation.constructs.eexception import EException
from bu4.evaluation.constructs.evaluable import Evaluable
from bu4.linking.constructs.linked import Linked
__all__ = ('LException',)
class LException(Linked):
def __init__(self, name: bytes):
self.name = name
self.future = set()
def evaluable(self, env: envtype) -> Evaluable:
return EException(self.name)
def __str__(self):
return f'«{self.name.decode()}»'

View File

@ -8,3 +8,4 @@ CODE_SKIP = 4
CODE_QUOT = 5
CODE_QOPN = 6
CODE_QCLS = 7
CODE_XCPT = 8

View File

@ -0,0 +1,16 @@
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
__all__ = ('PException',)
from bu4.linking.constructs.lexception import LException
from bu4.linking.states.linkingfinished import LinkingFinished
from bu4.linking.states.linkingstate import LinkingState
from bu4.parsing.constructs.parsed import Parsed
class PException(Parsed):
def __init__(self, name: bytes):
self.name = name
def link(self, promise: set[bytes]) -> LinkingState:
return LinkingFinished(LException(self.name))

View File

@ -0,0 +1,16 @@
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
from bu4.parsing.codes import CODE_XCPT
from bu4.parsing.constructs.pexception import PException
from bu4.parsing.extensions.extension import Extension
from bu4.parsing.states.parsestate import ParseState
from bu4.parsing.states.psafter import PSAfter
from bu4.parsing.states.psfinal import PSFinal
__all__ = ('XXcpt',)
class XXcpt(Extension, code=CODE_XCPT):
def apply(self, state: PSAfter) -> ParseState:
state.state = PSFinal(PException(self.parser.parse_name()))
return state

View File

@ -8,7 +8,7 @@ __all__ = ('readfile',)
def readfile(path: str) -> str:
srcio = StringIO()
with open(path + '.bu4') as file:
with open(path + '.bu4', encoding='utf-8') as file:
for line in file:
if line.startswith('@'):
srcio.write(readfile(os.path.join(path, os.path.pardir, line.removeprefix('@').strip())))

View File

@ -7,6 +7,7 @@ from bu4.parsing.extensions.xnull import XNull
from bu4.parsing.extensions.xqopn import XQopn
from bu4.parsing.extensions.xquot import XQuot
from bu4.parsing.extensions.xskip import XSkip
from bu4.parsing.extensions.xxcpt import XXcpt
__all__ = ('standard_extension',)
@ -18,4 +19,5 @@ standard_extension = (
XSkip,
XQuot,
XQopn,
XXcpt,
)

View File

@ -26,7 +26,7 @@ def transply(source: str) -> bytes:
transplied.write(bytes([CODE_SKIP]))
elif c in '?':
transplied.write(bytes([CODE_QOPN, CODE_NULL, CODE_QCLS]))
elif c in ']':
elif c in ']»':
transplied.write(bytes([CODE_NULL, CODE_QCLS]))
elif c in '[':
transplied.write(bytes([CODE_QOPN, CODE_NAME]))
@ -36,7 +36,8 @@ def transply(source: str) -> bytes:
transplied.write(bytes([CODE_QOPN]))
elif c in '>':
transplied.write(bytes([CODE_QCLS]))
elif c in '«':
transplied.write(bytes([CODE_QOPN, CODE_XCPT]))
else:
value = c.encode()
transplied.write(value if len(value) == 1 else f'[{value.hex()}]'.encode())
transplied.write(c.encode())
return transplied.getvalue()

View File

@ -0,0 +1,20 @@
{
/(b_eq)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_eq]
/
/[lbB]/[lbA][xnor]
[and]
/
[zqB]
[zqA]
[bB]
[bA]
[YC]
|
b_eq
}

View File

@ -1 +1 @@
{ (g) /? /? /? /? /[1][g] | dequeEmpty }
{ (g) /«deque_empty» /«deque_empty» /«deque_empty» /«deque_empty» /[1][g] | dequeEmpty }

View File

@ -3,3 +3,4 @@
{ (x)(y) /[0]/[y][x] | and }
{ (x)(y) /[y]/[1][x] | or }
{ (x)(y) /[y]/</[y][not]>[x] | xor }
{ (x)(y) /</[y][not]>/[y][x] | xnor }

View File

@ -4,9 +4,9 @@
/
[input]
/
?
«simple_input_has_no_outSys»
/
?
«simple_input_has_no_outBit»
/
[1]
[system]