Modules

String_Literal

moduleSource
macOSLinuxWindowswasm

since 0.27.0

#import "Extensions/String_Literal";

Where a byte of a string literal's value sits in the source. A jaic extension, not official Jai: other Jai compilers have no such module, and it may change between jaic releases. See docs/extensions/string-literal.md.

Compile-time code that checks a string it was given (a query, a pattern, a format) can report a problem at the exact character instead of at the whole literal:

Example
check_sql :: (code: Code) {
    literal := cast(*Code_Literal) compiler_get_nodes(code);
    error_at := find_problem(literal._string);
    location := String_Literal.location_of_byte(literal, error_at);
    compiler_report("syntax error", location);
}

Not run: the example is marked ignore.

Show moreShow less

Not run: it is a compile-time macro that reports to the compiler.

Both quoted literals (with every escape) and here-strings (#string, #string,cr, #string,\%) are mapped. The source is read through the compiler's file system, so the editor maps against the unsaved buffer.

Procedures#

location_of_bytesince 0.27.0
(literal: *Code_Literal, byte: int) -> (Source_Code_Location, ok: bool)

The location of byte byte of the value of literal (a string literal node from compiler_get_nodes); byte == value.count is the end of the value. ok is false when the literal's source cannot be read again, or does not decode to the node's value (a string the compiler built rather than read): the location is then where the literal starts.