Skip to content
Snippets Groups Projects
Commit 1816bf46 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Remove ParserFormatter's constructor.

All state held in that class is apparently now moved to the
ParserCombinator which uses the serialized output

Possibly change all methods in the class to be class/static methods
instead in the future.
parent db52c7b8
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,7 @@ def parse_puppet(source: str, file: str) -> str: ...@@ -98,7 +98,7 @@ def parse_puppet(source: str, file: str) -> str:
ast = build_ast(puppet_parser(source)) ast = build_ast(puppet_parser(source))
# logger.info("ast: %a", ast) # logger.info("ast: %a", ast)
# From the ast, build a parser combinator parser. # From the ast, build a parser combinator parser.
parser = ParserFormatter(source, file=file).serialize(ast) parser = ParserFormatter().serialize(ast)
# logger.warning("parser: %a", parser) # logger.warning("parser: %a", parser)
# Run the generatefd parser, giving us a list of match objects # Run the generatefd parser, giving us a list of match objects
match_objects = ParserCombinator(source, file).get(parser) match_objects = ParserCombinator(source, file).get(parser)
......
...@@ -201,25 +201,7 @@ class rich_char(ParseDirective): ...@@ -201,25 +201,7 @@ class rich_char(ParseDirective):
class ParserFormatter(Serializer[ParseDirective]): class ParserFormatter(Serializer[ParseDirective]):
""" """Reserialize AST by highlighting the original source code."""
Reserialize AST by highlighting the original source code.
:param source:
The original source code. *Must* be the exact same source as
used to construct the corresponinding Puppet ast object.
:param seek:
Current parsing position in the string.
TODO make this private.
"""
# parser: ParserCombinator
# def __init__(self, source: str, file: Optional[str] = None):
def __init__(self, source: str, file: str):
# self.parser = ParserCombinator(source=source, file=file)
self.file = file
pass
def declaration_parameter(self, item: PuppetDeclarationParameter) -> ParseDirective: def declaration_parameter(self, item: PuppetDeclarationParameter) -> ParseDirective:
"""Build parser for the given declaration parameter.""" """Build parser for the given declaration parameter."""
...@@ -683,7 +665,6 @@ class ParserFormatter(Serializer[ParseDirective]): ...@@ -683,7 +665,6 @@ class ParserFormatter(Serializer[ParseDirective]):
parser = (single_quoted | double_quoted) parser = (single_quoted | double_quoted)
else: else:
parser = (raw_string | single_quoted | double_quoted) parser = (raw_string | single_quoted | double_quoted)
# TODO should the whitespace really be here?
return ws & tag('string', name(it.s, parser)) return ws & tag('string', name(it.s, parser))
@override @override
......
...@@ -95,7 +95,7 @@ def parse_string(s: str, *, ...@@ -95,7 +95,7 @@ def parse_string(s: str, *,
if ast: if ast:
assert generated_ast == ast assert generated_ast == ast
parser = ParserFormatter(s, "s").serialize(generated_ast) parser = ParserFormatter().serialize(generated_ast)
print() print()
pprint(parser) pprint(parser)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment