Raw strings, indented with the code Scan.rawString reads a string between backquotes, with no escapes, over lines; one whose opening backquote ends its line and whose closing one has only blanks before it loses those blanks from every line (report 2026-10.25, section 2). tools/Scan reads them, Pretty leaves them as written, and vim and emacs colour them and keep their lines' indents. The seed predates them: src/check.sh leaves out the files that use them.
| @@ -0,0 +1,10 @@ | ||
| 1 | +module ScanRawIndent; | |
| 2 | +import Out; | |
| 3 | +proc main*; | |
| 4 | +begin | |
| 5 | + Out.str(` | |
| 6 | + a | |
| 7 | + b | |
| 8 | + `); | |
| 9 | +end; | |
| 10 | +end ScanRawIndent. |
| @@ -0,0 +1,4 @@ | ||
| 1 | +module ScanRawOpen; | |
| 2 | +const s = `abc; | |
| 3 | + | |
| 4 | +end ScanRawOpen. |
| @@ -0,0 +1,27 @@ | ||
| 1 | +14 |C:\tmp\"a b"\n| | |
| 2 | +45 |usage: tool [-v] file | |
| 3 | + -v say what is done | |
| 4 | +| | |
| 5 | +10 |back`quote| | |
| 6 | +3 |two| | |
| 7 | +0 || | |
| 8 | +7 |one | |
| 9 | +two| | |
| 10 | +22 |first | |
| 11 | + second | |
| 12 | + | |
| 13 | +third | |
| 14 | +| | |
| 15 | +6 |x | |
| 16 | + y | |
| 17 | +| | |
| 18 | +13 | a | |
| 19 | + b | |
| 20 | + | | |
| 21 | +7 | kept | |
| 22 | +| | |
| 23 | +0 || | |
| 24 | +5 |cr | |
| 25 | +lf| | |
| 26 | +equal | |
| 27 | +195 |
| @@ -0,0 +1,61 @@ | ||
| 1 | +(* Raw strings: no escapes, over lines, indented with the code *) | |
| 2 | +module RawStrings; | |
| 3 | +import Out; | |
| 4 | + | |
| 5 | +const | |
| 6 | + Path = `C:\tmp\"a b"\n`; | |
| 7 | + Usage = ` | |
| 8 | +usage: tool [-v] file | |
| 9 | + -v say what is done | |
| 10 | +`; | |
| 11 | + Joined = `back` + "`" + `quote`; | |
| 12 | + Names: [2][]U8 = [`one`, `two`]; | |
| 13 | + | |
| 14 | +proc show(s: []U8); | |
| 15 | +begin | |
| 16 | + Out.int(LEN(s)); Out.str(" |"); Out.str(s); Out.str("|\n"); | |
| 17 | +end; | |
| 18 | + | |
| 19 | +proc main*; | |
| 20 | +var b: [8]U8; | |
| 21 | +begin | |
| 22 | + show(Path); | |
| 23 | + show(Usage); | |
| 24 | + show(Joined); | |
| 25 | + show(Names[1]); | |
| 26 | + show(``); | |
| 27 | + show(`one | |
| 28 | +two`); | |
| 29 | + (* indented: the closing line's blanks come off every line, and a | |
| 30 | + line of blanks alone is empty *) | |
| 31 | + show(` | |
| 32 | + first | |
| 33 | + second | |
| 34 | + | |
| 35 | + third | |
| 36 | + `); | |
| 37 | + (* a tab as the indentation *) | |
| 38 | + show(` | |
| 39 | + x | |
| 40 | + y | |
| 41 | + `); | |
| 42 | + (* not indented: something follows the opening backquote *) | |
| 43 | + show(` a | |
| 44 | + b | |
| 45 | + `); | |
| 46 | + (* the closing backquote at the margin takes nothing off *) | |
| 47 | + show(` | |
| 48 | + kept | |
| 49 | +`); | |
| 50 | + (* empty, indented *) | |
| 51 | + show(` | |
| 52 | + `); | |
| 53 | + (* carriage returns are left out *) | |
| 54 | + show(`cr | |
| 55 | +lf`); | |
| 56 | + if `abc` = "abc" then Out.str("equal\n"); end; | |
| 57 | + b := `héllo`; | |
| 58 | + Out.int(I64(b[1])); Out.ln; | |
| 59 | +end; | |
| 60 | + | |
| 61 | +end RawStrings. |
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | | File | Lines | Code | What | |
| 15 | 15 | |---|---|---|---| |
| 16 | 16 | | `src/Diag.raz` | 410 | 315 | Messages: positions, source excerpts, colour, counts | |
| 17 | -| `src/Scan.raz` | 1,062 | 886 | Symbols, literals, comments, positions | | |
| 17 | +| `src/Scan.raz` | 1,125 | 934 | Symbols, literals, comments, positions | | |
| 18 | 18 | | `src/Sym.raz` | 687 | 556 | Types, objects, scopes, layout | |
| 19 | 19 | | `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes | |
| 20 | 20 | | `src/X64.raz` | 1,517 | 1,253 | The instruction encoder, jumps within a procedure, the assembler | |
| @@ -902,7 +902,12 @@ | ||
| 902 | 902 | Read `next` first: it skips white space and comments (`comment`, which |
| 903 | 903 | counts nesting), then dispatches on the first character. `number` |
| 904 | 904 | handles decimal, `0FFH`-style hexadecimal and reals; `litChar` handles |
| 905 | -one character of a literal, escapes included. `readReal` turns a real's | |
| 905 | +one character of a literal, escapes included. `rawString` reads a raw | |
| 906 | +string, between backquotes, which has no escapes: first to the closing | |
| 907 | +backquote, counting lines and checking UTF-8 as a comment does, to find | |
| 908 | +the blanks before it; then line by line into `sbuf`, taking those | |
| 909 | +blanks off the start of each line if the string is indented (the | |
| 910 | +report's section 2), and leaving carriage returns out. `readReal` turns a real's | |
| 906 | 911 | digits into the nearest `F64` exactly, as a fraction of two big integers |
| 907 | 912 | (`Big`), since a library's reader can be one bit off. |
| 908 | 913 |
| @@ -1,13 +1,14 @@ | ||
| 1 | 1 | ;;; raz-mode.el --- a major mode for raz -*- lexical-binding: t -*- |
| 2 | 2 | |
| 3 | 3 | ;; Colours raz's reserved words, basic types, built-in procedures, |
| 4 | -;; numbers, characters, strings and nested comments, and indents by | |
| 4 | +;; numbers, characters, strings, raw strings over lines and nested | |
| 5 | +;; comments, and indents by | |
| 5 | 6 | ;; `raz-indent-offset': a block's statements one level in from the |
| 6 | 7 | ;; word that opens it; end, until, else and elsif at that word's |
| 7 | 8 | ;; level; match arms at the level of match; procedures, sections |
| 8 | 9 | ;; (const, type, var) and module bodies at the left margin. The text |
| 9 | -;; of a comment, and a line that goes on with the expression of the | |
| 10 | -;; line before, keep the indent they have. | |
| 10 | +;; of a comment or of a raw string, and a line that goes on with the | |
| 11 | +;; expression of the line before, keep the indent they have. | |
| 11 | 12 | ;; |
| 12 | 13 | ;; (add-to-list 'load-path "/path/to/raz/editor/emacs") |
| 13 | 14 | ;; (require 'raz-mode) |
| @@ -43,6 +44,7 @@ | ||
| 43 | 44 | (modify-syntax-entry ?\" "\"" st) |
| 44 | 45 | (modify-syntax-entry ?\' "\"" st) |
| 45 | 46 | (modify-syntax-entry ?\\ "\\" st) |
| 47 | + (modify-syntax-entry ?` "." st) | |
| 46 | 48 | (modify-syntax-entry ?_ "_" st) |
| 47 | 49 | (dolist (c '(?+ ?- ?/ ?= ?# ?< ?> ?: ?\; ?, ?. ?^ ?| ?& ?~)) |
| 48 | 50 | (modify-syntax-entry c "." st)) |
| @@ -58,7 +60,28 @@ | ||
| 58 | 60 | ("\\_<[0-9][0-9A-F]*H\\_>\\|\\_<[0-9]+\\(?:\\.[0-9]+\\(?:E[-+]?[0-9]+\\)?\\)?\\_>" |
| 59 | 61 | . font-lock-constant-face)) |
| 60 | 62 | "What `raz-mode' colours, besides strings and comments.") |
| 63 | + | |
| 64 | +;;; Raw strings | |
| 61 | 65 | |
| 66 | +(defun raz--raw-string () | |
| 67 | + "Make the backquote just matched open a raw string, if it isn't in a | |
| 68 | +comment or string: it and the closing one string fences, and the | |
| 69 | +backslashes between them nothing special, since a raw string has no | |
| 70 | +escapes." | |
| 71 | + (let ((open (match-beginning 0))) | |
| 72 | + (unless (nth 8 (save-excursion (syntax-ppss open))) | |
| 73 | + (put-text-property open (1+ open) 'syntax-table (string-to-syntax "|")) | |
| 74 | + (when (search-forward "`" nil t) | |
| 75 | + (put-text-property (1- (point)) (point) 'syntax-table (string-to-syntax "|")) | |
| 76 | + (save-excursion | |
| 77 | + (let ((close (1- (point)))) | |
| 78 | + (goto-char open) | |
| 79 | + (while (search-forward "\\" close t) | |
| 80 | + (put-text-property (1- (point)) (point) 'syntax-table (string-to-syntax "."))))))))) | |
| 81 | + | |
| 82 | +(defconst raz--syntax-propertize | |
| 83 | + (syntax-propertize-rules ("`" (0 (ignore (raz--raw-string)))))) | |
| 84 | + | |
| 62 | 85 | ;;; Indenting |
| 63 | 86 | |
| 64 | 87 | (defconst raz--decl |
| @@ -85,6 +108,14 @@ | ||
| 85 | 108 | (back-to-indentation) |
| 86 | 109 | (and (nth 4 (syntax-ppss)) |
| 87 | 110 | (not (looking-at "(\\*"))))) |
| 111 | + | |
| 112 | +(defun raz--in-raw (n) | |
| 113 | + "Whether line N starts inside a raw string, which only a raw string | |
| 114 | +can, since it alone runs over lines." | |
| 115 | + (save-excursion | |
| 116 | + (goto-char (point-min)) | |
| 117 | + (forward-line (1- n)) | |
| 118 | + (eq (nth 3 (syntax-ppss)) t))) | |
| 88 | 119 | |
| 89 | 120 | (defun raz--prev (n) |
| 90 | 121 | "The last line before N that isn't blank, or 0." |
| @@ -98,11 +129,15 @@ | ||
| 98 | 129 | (let ((line (raz--line n))) |
| 99 | 130 | (when (raz--in-comment n) |
| 100 | 131 | (setq line (if (string-match "\\*)" line) (substring line (match-end 0)) ""))) |
| 132 | + ;; and inside a raw string, after the string | |
| 133 | + (when (raz--in-raw n) | |
| 134 | + (setq line (if (string-match "`" line) (concat "0" (substring line (match-end 0))) ""))) | |
| 101 | 135 | ;; one pattern, so that whichever comes first is taken |
| 102 | 136 | (setq line (replace-regexp-in-string |
| 103 | - "\"\\(?:[^\"\\\\]\\|\\\\.\\)*\"\\|'\\(?:[^'\\\\]\\|\\\\.\\)*'\\|(\\*.*?\\*)" | |
| 137 | + "\"\\(?:[^\"\\\\]\\|\\\\.\\)*\"\\|'\\(?:[^'\\\\]\\|\\\\.\\)*'\\|`[^`]*`\\|(\\*.*?\\*)" | |
| 104 | 138 | (lambda (m) (if (string-prefix-p "(" m) "" "0")) line t t)) |
| 105 | 139 | (setq line (replace-regexp-in-string "(\\*.*\\'" "" line t t)) |
| 140 | + (setq line (replace-regexp-in-string "`.*\\'" "0" line t t)) | |
| 106 | 141 | (string-trim line))) |
| 107 | 142 | |
| 108 | 143 | (defun raz--count (re s) |
| @@ -124,7 +159,8 @@ | ||
| 124 | 159 | (let ((p (raz--prev l))) |
| 125 | 160 | (if (or (= p 0) |
| 126 | 161 | (and (not (raz--continues p)) |
| 127 | - (not (string-match-p raz--leading (raz--line l))))) | |
| 162 | + (not (string-match-p raz--leading (raz--line l))) | |
| 163 | + (not (raz--in-raw l)))) | |
| 128 | 164 | (setq done t) |
| 129 | 165 | (setq l p)))) |
| 130 | 166 | l)) |
| @@ -166,7 +202,7 @@ | ||
| 166 | 202 | (cur (raz--line n)) |
| 167 | 203 | (prev (raz--prev n))) |
| 168 | 204 | (catch 'done |
| 169 | - (when (raz--in-comment n) (throw 'done nil)) | |
| 205 | + (when (or (raz--in-comment n) (raz--in-raw n)) (throw 'done nil)) | |
| 170 | 206 | (when (and (string-match-p raz--decl cur) (not (string-match-p "^[ \t]*proc[ \t]*(" cur))) |
| 171 | 207 | (throw 'done 0)) |
| 172 | 208 | ;; a comment before a declaration goes with it, at the margin |
| @@ -216,6 +252,7 @@ | ||
| 216 | 252 | "Major mode for editing raz." |
| 217 | 253 | :syntax-table raz-mode-syntax-table |
| 218 | 254 | (setq-local font-lock-defaults '(raz-font-lock-keywords nil nil)) |
| 255 | + (setq-local syntax-propertize-function raz--syntax-propertize) | |
| 219 | 256 | (setq-local comment-start "(* ") |
| 220 | 257 | (setq-local comment-end " *)") |
| 221 | 258 | (setq-local comment-start-skip "(\\*+[ \t]*") |
| @@ -2,8 +2,8 @@ | ||
| 2 | 2 | " level in from the word that opens it; end, until, else and elsif at |
| 3 | 3 | " that word's level; match arms at the level of match; procedures, |
| 4 | 4 | " sections (const, type, var) and module bodies at the left margin. |
| 5 | -" The text of a comment, and a line that goes on with the expression | |
| 6 | -" of the line before, keep the indent they have. | |
| 5 | +" The text of a comment or of a raw string, and a line that goes on with | |
| 6 | +" the expression of the line before, keep the indent they have. | |
| 7 | 7 | |
| 8 | 8 | if exists("b:did_indent") |
| 9 | 9 | finish |
| @@ -31,12 +31,17 @@ | ||
| 31 | 31 | if s:InComment(a:lnum) |
| 32 | 32 | let line = line =~ '\*)' ? substitute(line, '^.\{-}\*)', '', '') : '' |
| 33 | 33 | endif |
| 34 | + " and inside a raw string, after the string | |
| 35 | + if s:InRaw(a:lnum) | |
| 36 | + let line = line =~ '`' ? substitute(line, '^[^`]*`', '0', '') : '' | |
| 37 | + endif | |
| 34 | 38 | " one pattern, so that whichever comes first is taken: a " in a |
| 35 | 39 | " character, a ' in a string; strings become 0, comments go |
| 36 | 40 | let line = substitute(line, |
| 37 | - \ '"\%([^"\\]\|\\.\)*"\|''\%([^''\\]\|\\.\)*''\|(\*.\{-}\*)', | |
| 41 | + \ '"\%([^"\\]\|\\.\)*"\|''\%([^''\\]\|\\.\)*''\|`[^`]*`\|(\*.\{-}\*)', | |
| 38 | 42 | \ '\=submatch(0)[0] == "(" ? "" : "0"', 'g') |
| 39 | 43 | let line = substitute(line, '(\*.*$', '', '') |
| 44 | + let line = substitute(line, '`.*$', '0', '') | |
| 40 | 45 | return substitute(line, '^\s*\(.\{-}\)\s*$', '\1', '') |
| 41 | 46 | endfunction |
| 42 | 47 | |
| @@ -56,7 +61,7 @@ | ||
| 56 | 61 | let l = a:lnum |
| 57 | 62 | while 1 |
| 58 | 63 | let p = prevnonblank(l - 1) |
| 59 | - if p == 0 || !s:Continues(p) && getline(l) !~# s:leading | |
| 64 | + if p == 0 || !s:Continues(p) && getline(l) !~# s:leading && !s:InRaw(l) | |
| 60 | 65 | return l |
| 61 | 66 | endif |
| 62 | 67 | let l = p |
| @@ -96,9 +101,20 @@ | ||
| 96 | 101 | \ && getline(a:lnum) !~ '^\s*(\*' |
| 97 | 102 | endfunction |
| 98 | 103 | |
| 104 | +" Whether the line starts inside a raw string, which only a raw string | |
| 105 | +" can, since it alone runs over lines; a backquote first on the line | |
| 106 | +" closes one if what follows it isn't in a string. | |
| 107 | +function! s:IsRaw(lnum, col) | |
| 108 | + return synIDattr(synID(a:lnum, a:col, 1), "name") ==# 'razRawString' | |
| 109 | +endfunction | |
| 110 | + | |
| 111 | +function! s:InRaw(lnum) | |
| 112 | + return s:IsRaw(a:lnum, 1) && (getline(a:lnum) !~ '^`' || !s:IsRaw(a:lnum, 2)) | |
| 113 | +endfunction | |
| 114 | + | |
| 99 | 115 | function! GetRazIndent(lnum) |
| 100 | 116 | let cur = getline(a:lnum) |
| 101 | - if s:InComment(a:lnum) | |
| 117 | + if s:InComment(a:lnum) || s:InRaw(a:lnum) | |
| 102 | 118 | return -1 |
| 103 | 119 | endif |
| 104 | 120 | if cur =~# s:decl && cur !~# '^\s*proc\s*(' |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | " Vim syntax file for raz: reserved words, basic types, built-in |
| 2 | -" procedures, numbers, characters, strings and nested comments. | |
| 2 | +" procedures, numbers, characters, strings, raw strings over lines and | |
| 3 | +" nested comments. | |
| 3 | 4 | |
| 4 | 5 | if exists("b:current_syntax") |
| 5 | 6 | finish |
| @@ -25,6 +26,7 @@ | ||
| 25 | 26 | syntax match razEscape contained "\\\([ntr0\\'\"]\|x\x\x\|u{\x\+}\)" |
| 26 | 27 | syntax region razString start=+"+ skip=+\\.+ end=+"+ contains=razEscape oneline |
| 27 | 28 | syntax region razChar start=+'+ skip=+\\.+ end=+'+ contains=razEscape oneline |
| 29 | +syntax region razRawString start=+`+ end=+`+ | |
| 28 | 30 | |
| 29 | 31 | syntax region razComment start="(\*" end="\*)" contains=razComment,@Spell |
| 30 | 32 | syntax sync fromstart |
| @@ -35,6 +37,7 @@ | ||
| 35 | 37 | highlight default link razConstant Constant |
| 36 | 38 | highlight default link razNumber Number |
| 37 | 39 | highlight default link razString String |
| 40 | +highlight default link razRawString String | |
| 38 | 41 | highlight default link razChar Character |
| 39 | 42 | highlight default link razEscape SpecialChar |
| 40 | 43 | highlight default link razComment Comment |
| @@ -907,6 +907,68 @@ | ||
| 907 | 907 | end; |
| 908 | 908 | end; |
| 909 | 909 | |
| 910 | +(* A raw string, between backquotes (report, section 2): its bytes as | |
| 911 | + they stand, with no escapes, over as many lines as it runs; carriage | |
| 912 | + returns are left out. It is indented if the opening backquote ends | |
| 913 | + its line and the closing one has only blanks before it: the lines | |
| 914 | + between are its text, each without those blanks at its start. So | |
| 915 | + | |
| 916 | + Out.str(` | |
| 917 | + a | |
| 918 | + b | |
| 919 | + `); | |
| 920 | + | |
| 921 | + is "a\n b\n". The text is read twice: to the closing backquote, | |
| 922 | + for its blanks, then line by line into sbuf. *) | |
| 923 | +proc rawString; | |
| 924 | +var p, close, last, q, i, j: INT; c: U8; indented: BOOL; | |
| 925 | +begin | |
| 926 | + INC(cur.pos); | |
| 927 | + p := cur.pos; | |
| 928 | + while cur.buf[cur.pos] # '`' do | |
| 929 | + c := cur.buf[cur.pos]; | |
| 930 | + if c = 0 then | |
| 931 | + if cur.pos >= cur.len then markBytes(cur.tokPos, cur.tokPos + 1, "string not closed"); end; | |
| 932 | + markBytes(cur.pos, cur.pos + 1, "NUL byte in the text"); | |
| 933 | + elsif c >= 80H then | |
| 934 | + _ := utf8(cur.pos); | |
| 935 | + else | |
| 936 | + if c = '\n' then INC(cur.line); cur.lineStart := cur.pos + 1; end; | |
| 937 | + INC(cur.pos); | |
| 938 | + end; | |
| 939 | + end; | |
| 940 | + close := cur.pos; | |
| 941 | + q := close; (* where the blanks before the closing backquote start *) | |
| 942 | + while (q > p) and ((cur.buf[q - 1] = ' ') or (cur.buf[q - 1] = '\t')) do DEC(q); end; | |
| 943 | + i := p; | |
| 944 | + if cur.buf[i] = '\r' then INC(i); end; | |
| 945 | + indented := (cur.buf[i] = '\n') and (q > i) and (cur.buf[q - 1] = '\n'); | |
| 946 | + if indented then INC(i); last := q; else i := p; last := close; end; | |
| 947 | + slen := 0; | |
| 948 | + while i < last do | |
| 949 | + (* i is where a line starts *) | |
| 950 | + if indented then | |
| 951 | + j := i; | |
| 952 | + while (cur.buf[j] = ' ') or (cur.buf[j] = '\t') do INC(j); end; | |
| 953 | + if (cur.buf[j] = '\n') or (cur.buf[j] = '\r') then | |
| 954 | + i := j; (* only blanks: an empty line *) | |
| 955 | + elsif (j - i < close - q) or (cur.buf[i..i + close - q] # cur.buf[q..close]) then | |
| 956 | + markBytes(i, j + 1, "this line doesn't start with the blanks before the closing backquote"); | |
| 957 | + else | |
| 958 | + i := i + close - q; | |
| 959 | + end; | |
| 960 | + end; | |
| 961 | + repeat | |
| 962 | + c := cur.buf[i]; | |
| 963 | + INC(i); | |
| 964 | + if c # '\r' then put(INT(c)); end; | |
| 965 | + until (c = '\n') or (i >= last); | |
| 966 | + end; | |
| 967 | + cur.pos := close + 1; | |
| 968 | + sbuf[slen] := 0; | |
| 969 | + tok := sString; | |
| 970 | +end; | |
| 971 | + | |
| 910 | 972 | (* Reads the next symbol *) |
| 911 | 973 | proc next*; |
| 912 | 974 | var c: U8; start, h, v, i, p: INT; buf: ^U8; |
| @@ -989,6 +1051,7 @@ | ||
| 989 | 1051 | INC(cur.pos); |
| 990 | 1052 | sbuf[slen] := 0; |
| 991 | 1053 | tok := sString; |
| 1054 | + | '`': rawString; | |
| 992 | 1055 | | '=': |
| 993 | 1056 | if cur.buf[cur.pos + 1] = '=' then |
| 994 | 1057 | slip(2, sEql, "comparing is written =, not =="); |
| @@ -5,6 +5,13 @@ | ||
| 5 | 5 | # side is built by fpc from seed/. |
| 6 | 6 | set -e |
| 7 | 7 | b=build/src |
| 8 | +# The seed predates raw strings and match on a string (report | |
| 9 | +# 2026-10.25): the files that use them are the compiler's alone. | |
| 10 | +newer="conform/run/RawStrings.raz conform/err/ScanRawOpen.raz conform/err/ScanRawIndent.raz" | |
| 11 | +newer() { | |
| 12 | + case " $newer " in *" $1 "*) return 0 ;; esac | |
| 13 | + return 1 | |
| 14 | +} | |
| 8 | 15 | mkdir -p $b |
| 9 | 16 | fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/scandump.seed src/test/ScanDump.pas >/dev/null |
| 10 | 17 | ./raz -Werror -I src -o $b/scandump.src src/test/ScanDump.raz |
| @@ -17,6 +24,7 @@ | ||
| 17 | 24 | for f in $b/lex/*.raz lib/*.raz examples/*.raz tools/*.raz src/*.raz src/test/*.raz test/run/*.raz test/err/*.raz \ |
| 18 | 25 | conform/*/*.raz $b/reals.raz; do |
| 19 | 26 | [ -f "$f" ] || continue |
| 27 | + newer $f && continue | |
| 20 | 28 | s1=0; s2=0 |
| 21 | 29 | $b/scandump.seed $f >$b/seed.out 2>$b/seed.err || s1=$? |
| 22 | 30 | $b/scandump.src $f >$b/src.out 2>$b/src.err || s2=$? |
| @@ -116,7 +124,7 @@ | ||
| 116 | 124 | files= |
| 117 | 125 | for f in $c/bench/Bench.raz lib/*.raz examples/*.raz tools/*.raz src/*.raz test/run/*.raz test/libc/*.raz test/bench/*.raz \ |
| 118 | 126 | conform/run/*.raz test/err/*.raz conform/err/*.raz; do |
| 119 | - files="$files $f" | |
| 127 | + newer $f || files="$files $f" | |
| 120 | 128 | done |
| 121 | 129 | for side in seed src; do |
| 122 | 130 | rm -rf $c/$side |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ScanRawIndent.raz:7:1: error: this line doesn't start with the blanks before the closing backquote | |
| 2 | + 7 | b | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ScanRawOpen.raz:2:11: error: string not closed | |
| 2 | + 2 | const s = `abc; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,11 @@ | ||
| 1 | +module RawString; | |
| 2 | +import Out; | |
| 3 | +proc main*; | |
| 4 | +begin | |
| 5 | + Out.str(` | |
| 6 | + a | |
| 7 | + b | |
| 8 | + `); | |
| 9 | + Out.str(`x` + "y"); | |
| 10 | +end; | |
| 11 | +end RawString. |
| @@ -0,0 +1,11 @@ | ||
| 1 | +module RawString; | |
| 2 | +import Out; | |
| 3 | +proc main*; | |
| 4 | +begin | |
| 5 | + Out.str(` | |
| 6 | + a | |
| 7 | + b | |
| 8 | + `); | |
| 9 | + Out.str(`x`+"y"); | |
| 10 | +end; | |
| 11 | +end RawString. |
| @@ -14,7 +14,8 @@ | ||
| 14 | 14 | module, import, proc, the sections and begin at the margin, with the |
| 15 | 15 | comment just before them. A line that goes on with the expression of |
| 16 | 16 | the line before keeps its indent, moved as far as the statement's |
| 17 | - first line moved; so does the text of a comment. | |
| 17 | + first line moved; so does the text of a comment. A raw string stays | |
| 18 | + as written, every byte, since its lines are its value. | |
| 18 | 19 | |
| 19 | 20 | Within a line, a binary operator has one space on each side, a unary |
| 20 | 21 | minus or ~ none after it, and , and ; none before them and one after. A |
| @@ -224,13 +225,18 @@ | ||
| 224 | 225 | end; |
| 225 | 226 | |
| 226 | 227 | (* The current symbol as written; each line of a comment after its |
| 227 | - first is moved as far as the line the comment starts on. *) | |
| 228 | + first is moved as far as the line the comment starts on, and a raw | |
| 229 | + string's lines are left as they are. *) | |
| 228 | 230 | proc write; |
| 229 | 231 | var i, k: INT; |
| 230 | 232 | begin |
| 231 | 233 | i := sc.start; |
| 232 | 234 | while i < sc.stop do |
| 233 | - if src[i] = '\n' then | |
| 235 | + if (src[i] = '\n') and (sc.kind = Scan.literal) then | |
| 236 | + Buf.add(ADR(out), '\n'); | |
| 237 | + lineAt := out.len; | |
| 238 | + INC(i); | |
| 239 | + elsif src[i] = '\n' then | |
| 234 | 240 | newLine; |
| 235 | 241 | k := i + 1; |
| 236 | 242 | while (k < sc.stop) and (src[k] = ' ') do INC(k); end; |
| @@ -2,8 +2,8 @@ | ||
| 2 | 2 | compiler's scanner it keeps comments, as symbols of their own, and |
| 3 | 3 | says where each symbol is in the text and whether a line break comes |
| 4 | 4 | before it. It doesn't check what it reads: a malformed number is |
| 5 | - read as far as it goes, and a string, character or comment left open | |
| 6 | - ends with its line or the text. *) | |
| 5 | + read as far as it goes, and a string or character left open ends | |
| 6 | + with its line, a raw string or comment with the text. *) | |
| 7 | 7 | module Scan; |
| 8 | 8 | |
| 9 | 9 | type |
| @@ -98,14 +98,16 @@ | ||
| 98 | 98 | return p; |
| 99 | 99 | end; |
| 100 | 100 | |
| 101 | -(* Past the string or character that starts at p, or to its line's end. *) | |
| 101 | +(* Past the string or character that starts at p, or to its line's end; | |
| 102 | + a raw string, between backquotes, has no escapes and may run over | |
| 103 | + lines. *) | |
| 102 | 104 | proc pastLiteral(src: []U8; p: INT): INT; |
| 103 | 105 | var q: U8; |
| 104 | 106 | begin |
| 105 | 107 | q := src[p]; |
| 106 | 108 | INC(p); |
| 107 | - while (p < LEN(src)) and (src[p] # q) and (src[p] # '\n') do | |
| 108 | - if (src[p] = '\\') and (p + 1 < LEN(src)) then INC(p); end; | |
| 109 | + while (p < LEN(src)) and (src[p] # q) and ((src[p] # '\n') or (q = '`')) do | |
| 110 | + if (src[p] = '\\') and (q # '`') and (p + 1 < LEN(src)) then INC(p); end; | |
| 109 | 111 | INC(p); |
| 110 | 112 | end; |
| 111 | 113 | if (p < LEN(src)) and (src[p] = q) then INC(p); end; |
| @@ -141,7 +143,7 @@ | ||
| 141 | 143 | elsif isWord(c) then |
| 142 | 144 | s^.kind := word; |
| 143 | 145 | while (p < LEN(src)) and isWord(src[p]) do INC(p); end; |
| 144 | - elsif (c = '"') or (c = '\'') then | |
| 146 | + elsif (c = '"') or (c = '\'') or (c = '`') then | |
| 145 | 147 | s^.kind := literal; p := pastLiteral(src, p); |
| 146 | 148 | else |
| 147 | 149 | s^.kind := symbol; |