diff --git a/src/bootstraparse/modules/config.py b/src/bootstraparse/modules/config.py index 20eb837..ab645aa 100644 --- a/src/bootstraparse/modules/config.py +++ b/src/bootstraparse/modules/config.py @@ -1,4 +1,7 @@ # Interprets config files +# You probably want to go to environment to get the loaded config +# The ConfigLoader class has load_from_file and load_from_folder methods and __getitem__ for accessing loaded elements + import os import yaml from bootstraparse.modules import error_mngr diff --git a/src/bootstraparse/modules/context_mngr.py b/src/bootstraparse/modules/context_mngr.py index 1893721..c37760d 100644 --- a/src/bootstraparse/modules/context_mngr.py +++ b/src/bootstraparse/modules/context_mngr.py @@ -1,4 +1,12 @@ # Interprets where the parser is located and resolves errors +# You're probably here for the ContextManager class. +# Containers have class_name, debug_map and validate methods for debug, +# self.content: accessible via __getitem__, __setitem__, add, __len__, __iter__ and __getslice__. +# self.optionals: accessible via __rshift__ (remapped to return self.map[other]()) +# and self.map: accessible via __invert__ (remapped to return self.optionals) +import rich + + class BaseContainer: """ Creates container holding all the elements from the start of a parsed element to its end. @@ -117,7 +125,87 @@ class EtEmContainer(BaseContainer): pass +class EtStrongContainer(BaseContainer): + pass + + +class EtUnderlineContainer(BaseContainer): + pass + + +class EtStrikethroughContainer(BaseContainer): + pass + + +class IlLinkContainer(BaseContainer): + def __init__(self): + self.map += {'url': ""} + pass + + +class IlImageContainer(BaseContainer): + pass + + +class SeDivContainer(BaseContainer): + pass + + +class SeArticleContainer(BaseContainer): + pass + + +class SeAsideContainer(BaseContainer): + pass + + +class SeSectionContainer(BaseContainer): + pass + + +class SeHeaderContainer(BaseContainer): + def __init__(self): + self.map += {'header_level': ""} + pass + + +class SeDisplayContainer(BaseContainer): + def __init__(self): + self.map += {'display_level': ""} + pass + + +class TableMainContainer(BaseContainer): + pass + + +class TableHeadContainer(BaseContainer): + def __init__(self): + self.map += {'colspan': ""} + pass + + +class TableRowContainer(BaseContainer): + def __init__(self): + self.map += {'colspan': ""} + pass + + +class TableCellContainer(BaseContainer): + def __init__(self): + self.map += {'colspan': ""} + pass + + class ContextManager: pass # Defines all methods to manage the context of the parser as a file is being parsed # Builds all containers as the parser is parsing the file + + +if __name__ == "__main__": + from bootstraparse.modules import parser + from io import StringIO + io_string = StringIO('test') + test = parser.parse_line(io_string) + # rich.print(test) diff --git a/src/bootstraparse/modules/environment.py b/src/bootstraparse/modules/environment.py index 2356ff4..0213015 100644 --- a/src/bootstraparse/modules/environment.py +++ b/src/bootstraparse/modules/environment.py @@ -1,4 +1,7 @@ # Module for containing super important variables +# Environment has self._mParams for mandatory parameters, self._sParams for secondary parameters and +# self.wasInitialised and integrity_check for debug. +# __getattr__ and __setattr__ check for existing super, s or m parameters, returns error if not found. from bootstraparse.modules import error_mngr diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index b3092e0..98ed038 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -1,4 +1,7 @@ # Dedicated module for defining and interpreting errors as well as generating error messages +# You're probably here for log_message or log_exception. +# They take: message, level="ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL" +# There's also a dict_check(dic, *args) that returns true if all args are keys in the dict. import logging import traceback diff --git a/src/bootstraparse/modules/export.py b/src/bootstraparse/modules/export.py index 1bdb210..fbfd446 100644 --- a/src/bootstraparse/modules/export.py +++ b/src/bootstraparse/modules/export.py @@ -1,4 +1,5 @@ # Module for final generation of the translated website +# Everything seems important :( from bootstraparse.modules import config, pathresolver, error_mngr from collections import namedtuple diff --git a/src/bootstraparse/modules/parser.py b/src/bootstraparse/modules/parser.py index 06ae106..74ca144 100644 --- a/src/bootstraparse/modules/parser.py +++ b/src/bootstraparse/modules/parser.py @@ -1 +1,35 @@ -# Main parser, interprets userfiles and translates into html +# Main parser, gets config files and parses them for the context manager. +# parse_line takes a io and outputs it all as a list of parsed elements +# TODO: decide the parser scope +from io import StringIO + +import rich + +import bootstraparse.modules.syntax as syntax + + +def parse_line(io): + """ + Takes an io string and returns the parsed output. + :param io: io.StringIO + :params + :io: io string input + :rtype: list + :return: a list of parsed objects + """ + output = [] + for line in io.readlines(): + output += syntax.line.parseString(line).asList() + [syntax.Linebreak('')] + + return output + + +if __name__ == "__main__": + hello = StringIO( + """ + *hellooooooooooooooooooooooooooooooooooooooooooooooooo* + my name is **bernard** + # hello # + """ + ) + print(parse_line(hello)) diff --git a/src/bootstraparse/modules/pathresolver.py b/src/bootstraparse/modules/pathresolver.py index 67af985..00eb51a 100644 --- a/src/bootstraparse/modules/pathresolver.py +++ b/src/bootstraparse/modules/pathresolver.py @@ -1,4 +1,6 @@ # Module for resolving relative path problems +# PathResolver takes a relative path in the module and outputs the absolute path, +# BoostraPath can deal with relative paths in the installation folder. # import pathlib import os diff --git a/src/bootstraparse/modules/preparser.py b/src/bootstraparse/modules/preparser.py index 64794fd..586e99c 100644 --- a/src/bootstraparse/modules/preparser.py +++ b/src/bootstraparse/modules/preparser.py @@ -1,4 +1,5 @@ # Module for pre-parsing user files in preparation for the parser +# the PreParser has all the methods you want and probably a lot more pls help import os import regex # future: remove regex from io import StringIO diff --git a/src/bootstraparse/modules/syntax.py b/src/bootstraparse/modules/syntax.py index c5eb4fc..888b10c 100644 --- a/src/bootstraparse/modules/syntax.py +++ b/src/bootstraparse/modules/syntax.py @@ -1,4 +1,7 @@ # Dedicated module for the syntax of all the parsing +# All tokens inherit a SemanticType among SemanticType, ExplicitSemanticType and EmptySemanticType +# All tokens have a label, and __eq__ and __ne__ methods. +# Note: there is an UnimplementedToken import os from itertools import zip_longest from collections import namedtuple @@ -194,6 +197,10 @@ class BlockQuoteAuthorToken(SemanticType): label = "bq:author" +class Linebreak(ExplicitSemanticType): + label = "linebreak" + + def of_type(token_class): """ Function creating a custom function for generating the given Token type.