From b1515fb303a0d0edfa91469f0aa98291ed0fa88f Mon Sep 17 00:00:00 2001 From: Robert Spralja Date: Thu, 7 Apr 2022 17:27:06 +0200 Subject: [PATCH 1/3] Added docstrings for __main__ Includes 'pychart --help' output --- src/pychart/__main__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pychart/__main__.py b/src/pychart/__main__.py index 0885e02..cda3902 100644 --- a/src/pychart/__main__.py +++ b/src/pychart/__main__.py @@ -4,6 +4,18 @@ from .runner import run_prompt, run_file def main(): + """ + The default entrypoint for the pychart-lang + + usage: pychart [-h] [--version] [file] + + positional arguments: + file run a pychart file + + optional arguments: + -h, --help show this help message and exit + --version, -V + """ parser = argparse.ArgumentParser(prog='pychart') parser.add_argument('file', nargs='?', help='run a pychart file') parser.add_argument('--version', '-V', action='store_true') From 510fa362a4dba53576de299ad6a027477c32ff7b Mon Sep 17 00:00:00 2001 From: Robert Spralja Date: Tue, 10 May 2022 17:10:13 +0200 Subject: [PATCH 2/3] Docs: Scanner --- src/pychart/_interpreter/scanner.py | 35 +++++++++++++++++++++++++++++ src/pychart/runner.py | 3 +++ 2 files changed, 38 insertions(+) diff --git a/src/pychart/_interpreter/scanner.py b/src/pychart/_interpreter/scanner.py index a2919b5..b08bd05 100644 --- a/src/pychart/_interpreter/scanner.py +++ b/src/pychart/_interpreter/scanner.py @@ -36,12 +36,20 @@ class Scanner: } def __init__(self, program_text: str): + """ + program_text: str - The source text to turn into tokens + """ self.source = program_text def __is_at_end(self) -> bool: + """Checks whether the pointer has reached EOF""" return self.current >= len(self.source) def __advance(self) -> str: + """ + advances the pointer + returns the current character + """ char = self.source[self.current] self.current += 1 return char @@ -51,6 +59,10 @@ def __add_token(self, token_type: TokenType, literal: Any = None): self.tokens.append(Token(token_type, text, literal, self.line)) def __match(self, char: str) -> bool: + """ + Checks whether the next character is char, and advances the pointer + returns True if the next character is char, False otherwise + """ if self.__is_at_end(): return False @@ -61,17 +73,24 @@ def __match(self, char: str) -> bool: return True def __peek(self) -> str: + """ + returns the following character + """ if self.__is_at_end(): return "\0" return self.source[self.current] def __peek_next(self) -> str: + """ Same as __peek but one simulated advance in the future""" if self.current + 1 >= len(self.source): return "\0" return self.source[self.current + 1] def __string(self): + """ + Scans a string literal which is exactly the characters between two quotation marks (") + """ while self.__peek() != '"' and not self.__is_at_end(): if self.__peek() == "\n": self.line += 1 @@ -86,6 +105,10 @@ def __string(self): self.__add_token(TokenType.STRING, value) def __number(self): + """ + Scans a number literal (base 10) defined as any alpha string + (including leading zeros and any number of characters) and is stored as a float + """ while self.__peek().isdigit(): self.__advance() @@ -99,6 +122,10 @@ def __number(self): ) def __identifier(self): + """ + Scans a identifier which is an alphanumeric string of any lengths starting with + a letter + """ while self.__peek().isalnum(): self.__advance() @@ -159,10 +186,15 @@ def __scan_token(self): while self.__peek() != "\n" and not self.__is_at_end(): self.__advance() else: + # Division (Slash) self.__add_token(TokenType.SLASH) # Whitespace elif char == " " or char == "\r" or char == "\t": + """ + note: + could be replaced with a char in frozenset({' ', '\r', '\t'}) could be more efficient + """ # Ignore whitespace pass elif char == "\n": @@ -176,9 +208,12 @@ def __scan_token(self): elif char.isalpha(): self.__identifier() else: + """ Should throw error currently characters like '$', '#' are just ignored""" pass # Throw error -> unrecognised token def get_tokens(self) -> List[Token]: + """Turns the source text used into a list of tokens""" + if len(self.tokens) != 0: self.tokens = [] diff --git a/src/pychart/runner.py b/src/pychart/runner.py index acab04f..c2cffd5 100644 --- a/src/pychart/runner.py +++ b/src/pychart/runner.py @@ -41,6 +41,9 @@ def run(source: str): def run_prompt(): + """ + REPL entrypoint, exit with ".exit" + """ try: while True: line = input("$ : ") From f5b15ede752898a3765cf3b8f6fe68c9ef851e51 Mon Sep 17 00:00:00 2001 From: Robert Spralja Date: Mon, 16 May 2022 11:53:02 +0200 Subject: [PATCH 3/3] Docs: removed some comments they were changed into an issue --- src/pychart/_interpreter/scanner.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pychart/_interpreter/scanner.py b/src/pychart/_interpreter/scanner.py index b08bd05..a251d04 100644 --- a/src/pychart/_interpreter/scanner.py +++ b/src/pychart/_interpreter/scanner.py @@ -191,10 +191,6 @@ def __scan_token(self): # Whitespace elif char == " " or char == "\r" or char == "\t": - """ - note: - could be replaced with a char in frozenset({' ', '\r', '\t'}) could be more efficient - """ # Ignore whitespace pass elif char == "\n": @@ -208,7 +204,6 @@ def __scan_token(self): elif char.isalpha(): self.__identifier() else: - """ Should throw error currently characters like '$', '#' are just ignored""" pass # Throw error -> unrecognised token def get_tokens(self) -> List[Token]: