hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 34cab1d7301317c8add52bb141bf712c989f39bb
parent eb87aeb261301f19d6a250b696dc9b7444673181
Author: Sebastian <sebastian@sebsite.pw>
Date:   Mon, 21 Feb 2022 14:02:27 -0500

lex: add support for `raw strings`

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mhare/lex/lex.ha | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -226,24 +226,27 @@ fn lex_rune(lex: *lexer, loc: location) (rune | error) = { }; }; -fn lex_string(lex: *lexer, loc: location) (token | error) = { +fn lex_string(lex: *lexer, loc: location, delim: rune) (token | error) = { + let ret: token = (ltok::LIT_STR, "", loc); let buf = strio::dynamic(); for (true) match (next(lex)?) { case io::EOF => return syntaxerr(loc, "unexpected EOF scanning string literal"); case let r: (rune, location) => - if (r.0 == '"') break - else { + if (r.0 == delim) break + else if (delim == '"') { unget(lex, r); let r = lex_rune(lex, loc)?; strio::appendrune(&buf, r)?; + } else { + strio::appendrune(&buf, r.0)?; }; }; match (nextw(lex)?) { case io::EOF => void; case let r: (rune, location) => if (r.0 == '"') { - const tok = lex_string(lex, loc)?; + const tok = lex_string(lex, loc, r.0)?; const next = tok.1 as str; strio::concat(&buf, next)!; free(next); @@ -264,8 +267,8 @@ fn lex_rn_str(lex: *lexer) (token | error) = { }; switch (r) { case '\'' => void; - case '\"' => - return lex_string(lex, loc); + case '\"', '`' => + return lex_string(lex, loc, r); case => abort(); // Invariant };