go: lex.sx — raw string literals (backtick) + 9 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Adds Go raw string literals per Go spec § String literals: backtick-delimited, no escape processing, may span multiple lines, '\r' chars discarded from the value. gl-read-raw-string! mirrors gl-read-string! but skips escape handling and the \r filter. scan! routes the leading backtick to it; emits "string" type (same as interpreted strings — no need to distinguish at parse/type time). lex 123/123. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -143,7 +143,38 @@
|
||||
(go-test "imag: ASI at newline" (tok-types "1i\n") (list "imag" "semi" "eof"))
|
||||
|
||||
;; ── string literals ───────────────────────────────────────────────
|
||||
(go-test "raw: simple" (tok-values "`hello`") (list "hello" "\n" nil))
|
||||
(go-test "raw: empty" (tok-values "``") (list "" "\n" nil))
|
||||
(go-test
|
||||
"raw: backslash literal — no escape processing"
|
||||
(tok-values "`a\\nb`")
|
||||
(list "a\\nb" "\n" nil))
|
||||
(go-test
|
||||
"raw: multi-line"
|
||||
(tok-values "`line1\nline2`")
|
||||
(list "line1\nline2" "\n" nil))
|
||||
(go-test
|
||||
"raw: contains double-quote"
|
||||
(tok-values "`say \"hi\"`")
|
||||
(list "say \"hi\"" "\n" nil))
|
||||
(go-test
|
||||
"raw: CR stripped (Go spec § String literals)"
|
||||
(tok-values "`a\r\nb`")
|
||||
(list "a\nb" "\n" nil))
|
||||
(go-test "raw: type" (tok-types "`x`") (list "string" "semi" "eof"))
|
||||
|
||||
;; ── rune literals ─────────────────────────────────────────────────
|
||||
(go-test
|
||||
"raw: then +"
|
||||
(tok-types "`x` + 1")
|
||||
(list "string" "op" "int" "semi" "eof"))
|
||||
(go-test
|
||||
"raw: ASI at newline after"
|
||||
(tok-types "`abc`\n")
|
||||
(list "string" "semi" "eof"))
|
||||
(go-test "string: empty" (tok-values "\"\"") (list "" "\n" nil))
|
||||
|
||||
;; ── comments ──────────────────────────────────────────────────────
|
||||
(go-test "string: hello" (tok-values "\"hello\"") (list "hello" "\n" nil))
|
||||
(go-test
|
||||
"string: with space"
|
||||
@@ -155,14 +186,12 @@
|
||||
"string: escape backslash"
|
||||
(tok-values "\"a\\\\b\"")
|
||||
(list "a\\b" "\n" nil))
|
||||
(go-test "string: type" (tok-types "\"x\"") (list "string" "semi" "eof"))
|
||||
|
||||
;; ── rune literals ─────────────────────────────────────────────────
|
||||
;; ── operators & punctuation ───────────────────────────────────────
|
||||
(go-test "string: type" (tok-types "\"x\"") (list "string" "semi" "eof"))
|
||||
(go-test "rune: simple" (tok-values "'a'") (list "a" "\n" nil))
|
||||
(go-test "rune: escape" (tok-values "'\\n'") (list "\n" "\n" nil))
|
||||
(go-test "rune: type" (tok-types "'a'") (list "rune" "semi" "eof"))
|
||||
|
||||
;; ── comments ──────────────────────────────────────────────────────
|
||||
(go-test "line comment" (tok-types "// ignored") (list "eof"))
|
||||
(go-test "line comment then code" (tok-values "// hi\nx") (list "x" "\n" nil))
|
||||
(go-test "block comment" (tok-types "/* a b c */") (list "eof"))
|
||||
@@ -175,7 +204,7 @@
|
||||
(tok-types "x /* multi\nline */ y")
|
||||
(list "ident" "semi" "ident" "semi" "eof"))
|
||||
|
||||
;; ── operators & punctuation ───────────────────────────────────────
|
||||
;; ── automatic semicolon insertion (Go spec § Semicolons) ──────────
|
||||
(go-test
|
||||
"ops: arithmetic"
|
||||
(tok-values "+ - * / %")
|
||||
@@ -200,8 +229,6 @@
|
||||
"punct: comma colon dot"
|
||||
(tok-values ", : .")
|
||||
(list "," ":" "." nil))
|
||||
|
||||
;; ── automatic semicolon insertion (Go spec § Semicolons) ──────────
|
||||
(go-test
|
||||
"ASI: after ident at newline"
|
||||
(tok-types "x\ny")
|
||||
@@ -213,6 +240,8 @@
|
||||
(tok-types "\"hi\"\n")
|
||||
(list "string" "semi" "eof"))
|
||||
(go-test "ASI: after rune" (tok-types "'a'\n") (list "rune" "semi" "eof"))
|
||||
|
||||
;; ── short program ─────────────────────────────────────────────────
|
||||
(go-test
|
||||
"ASI: after )"
|
||||
(tok-types "f()\n")
|
||||
@@ -222,37 +251,45 @@
|
||||
(tok-types "x[0]\n")
|
||||
(list "ident" "op" "int" "op" "semi" "eof"))
|
||||
(go-test "ASI: after }" (tok-types "{}\n") (list "op" "op" "semi" "eof"))
|
||||
|
||||
;; ── report ────────────────────────────────────────────────────────
|
||||
(go-test "ASI: after ++" (tok-types "i++\n") (list "ident" "op" "semi" "eof"))
|
||||
|
||||
(go-test
|
||||
"ASI: NOT after +"
|
||||
(tok-types "x +\ny")
|
||||
(list "ident" "op" "ident" "semi" "eof"))
|
||||
|
||||
(go-test
|
||||
"ASI: NOT after ("
|
||||
(tok-types "f(\nx)")
|
||||
(list "ident" "op" "ident" "op" "semi" "eof"))
|
||||
|
||||
(go-test
|
||||
"ASI: blank lines collapse — single semi only"
|
||||
(tok-types "x\n\n\ny")
|
||||
(list "ident" "semi" "ident" "semi" "eof"))
|
||||
|
||||
(go-test
|
||||
"ASI: at EOF after ident"
|
||||
(tok-types "x")
|
||||
(list "ident" "semi" "eof"))
|
||||
|
||||
(go-test
|
||||
"ASI: explicit semi"
|
||||
(tok-types "x;y")
|
||||
(list "ident" "semi" "ident" "semi" "eof"))
|
||||
|
||||
;; ── short program ─────────────────────────────────────────────────
|
||||
(go-test
|
||||
"short-decl: x := 42 (types)"
|
||||
(tok-types "x := 42")
|
||||
(list "ident" "op" "int" "semi" "eof"))
|
||||
|
||||
(go-test
|
||||
"short-decl: x := 42 (values)"
|
||||
(tok-values "x := 42")
|
||||
(list "x" ":=" "42" "\n" nil))
|
||||
|
||||
(go-test
|
||||
"func decl shape"
|
||||
(tok-types "func foo() int { return 0 }")
|
||||
@@ -269,5 +306,4 @@
|
||||
"semi"
|
||||
"eof"))
|
||||
|
||||
;; ── report ────────────────────────────────────────────────────────
|
||||
(define go-lex-test-summary (str "lex " go-test-pass "/" go-test-count))
|
||||
|
||||
Reference in New Issue
Block a user