mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-17 23:13:03 +08:00
feat(autoscript): 支持 // 行内注释与完整注释行解析
This commit is contained in:
@@ -381,6 +381,20 @@ class ASTokenizer:
|
|||||||
stmt.op_type = OP_SUB
|
stmt.op_type = OP_SUB
|
||||||
return stmt
|
return stmt
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _stripComment(
|
||||||
|
cls,
|
||||||
|
line: str
|
||||||
|
) -> str:
|
||||||
|
|
||||||
|
in_single = False
|
||||||
|
for i, ch in enumerate(line):
|
||||||
|
if ch == "'":
|
||||||
|
in_single = not in_single
|
||||||
|
elif ch == "/" and i + 1 < len(line) and line[i + 1] == "/" and not in_single:
|
||||||
|
return line[:i].rstrip()
|
||||||
|
return line
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _tokenizeImpl(
|
def _tokenizeImpl(
|
||||||
cls,
|
cls,
|
||||||
@@ -389,11 +403,11 @@ class ASTokenizer:
|
|||||||
|
|
||||||
statements = []
|
statements = []
|
||||||
for raw_line in script.split("\n"):
|
for raw_line in script.split("\n"):
|
||||||
stripped = raw_line.strip()
|
code = cls._stripComment(raw_line.strip())
|
||||||
if not stripped:
|
if not code:
|
||||||
continue
|
continue
|
||||||
kind, data = cls._matchLine(stripped)
|
kind, data = cls._matchLine(code)
|
||||||
statements.append(cls._buildStmt(stripped, kind, data))
|
statements.append(cls._buildStmt(code, kind, data))
|
||||||
return statements
|
return statements
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -476,12 +490,12 @@ class ASTokenizer:
|
|||||||
cls._notifyObservers(observers, "onParseStart", script)
|
cls._notifyObservers(observers, "onParseStart", script)
|
||||||
statements = []
|
statements = []
|
||||||
for i, raw_line in enumerate(script.split("\n"), 1):
|
for i, raw_line in enumerate(script.split("\n"), 1):
|
||||||
stripped = raw_line.strip()
|
code = cls._stripComment(raw_line.strip())
|
||||||
if not stripped:
|
if not code:
|
||||||
continue
|
continue
|
||||||
kind, data = cls._matchLine(stripped)
|
kind, data = cls._matchLine(code)
|
||||||
cls._notifyObservers(observers, "onTokenParsed", kind, data, i, stripped)
|
cls._notifyObservers(observers, "onTokenParsed", kind, data, i, code)
|
||||||
statements.append(cls._buildStmt(stripped, kind, data))
|
statements.append(cls._buildStmt(code, kind, data))
|
||||||
cls._notifyObservers(observers, "onParseComplete", statements)
|
cls._notifyObservers(observers, "onParseComplete", statements)
|
||||||
return statements
|
return statements
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user