From c7974ffe077ccd672d7f5c3a89fca668f8f175d3 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Sat, 28 May 2022 16:36:02 +0200 Subject: [PATCH] Added a couple of docs --- src/bootstraparse/modules/parser.py | 13 ++++++++----- src/bootstraparse/modules/pathresolver.py | 5 ++++- src/bootstraparse/modules/preparser.py | 10 +++++++++- src/bootstraparse/modules/syntax.py | 7 +++++++ src/bootstraparse/modules/tools.py | 12 +++++++++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/bootstraparse/modules/parser.py b/src/bootstraparse/modules/parser.py index bfc9fdb..338d4e5 100644 --- a/src/bootstraparse/modules/parser.py +++ b/src/bootstraparse/modules/parser.py @@ -1,5 +1,9 @@ # 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 +# Usage: +# from bootstraparse.modules.parser import parse_line +# parse_line(io) -> [element, element, element] + # TODO: decide the parser scope from io import StringIO @@ -9,11 +13,10 @@ 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 + Parameters: + io (StringIO): The io string to parse. + Returns: + list[syntax.SemanticType]: The parsed output. """ output = [] for line in io.readlines(): diff --git a/src/bootstraparse/modules/pathresolver.py b/src/bootstraparse/modules/pathresolver.py index 00eb51a..51c166a 100644 --- a/src/bootstraparse/modules/pathresolver.py +++ b/src/bootstraparse/modules/pathresolver.py @@ -1,8 +1,11 @@ # 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. +# Usage: +# from bootstraparse.modules.pathresolver import PathResolver, b_path +# b_path("../relative/path/to/file") # returns absolute path to file from the bootstraparse folder +# path= PathResolver("../relative/path/to/file") # Make a PathResolver object pointing at the first path given -# import pathlib import os diff --git a/src/bootstraparse/modules/preparser.py b/src/bootstraparse/modules/preparser.py index d8283cb..4b5ac94 100644 --- a/src/bootstraparse/modules/preparser.py +++ b/src/bootstraparse/modules/preparser.py @@ -1,5 +1,13 @@ # 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 +# Usage: +# from bootstraparse.modules.preparser import preparser +# pp = preparser(file, enviroment) +# pp.do_import() # imports all the modules and adds them to the file, do the same for all the files that are to be imported +# pp.do_replacements() # replaces all images and shortcuts in the file +# pp.readlines() # returns the lines of ORIGINAL file +# pp.get_all_lines() # returns the lines of the file after replacements and imports + + 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 31da602..8c060de 100644 --- a/src/bootstraparse/modules/syntax.py +++ b/src/bootstraparse/modules/syntax.py @@ -2,6 +2,13 @@ # 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 +# Usage: +# from bootstraparse.modules.syntax import line +# line.parse_line('string') # returns a List of tokens +# line_to_replace.parse_line('string') # returns a List of tokens parsed for replacements +# imports.parse_line('string', True) # returns a List of tokens parsed for imports # FUTURE: Not implemented yet +# any_token.create_diagram("filename") # Debugging + import os from itertools import zip_longest from collections import namedtuple diff --git a/src/bootstraparse/modules/tools.py b/src/bootstraparse/modules/tools.py index eda6a45..7ec6747 100644 --- a/src/bootstraparse/modules/tools.py +++ b/src/bootstraparse/modules/tools.py @@ -1,11 +1,17 @@ +############################################################################### +# List of tools for testing +############################################################################### +# Usage: +# from bootstraparse.modules.tools import __GLk, __GL, find_*_in_file +# __GLk(n) # Returns a file link n traceback objects back +# __GL() # Returns a line number at current position +# find_*_in_file(file) # Try to find (class, function or variable) in file and return it's line number + import inspect import os import re -############################################################################### -# List of tools for testing -############################################################################### ############################################################################### # Paths ########################################