lexer: strip JS/CSS comments from code-bearing string literals at compile time
scan_string() is the right gate for this: every El source that embeds JS or CSS does so as a quoted string literal, and the lexer is the single chokepoint every backend reads. Strip there and the // line comments and /* */ block comments never reach the parser, codegen, or the served HTML. looks_like_code is intentionally narrow: - contains "<script" or "<style" (the embedded-asset case), or - contains "function" AND ";" (a JS body without an opening tag) Plain prose with stray // sequences passes through verbatim. strip_code_comments tracks JS string state (single, double, backtick) and never strips inside one. Backslash escapes inside JS strings consume the next char verbatim. URL guard: when the char before / is ':', emit the / literally and advance one — preserves https:// inside string literals. Block-comment scan walks until the matching '*/' pair. elc-cli.el is now a one-line `import "el-compiler/src/compiler.el"` shim. Top-level `let _argv = args()` was clashing with C int main()'s `char** _argv` parameter once compiler.el's fn main() body got folded into C main. compiler.el owns the CLI entry point now. Self-host fixed point reached: gen2 == gen3 byte-identical. Tagged dist/platform/elc.20260502-1104-self-host alongside dist/platform/elc.
This commit is contained in:
+6
-7
@@ -1,8 +1,7 @@
|
||||
// elc-cli.el — entry point for the self-hosted el compiler.
|
||||
//
|
||||
// All logic lives in el-compiler/src/compiler.el (which defines fn main()).
|
||||
// Importing it pulls in compiler.el + parser + lexer + codegen transitively.
|
||||
// The native compiler resolves imports textually and folds fn main() into
|
||||
// C's int main(), so this file does not declare any top-level work itself.
|
||||
import "el-compiler/src/compiler.el"
|
||||
|
||||
// compile() streams C source to stdout via println.
|
||||
// We read source from args()[0] and compile it.
|
||||
let _argv: [String] = args()
|
||||
let src_path: String = native_list_get(_argv, 0)
|
||||
let source: String = fs_read(src_path)
|
||||
compile(source)
|
||||
|
||||
Reference in New Issue
Block a user