From a8fadefcc067970c5d5cb7b9e1588e6e3d83daf1 Mon Sep 17 00:00:00 2001 From: Terry Yin Date: Fri, 31 Jan 2025 16:40:19 +0800 Subject: [PATCH] commonize --- lizard_languages/jsx.py | 10 ++++++++++ lizard_languages/tsx.py | 14 +------------- prompt-history.md | 6 +++++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lizard_languages/jsx.py b/lizard_languages/jsx.py index 3b0113ba..1ae8173c 100644 --- a/lizard_languages/jsx.py +++ b/lizard_languages/jsx.py @@ -23,6 +23,16 @@ def generate_tokens(source_code, addition='', token_class=None): for tok in js_tokenizer(token): yield tok + def _expecting_func_opening_bracket(self, token): + if token == '<': + self.next(self._expecting_jsx) + return + super()._expecting_func_opening_bracket(token) + + def _expecting_jsx(self, token): + if token == '>': + self.next(self._expecting_func_opening_bracket) + class JSXReader(JavaScriptReader, JSXMixin): # pylint: disable=R0903 diff --git a/lizard_languages/tsx.py b/lizard_languages/tsx.py index 8fdf6892..32fbdb96 100644 --- a/lizard_languages/tsx.py +++ b/lizard_languages/tsx.py @@ -22,16 +22,4 @@ def generate_tokens(source_code, addition='', token_class=None): def __init__(self, context): super(TSXReader, self).__init__(context) - self.parallel_states = [TSXStates(context)] - - -class TSXStates(TypeScriptStates): - def _expecting_func_opening_bracket(self, token): - if token == '<': - self.next(self._expecting_jsx) - return - super(TSXStates, self)._expecting_func_opening_bracket(token) - - def _expecting_jsx(self, token): - if token == '>': - self.next(self._expecting_func_opening_bracket) \ No newline at end of file + # No need for parallel states since JSX handling is in the mixin \ No newline at end of file diff --git a/prompt-history.md b/prompt-history.md index 844fac39..f0a22df9 100644 --- a/prompt-history.md +++ b/prompt-history.md @@ -47,4 +47,8 @@ It looks like the XMLTagWithAttrTokenizer from @javascript.py belongs to @jsx.py --------- -@tsx.py @jsx.py should be doing very similar things. please refactor to remove the duplicate, inccluding conceptually duplicate code. \ No newline at end of file +@tsx.py @jsx.py should be doing very similar things. please refactor to remove the duplicate, inccluding conceptually duplicate code. + +--------- + +@tsx.py and@jsx.py should be doing very similar things. But TSX has a TSXStates as parallel_states, but JSX doesn't need one. Why? please commonize the solution. \ No newline at end of file