public stripLineComments(line as String, initialState as LexicalState, out endState as LexicalState) as String
Strips line and block comments from a single line while preserving string literals and updating endState for multi-line block comments or strings.
| Parameter | Description |
|---|---|
line | Single source line. |
initialState | Lexical state at the start of line. |
endState | Receives the lexical state at the end of line. |
Source line with comments removed.
import klyn.code
import klyn.code.klyn
t = KlynTokenizer()
endState = LexicalState.NORMAL
cleaned = t.stripLineComments("x = 1 # comment", LexicalState.NORMAL, out endState)
assert cleaned.toTrim() == "x = 1"