add some error handling
This commit is contained in:
parent
a22c430555
commit
b70abdc286
2 changed files with 33 additions and 3 deletions
29
PyTeX/format/errors.py
Normal file
29
PyTeX/format/errors.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
class PyTeXError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class PyTeXFormattingError(PyTeXError):
|
||||
pass
|
||||
|
||||
|
||||
class PyTeXBuildError(PyTeXError):
|
||||
pass
|
||||
|
||||
|
||||
class PyTeXMacroError(PyTeXError):
|
||||
pass
|
||||
|
||||
|
||||
class PyTeXInvalidMacroUsageError(PyTeXMacroError):
|
||||
pass
|
||||
|
||||
|
||||
class PyTeXInvalidBeginMacroCodeUsageError(PyTeXInvalidMacroUsageError):
|
||||
pass
|
||||
|
||||
|
||||
class PyTeXInvalidEndMacroCodeUsageError(PyTeXInvalidMacroUsageError):
|
||||
pass
|
||||
|
||||
|
|
@ -4,6 +4,7 @@ from typing import List, Union, Tuple, Dict
|
|||
from .constants import *
|
||||
from .enums import FormatterProperty, Argument, FormatterMode
|
||||
from abc import ABC, abstractmethod
|
||||
from .errors import *
|
||||
|
||||
|
||||
class MacroReplacement:
|
||||
|
@ -134,7 +135,7 @@ class ConfigBeginMacro(SingleLineMacro):
|
|||
super(ConfigBeginMacro, self).__init__(FORMATTER_PREFIX + INFILE_CONFIG_BEGIN_CONFIG)
|
||||
|
||||
def _apply(self, line: str, formatter) -> Union[str, List[str]]:
|
||||
if not formatter.mode == FormatterMode.normal:
|
||||
if formatter.mode not in [FormatterMode.normal, FormatterMode.meta]:
|
||||
raise NotImplementedError # invalid config begin
|
||||
formatter.mode = FormatterMode.drop
|
||||
return []
|
||||
|
@ -157,7 +158,7 @@ class MacroCodeBeginMacro(SingleLineMacro):
|
|||
|
||||
def _apply(self, line: str, formatter) -> Union[str, List[str]]:
|
||||
if not formatter.mode == FormatterMode.meta:
|
||||
raise NotImplementedError
|
||||
raise PyTeXInvalidBeginMacroCodeUsageError
|
||||
formatter.mode = FormatterMode.macrocode
|
||||
return r'% \begin{macrocode}'
|
||||
|
||||
|
@ -168,7 +169,7 @@ class MacroCodeEndMacro(SingleLineMacro):
|
|||
|
||||
def _apply(self, line: str, formatter) -> Union[str, List[str]]:
|
||||
if not formatter.mode == FormatterMode.macrocode:
|
||||
raise NotImplementedError
|
||||
raise PyTeXInvalidEndMacroCodeUsageError
|
||||
formatter.mode = FormatterMode.meta
|
||||
return r'% \end{macrocode}'
|
||||
|
||||
|
|
Loading…
Reference in a new issue