exceptions
This commit is contained in:
parent
e3ca0d396d
commit
874fb84957
17
bu4/evaluation/constructs/eexception.py
Normal file
17
bu4/evaluation/constructs/eexception.py
Normal 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()}»'
|
20
bu4/linking/constructs/lexception.py
Normal file
20
bu4/linking/constructs/lexception.py
Normal 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()}»'
|
@ -8,3 +8,4 @@ CODE_SKIP = 4
|
||||
CODE_QUOT = 5
|
||||
CODE_QOPN = 6
|
||||
CODE_QCLS = 7
|
||||
CODE_XCPT = 8
|
||||
|
16
bu4/parsing/constructs/pexception.py
Normal file
16
bu4/parsing/constructs/pexception.py
Normal 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))
|
16
bu4/parsing/extensions/xxcpt.py
Normal file
16
bu4/parsing/extensions/xxcpt.py
Normal 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
|
@ -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())))
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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()
|
||||
|
20
src/binary/comparison/eq.bu4
Normal file
20
src/binary/comparison/eq.bu4
Normal 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
|
||||
}
|
@ -1 +1 @@
|
||||
{ (g) /? /? /? /? /[1][g] | dequeEmpty }
|
||||
{ (g) /«deque_empty» /«deque_empty» /«deque_empty» /«deque_empty» /[1][g] | dequeEmpty }
|
||||
|
@ -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 }
|
||||
|
@ -4,9 +4,9 @@
|
||||
/
|
||||
[input]
|
||||
/
|
||||
?
|
||||
«simple_input_has_no_outSys»
|
||||
/
|
||||
?
|
||||
«simple_input_has_no_outBit»
|
||||
/
|
||||
[1]
|
||||
[system]
|
||||
|
Loading…
Reference in New Issue
Block a user