Initial commit - fix problems & refactor code
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
from core.environment import IGNORE, MEANINGFUL
|
||||
import re
|
||||
|
||||
def processString(source: str) -> str:
|
||||
"""Remove blank characters and comments from source code.
|
||||
|
||||
Args:
|
||||
source: The source code string.
|
||||
|
||||
Returns:
|
||||
The cleaned source code.
|
||||
"""
|
||||
source = source.lstrip(IGNORE)
|
||||
|
||||
while source and source[0] == ";":
|
||||
line_end: int = source.find("\n")
|
||||
|
||||
if line_end < 0:
|
||||
return ""
|
||||
|
||||
source = source[line_end:].lstrip(IGNORE)
|
||||
|
||||
return source
|
||||
|
||||
|
||||
def findPrefix(source: str, separators: str = IGNORE + MEANINGFUL) -> str:
|
||||
"""Find a meaningful prefix (token) in the source string.
|
||||
|
||||
Args:
|
||||
source: The source code string.
|
||||
separators: Characters that mark token boundaries.
|
||||
|
||||
Returns:
|
||||
The prefix token found, or empty string if none.
|
||||
"""
|
||||
pattern: str = rf"^[^{separators}]*"
|
||||
match = re.match(pattern, source)
|
||||
return match.group(0) if match else ""
|
||||
Reference in New Issue
Block a user