~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
3 2

[PATCH hare v2 1/3] hare::lex: fix number lexing

Details
Message ID
<20220623232101.30955-1-sebastian@sebsite.pw>
DKIM signature
pass
Download raw message
Patch: +19 -1
The following invalid number literals are now forbidden:

0x
0xz
0xu
0xu64
0be+0
0bf64
3.5i64

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
Since v1: added 3rd patch which disallows leading 0s in decimal literals

 hare/lex/lex.ha | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
index c1874486..25416ac4 100644
--- a/hare/lex/lex.ha
+++ b/hare/lex/lex.ha
@@ -397,6 +397,7 @@ fn lex_literal(lex: *lexer) (token | error) = {
		yield r;
	};

	let started = false;
	let base = 10u;
	if (r.0 == '0') {
		append(chars, utf8::encoderune(r.0)...);
@@ -414,6 +415,7 @@ fn lex_literal(lex: *lexer) (token | error) = {
		case 'x' =>
			base = 16;
		case =>
			started = true;
			unget(lex, r);
		};
	} else unget(lex, r);
@@ -441,6 +443,10 @@ fn lex_literal(lex: *lexer) (token | error) = {
		};
		if (!strings::contains(basechrs, r.0)) switch (r.0) {
		case '.' =>
			if (!started) {
				return syntaxerr(loc,
					"Expected integer literal");
			};
			if (float || exp is size || suff is size
					|| base != 10 || lex.require_int) {
				unget(lex, r);
@@ -466,6 +472,10 @@ fn lex_literal(lex: *lexer) (token | error) = {
				append(chars, utf8::encoderune('.')...);
			};
		case 'e', 'E' =>
			if (!started) {
				return syntaxerr(loc,
					"Expected integer literal");
			};
			if (exp is size || suff is size || base != 10) {
				unget(lex, r);
				break;
@@ -488,7 +498,11 @@ fn lex_literal(lex: *lexer) (token | error) = {
				basechrs = "0123456789";
			};
		case 'i', 'u', 'f', 'z' =>
			if (suff is size) {
			if (!started) {
				return syntaxerr(loc,
					"Expected integer literal");
			};
			if (suff is size || r.0 != 'f' && float) {
				unget(lex, r);
				break;
			} else {
@@ -501,6 +515,10 @@ fn lex_literal(lex: *lexer) (token | error) = {
			unget(lex, r);
			break;
		} else append(chars, utf8::encoderune(r.0)...);
		started = true;
	};
	if (!started) {
		return syntaxerr(loc, "expected integer literal");
	};
	if (end == 0) end = len(chars);
	lex.require_int = false;
-- 
2.36.1

[PATCH hare v2 2/3] hare::lex: disallow f suffix on non-base-10 literals

Details
Message ID
<20220623232101.30955-2-sebastian@sebsite.pw>
In-Reply-To
<20220623232101.30955-1-sebastian@sebsite.pw> (view parent)
DKIM signature
pass
Download raw message
Patch: +2 -1
The spec only details the 0b, 0o, and 0x prefixes for integer literals.
Floating point literals are always treated as decimal.

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 hare/lex/lex.ha | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
index 25416ac4..2db75c68 100644
--- a/hare/lex/lex.ha
+++ b/hare/lex/lex.ha
@@ -502,7 +502,8 @@ fn lex_literal(lex: *lexer) (token | error) = {
				return syntaxerr(loc,
					"Expected integer literal");
			};
			if (suff is size || r.0 != 'f' && float) {
			if (suff is size || r.0 != 'f' && float
					|| r.0 == 'f' && base != 10) {
				unget(lex, r);
				break;
			} else {
-- 
2.36.1

[PATCH hare v2 3/3] hare::lex: disallow leading zeros in number literal

Details
Message ID
<20220623232101.30955-3-sebastian@sebsite.pw>
In-Reply-To
<20220623232101.30955-1-sebastian@sebsite.pw> (view parent)
DKIM signature
pass
Download raw message
Patch: +4 -0
Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
Still needs spec update

 hare/lex/lex.ha | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
index 2db75c68..c9e836cc 100644
--- a/hare/lex/lex.ha
+++ b/hare/lex/lex.ha
@@ -415,6 +415,10 @@ fn lex_literal(lex: *lexer) (token | error) = {
		case 'x' =>
			base = 16;
		case =>
			if (ascii::isdigit(r.0)) {
				return syntaxerr(loc,
					"Leading zeros in number literals aren't permitted (for octal, use the 0o prefix instead)");
			};
			started = true;
			unget(lex, r);
		};
-- 
2.36.1

[hare/patches] build success

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

[hare::lex: fix number lexing][0] v2 from [Sebastian][1]

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

✓ #786648 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/786648
✓ #786647 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/786647
Reply to thread Export thread (mbox)