vile / lexer / block_scan.c.v
60 lines · 47 sloc · 2.24 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module lexer
2
3#include "@VMODROOT/lexer/block_scan.h"
4
5fn C.vile_identifier_run(const_source &u8, length i64) i64
6
7fn C.vile_block_non_ascii(const_source &u8) int
8fn C.vile_block_string_special(const_source &u8) int
9
10@[inline]
11fn block_non_ascii(source string, start int) bool {
12 // The private caller's loop established 0 <= start <= len - 16. C borrows
13 // the immutable source synchronously and retains no pointer or allocation.
14 return unsafe { C.vile_block_non_ascii(source.str + start) != 0 }
15}
16
17@[inline]
18fn block_string_special(source string, start int) bool {
19 // Identical bounded-load contract to block_non_ascii; no source mutation,
20 // ownership transfer, or pointer retention crosses this call.
21 return unsafe { C.vile_block_string_special(source.str + start) != 0 }
22}
23
24@[inline]
25fn native_identifier_end(source string, start int) int {
26 // The private caller supplies 0 <= start <= source.len. C borrows only the
27 // remaining bytes, retains no pointer, and returns a count within that range.
28 count := unsafe { C.vile_identifier_run(source.str + start, i64(source.len - start)) }
29 return start + int(count)
30}
31
32fn C.vile_string_unicode_run(source &u8, length i64) i64
33fn C.vile_comment_unicode_run(source &u8, length i64) i64
34
35@[inline]
36fn native_string_unicode_end(source string, start int) int {
37 return start + int(unsafe { C.vile_string_unicode_run(source.str + start, i64(source.len - start)) })
38}
39
40@[inline]
41fn native_comment_unicode_end(source string, start int) int {
42 return start + int(unsafe { C.vile_comment_unicode_run(source.str + start, i64(source.len - start)) })
43}
44
45fn C.vile_string_legacy_run(source &u8, length i64) i64
46
47@[inline]
48fn native_string_legacy_end(source string, start int) int {
49 // Private caller proves start in0..len. C borrows only remaining bytes.
50 return start + int(unsafe { C.vile_string_legacy_run(source.str + start, i64(source.len - start)) })
51}
52
53fn C.vile_comment_ascii_run(source &u8, length i64) i64
54
55@[inline]
56fn native_comment_ascii_end(source string, start int) int {
57 // The caller proves an ASCII source and a valid remaining span. The existing
58 // native loop specializes away Unicode candidates, without copies or views.
59 return start + int(unsafe { C.vile_comment_ascii_run(source.str + start, i64(source.len - start)) })
60}
61