Documentation
¶
Overview ¶
Package codetext separates comments from code in Go and JavaScript source for the contracts text rules. It is a lexer, not a parser: it walks the text left to right and tracks string, raw-string, rune and template literals, so a "*/*" Accept value or a "locales/*.json" glob stays code instead of opening a comment that blanks the rest of the file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Strip ¶
Strip returns src with every // and /* */ comment removed. Newlines inside a comment are kept, so line numbers still match the original.
A string literal is code, but the code it holds may carry its own comments: a generator emits "// fontFaceCSS holds the @font-face rules", and a stylesheet in a raw string has /* knob notes */. Those are prose too, so they go, with two limits that keep the "*/*" class out. A /* inside a literal opens a comment only when its */ closes inside the same literal ("image/*" never does). A // inside a literal opens one only at the literal's start or after whitespace or an escaped newline, with whitespace after it, and runs to the end of the line or the literal, whichever comes first ("https://cdn" and '//cdn.example/x.js' stay).
script selects JavaScript literal rules: a backslash escapes inside a template literal, which it never does inside a Go raw string. A regular-expression literal is not tracked; a quote inside one at worst keeps the rest of that line as code.