fix parsing tex type and flavour

This commit is contained in:
Maximilian Keßler 2022-02-09 11:55:18 +01:00
parent 5a5f0ef1e4
commit c04897c26c
4 changed files with 16 additions and 11 deletions

View file

@ -1,6 +1,6 @@
from __future__ import annotations
from enum import Enum from enum import Enum
from typing import Optional
from PyTeX.format.macros import MacroReplacementAtomIF
class NamingScheme(Enum): class NamingScheme(Enum):
@ -16,7 +16,9 @@ class TeXType(Enum):
TeXDocumentation = 'TeXDocumentation' TeXDocumentation = 'TeXDocumentation'
@staticmethod @staticmethod
def parse(tex_type: str): def parse(tex_type: str) -> Optional[TeXType]:
if tex_type is None:
return None
switcher = { switcher = {
'package': TeXType.TeXPackage, 'package': TeXType.TeXPackage,
'sty': TeXType.TeXPackage, 'sty': TeXType.TeXPackage,
@ -42,7 +44,9 @@ class TeXFlavour(Enum):
LaTeX3 = 'LaTeX3' LaTeX3 = 'LaTeX3'
@staticmethod @staticmethod
def parse(flavour: str): def parse(flavour: str) -> Optional[TeXFlavour]:
if flavour is None:
return None
switcher = { switcher = {
'1': TeXFlavour.TeX, '1': TeXFlavour.TeX,
'2': TeXFlavour.LaTeX2e, '2': TeXFlavour.LaTeX2e,
@ -50,6 +54,7 @@ class TeXFlavour(Enum):
'3': TeXFlavour.LaTeX3, '3': TeXFlavour.LaTeX3,
'TeX': TeXFlavour.TeX, 'TeX': TeXFlavour.TeX,
'LaTeX2e': TeXFlavour.LaTeX2e, 'LaTeX2e': TeXFlavour.LaTeX2e,
'LaTeX2': TeXFlavour.LaTeX2e,
'LateX3': TeXFlavour.LaTeX3 'LateX3': TeXFlavour.LaTeX3
} }
if flavour not in switcher.keys(): if flavour not in switcher.keys():
@ -58,6 +63,10 @@ class TeXFlavour(Enum):
return switcher[flavour] return switcher[flavour]
class MacroReplacementAtomIF:
pass
class FormatterProperty(MacroReplacementAtomIF, Enum): class FormatterProperty(MacroReplacementAtomIF, Enum):
author = 'author' author = 'author'
shortauthor = 'shortauthor' shortauthor = 'shortauthor'

View file

@ -89,8 +89,8 @@ class FormattingConfig(Config):
info = filled_content[YAML_INFO] info = filled_content[YAML_INFO]
self._author = info[YAML_AUTHOR] self._author = info[YAML_AUTHOR]
self._naming_scheme = info[YAML_NAMING_SCHEME] self._naming_scheme = info[YAML_NAMING_SCHEME]
self._tex_flavour = info[YAML_TEX_FLAVOUR] self._tex_flavour = TeXFlavour.parse(info[YAML_TEX_FLAVOUR])
self._tex_type = info[YAML_TEX_TYPE] self._tex_type = TeXType.parse(info[YAML_TEX_TYPE])
self._description = info[YAML_DESCRIPTION] self._description = info[YAML_DESCRIPTION]
self._version = info[YAML_VERSION] self._version = info[YAML_VERSION]

View file

@ -5,10 +5,6 @@ from .constants import *
from .enums import FormatterProperty, Argument from .enums import FormatterProperty, Argument
class MacroReplacementAtomIF:
pass
class MacroReplacement: class MacroReplacement:
def __init__( def __init__(
self, self,

View file

@ -1,6 +1,6 @@
import re import re
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional, Dict
from .constants import * from .constants import *
from .formatterif import FormatterIF from .formatterif import FormatterIF