# fixer.py
content = """import re

class Lexer:
    def __init__(self, code):
        self.code = code
        self.tokens = []
        self.pos = 0
        self.rules = [
            ('COMMENT', r'--\[\[.*?\].*?--.*'),
            ('STRING', r'\"(?:\\.|[^\"\\])*\"|\'(?:\\.|[^\'\])*\'|\\[\\[.*?\\]\\].*?'),
            ('NUMBER', r'\d+\.?\d*'),
            ('KEYWORD', r'\b(and|break|do|else|elseif|end|false|for|function|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b'),
            ('IDENT', r'[a-zA-Z_][a-zA-Z0-9_]*'),
            ('OP', r'==|~=|<=|>=|\.\.\.|\.\.|>>|<<|[\+\-\*/%^#=\<\>\(\)\{\}\[\];:,.\.]'),
            ('SPACE', r'\s+')
        ]

    def tokenize(self):
        while self.pos < len(self.code):
            match = None
            for name, pattern in self.rules:
                regex = re.compile(pattern, re.DOTALL)
                match = regex.match(self.code, self.pos)
                if match:
                    if name != 'SPACE' and name != 'COMMENT':
                        self.tokens.append((name, match.group(0)))
                    self.pos = match.end()
                    break
            if not match:
                self.pos += 1
        return self.tokens

class Parser:
    def __init__(self, tokens):
        self.tokens = tokens
        self.pos = 0

    def peek(self):
        return self.tokens[self.pos] if self.pos < len(self.tokens) else (None, None)

    def consume(self, expected_type=None):
        token = self.peek()
        if expected_type and token[0] != expected_type:
            return None
        self.pos += 1
        return token

    def parse(self):
        nodes = []
        while self.pos < len(self.tokens):
            node = self.parse_statement()
            if node:
                nodes.append(node)
            else:
                self.pos += 1
        return nodes

    def parse_statement(self):
        token = self.peek()
        if token[0] == 'IDENT':
            ident = self.consume()[1]
            next_token = self.peek()
            if next_token[1] == '(':
                self.consume()
                args = []
                while self.peek()[1] != ')':
                    args.append(self.peek()[1])
                    self.consume()
                    if self.peek()[1] == ',':
                        self.consume()
                self.consume()
                return {'type': 'call', 'name': ident, 'args': args}
            elif next_token[1] == '=':
                self.consume()
                value = self.consume()[1]
                return {'type': 'assign', 'name': ident, 'value': value}
        return None
"""
with open("core/parser.py", "w") as f:
    f.write(content)

