~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
1

[PATCH hare] hare::parse::doc: improve invalid utf-8 location

Details
Message ID
<20240907204326.21280-1-sebastian@sebsite.pw>
DKIM signature
pass
Download raw message
Patch: +13 -8
Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 hare/parse/doc/doc.ha | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/hare/parse/doc/doc.ha b/hare/parse/doc/doc.ha
index f7c4a129..5062414a 100644
--- a/hare/parse/doc/doc.ha
+++ b/hare/parse/doc/doc.ha
@@ -42,7 +42,8 @@ export fn parse(in: io::handle, start: lex::location) (doc | error) = {
	let sc = bufio::newscanner(in);
	defer bufio::finish(&sc);

	match (_parse(&sc)) {
	let loc = lex::location { ... };
	match (_parse(&sc, &loc)) {
	case let doc: doc =>
		return doc;
	case let err: lex::syntax =>
@@ -53,13 +54,17 @@ export fn parse(in: io::handle, start: lex::location) (doc | error) = {
	case let err: io::error =>
		return err;
	case utf8::invalid =>
		// XXX: the location for this error is inaccurate
		return lex::syntaxerr(start, "Invalid UTF-8");
		loc.path = start.path;
		loc.line += start.line;
		loc.col += start.col;
		return lex::syntaxerr(loc, "Invalid UTF-8");
	};
};

fn _parse(sc: *bufio::scanner) (doc | ...error | utf8::invalid) = {
	let loc = lex::location { ... };
fn _parse(
	sc: *bufio::scanner,
	loc: *lex::location,
) (doc | ...error | utf8::invalid) = {
	let doc: doc = [];

	for (let r => bufio::scan_rune(sc)?) {
@@ -76,16 +81,16 @@ fn _parse(sc: *bufio::scanner) (doc | ...error | utf8::invalid) = {
		switch (r) {
		case '\t' =>
			loc.col = 8;
			append(doc, scan_code_sample(sc, &loc)?);
			append(doc, scan_code_sample(sc, loc)?);
		case '\n' =>
			loc.line += 1;
			loc.col = 0;
		case '-' =>
			loc.col += 1;
			append(doc, scan_list(sc, &loc)?);
			append(doc, scan_list(sc, loc)?);
		case =>
			bufio::unreadrune(sc, r);
			append(doc, scan_paragraph(sc, &loc)?);
			append(doc, scan_paragraph(sc, loc)?);
		};
	};

-- 
2.45.2
Details
Message ID
<D441XVC0S9QF.RGBVUXFWSC7B@d2evs.net>
In-Reply-To
<20240907204326.21280-1-sebastian@sebsite.pw> (view parent)
DKIM signature
pass
Download raw message
thanks!

to git@git.sr.ht:~sircmpwn/hare
  73befbb9..df6d453e  master -> master
Reply to thread Export thread (mbox)