~sircmpwn/ipcgen

3931f5b6df7c222ac3c6b18fbbb919e73dfce340 — Drew DeVault 1 year, 7 months ago 9ab776c
parse error declarations
2 files changed, 26 insertions(+), 1 deletions(-)

M ast/ast.ha
M parse/document.ha
M ast/ast.ha => ast/ast.ha +7 -0
@@ 3,6 3,7 @@ export type document = struct {
	namespace: ident,
	imports: []ident,
	interfaces: []interface,
	errors: []error,
};

// An IPC interface.


@@ 13,6 14,12 @@ export type interface = struct {
	methods: []method,
};

// An error type.
export type error = struct {
	name: str,
	value: ipc_type,
};

// An IPC method.
export type method = struct {
	name: str,

M parse/document.ha => parse/document.ha +19 -1
@@ 1,4 1,5 @@
use ast;
use ast::{ptype};
use lex;
use lex::{ltok};
use strings;


@@ 27,7 28,8 @@ export fn document(lex: *lex::lexer) (ast::document | error) = {
		case ltok::ENUM =>
			abort(); // TODO
		case ltok::ERROR =>
			abort(); // TODO
			const err = parse_error(lex)?;
			append(doc.errors, err);
		case ltok::EOF =>
			break;
		};


@@ 52,3 54,19 @@ fn imports(lex: *lex::lexer) ([]ast::ident | error) = {
	};
	return imports;
};

fn parse_error(lex: *lex::lexer) (ast::error | error) = {
	const name = strings::dup(want(lex, ltok::WORD)?.1 as str);

	let value: ast::ipc_type = ptype::VOID;
	if (try(lex, ltok::COLON)? is lex::token) {
		value = ipc_type(lex)?;
	};

	want(lex, ltok::SEMICOLON)?;

	return ast::error {
		name = name,
		value = value,
	};
};