~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH hare] hare::lex: properly lex strings separated by comments

Details
Message ID
<20220514033452.22966-1-sebastian@sebsite.pw>
DKIM signature
pass
Download raw message
Patch: +29 -6
This example wasn't lexed correctly prior to this commit:

	"foo"
	// bar
	"baz";

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 hare/lex/+test.ha |  7 +++++++
 hare/lex/lex.ha   | 28 ++++++++++++++++++++++------
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha
index 4873024c..6eec246b 100644
--- a/hare/lex/+test.ha
+++ b/hare/lex/+test.ha
@@ -261,6 +261,13 @@ fn loc(line: uint, col: uint) location = location {
		(ltok::LIT_STR, "foo", loc(1, 35)),
	];
	lextest(in, expected);
	const in = "\"foo\"\n"
		"// bar\n"
		"\"baz\"";
	const expected: [_]token = [
		(ltok::LIT_STR, "foobaz", loc(1, 1)),
	];
	lextest(in, expected);
};

@test fn literals() void = {
diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
index 7b1929b9..5231af8c 100644
--- a/hare/lex/lex.ha
+++ b/hare/lex/lex.ha
@@ -237,20 +237,36 @@ fn lex_string(lex: *lexer, loc: location, delim: rune) (token | error) = {
			strio::appendrune(&buf, r.0)?;
		};
	};
	match (nextw(lex)?) {
	case io::EOF => void;
	for (true) match (nextw(lex)?) {
	case io::EOF =>
		break;
	case let r: (rune, location) =>
		if (r.0 == '"') {
		switch (r.0) {
		case '"', '`' =>
			const tok = lex_string(lex, loc, r.0)?;
			const next = tok.1 as str;
			strio::concat(&buf, next)!;
			free(next);
		} else {
			break;
		case '/' =>
			match (nextw(lex)?) {
			case io::EOF =>
				unget(lex, r);
			case let s: (rune, location) =>
				if (s.0 == '/') {
					lex_comment(lex)?;
					continue;
				} else {
					unget(lex, s);
					unget(lex, r);
				};
			};
			break;
		case =>
			unget(lex, r);
			break;
		};
	};
	line_comment(lex)?;

	return (ltok::LIT_STR, strio::string(&buf), loc);
};

-- 
2.35.1

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CJZ648VV5KVN.3DIOV9WIN5E4B@cirno>
In-Reply-To
<20220514033452.22966-1-sebastian@sebsite.pw> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m26s

[hare::lex: properly lex strings separated by comments][0] from [Sebastian][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/32269
[1]: sebastian@sebsite.pw

✓ #757830 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/757830
✓ #757831 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/757831
Details
Message ID
<CK15IWYUJYLS.27LMRFUCBU6LC@taiga>
In-Reply-To
<20220514033452.22966-1-sebastian@sebsite.pw> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Thanks!

To git@git.sr.ht:~sircmpwn/hare
   a0ecfc62..1ecd1920  master -> master
Reply to thread Export thread (mbox)