~sircmpwn/hare-json

4af2d111255c067fa8697bebb0d90c80f1a0c551 — Willow Barraco 8 months ago 99ae40e
Bump Hare stdlib usage

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
3 files changed, 19 insertions(+), 19 deletions(-)

M encoding/json/dump.ha
M encoding/json/lex.ha
M encoding/json/load.ha
M encoding/json/dump.ha => encoding/json/dump.ha +3 -3
@@ 3,7 3,7 @@
use fmt;
use io;
use strings;
use strio;
use memio;

// Dumps a [[value]] into an [[io::handle]] as a string without any additional
// formatting.


@@ 78,7 78,7 @@ export fn dump(out: io::handle, val: value) (size | io::error) = {
// Dumps a [[value]] into a string without any additional formatting. The caller
// must free the return value.
export fn dumpstr(val: value) str = {
	let s = strio::dynamic();
	let s = memio::dynamic();
	dump(&s, val)!;
	return strio::string(&s);
	return memio::string(&s)!;
};

M encoding/json/lex.ha => encoding/json/lex.ha +14 -14
@@ 7,12 7,12 @@ use io;
use os;
use strconv;
use strings;
use strio;
use memio;

export type lexer = struct {
	src: io::handle,
	buffer: []u8,
	strbuf: strio::stream,
	strbuf: memio::stream,
	un: (token | void),
	rb: (rune | void),
	loc: (uint, uint),


@@ 24,11 24,11 @@ export type lexer = struct {
// Creates a new JSON lexer. The caller may obtain tokens with [[lex]] and
// should pass the result to [[close]] when they're done with it.
export fn newlexer(src: io::handle) lexer = {
	let buf: []u8 = alloc([0...], os::BUFSIZ);
	let buf: []u8 = alloc([0...], os::BUFSZ);
	return lexer {
		src = src,
		buffer = buf,
		strbuf = strio::dynamic(),
		strbuf = memio::dynamic(),
		un = void,
		rb = void,
		loc = (1, 0),


@@ 117,7 117,7 @@ export fn unlex(lex: *lexer, tok: token) void = {
// Scans until encountering a non-alphabetical character, returning the
// resulting word.
fn scan_word(lex: *lexer) (str | error) = {
	strio::reset(&lex.strbuf);
	memio::reset(&lex.strbuf);

	for (true) {
		const rn = match (nextrune(lex)?) {


@@ 130,10 130,10 @@ fn scan_word(lex: *lexer) (str | error) = {
			unget(lex, rn);
			break;
		};
		strio::appendrune(&lex.strbuf, rn)!;
		memio::appendrune(&lex.strbuf, rn)!;
	};

	return strio::string(&lex.strbuf);
	return memio::string(&lex.strbuf)!;
};

type numstate = enum {


@@ 149,7 149,7 @@ type numstate = enum {
};

fn scan_number(lex: *lexer) (token | error) = {
	strio::reset(&lex.strbuf);
	memio::reset(&lex.strbuf);

	let state = numstate::SIGN;
	for (true) {


@@ 235,10 235,10 @@ fn scan_number(lex: *lexer) (token | error) = {
			};
		};

		strio::appendrune(&lex.strbuf, rn)!;
		memio::appendrune(&lex.strbuf, rn)!;
	};

	match (strconv::stof64(strio::string(&lex.strbuf))) {
	match (strconv::stof64(memio::string(&lex.strbuf)!)) {
	case let f: f64 =>
		return f;
	case =>


@@ 247,7 247,7 @@ fn scan_number(lex: *lexer) (token | error) = {
};

fn scan_str(lex: *lexer) (token | error) = {
	strio::reset(&lex.strbuf);
	memio::reset(&lex.strbuf);

	for (true) {
		const rn = match (nextrune(lex)?) {


@@ 263,16 263,16 @@ fn scan_str(lex: *lexer) (token | error) = {
			break;
		case '\\' =>
			const rn = scan_escape(lex)?;
			strio::appendrune(&lex.strbuf, rn)!;
			memio::appendrune(&lex.strbuf, rn)!;
		case =>
			if (iscntrl(rn)) {
				return lex.loc: invalid;
			};
			strio::appendrune(&lex.strbuf, rn)!;
			memio::appendrune(&lex.strbuf, rn)!;
		};
	};

	return strio::string(&lex.strbuf);
	return memio::string(&lex.strbuf)!;
};

fn scan_escape(lex: *lexer) (rune | error) = {

M encoding/json/load.ha => encoding/json/load.ha +2 -2
@@ 1,4 1,4 @@
use bufio;
use memio;
use io;
use strings;
use types;


@@ 36,7 36,7 @@ export fn load(src: io::handle, opts: load_option...) (value | error) = {
// See the documentation for [[load]] for information on dealing with
// potentially malicious inputs.
export fn loadstr(input: str, opts: load_option...) (value | error) = {
	let src = bufio::fixed(strings::toutf8(input), io::mode::READ);
	let src = memio::fixed(strings::toutf8(input));
	return load(&src, opts...);
};