commit cd711543cce22ff401faed8287b4191cf683f3b1
parent 6efed7de7248d0a56a146a20234bb7a32ab2b26e
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 22 Feb 2021 13:15:09 -0500
hare::*: s/identifier/ident/g
Diffstat:
3 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/hare/ast/types.ha b/hare/ast/types.ha
@@ -1,13 +1,14 @@
// Identifies a single object, e.g. foo::bar::baz
-export type identifier = struct {
+export type ident = struct {
name: str,
- ns: nullable *identifier,
+ ns: nullable *ident,
};
-export fn identifier_finish(ident: *identifier) void = {
+// Frees resources associated with an identifier
+export fn ident_finish(ident: *ident) void = {
match (ident.ns) {
null => void,
- ns: *identifier => identifier_finish(ns),
+ ns: *ident => ident_finish(ns),
};
free(ident.name);
};
@@ -19,17 +20,17 @@ export type subunit = struct {
};
// use module;
-export type import_module = identifier;
+export type import_module = ident;
// use alias = module;
export type import_alias = struct {
- ident: identifier,
+ ident: ident,
alias: str,
};
// use module::{foo, bar, baz};
export type import_objects = struct {
- ident: identifier,
+ ident: ident,
objects: []str,
};
diff --git a/hare/parse/+test.ha b/hare/parse/+test.ha
@@ -3,13 +3,13 @@ use hare::ast;
use hare::lex;
use strings;
-@test fn identifier() void = {
+@test fn ident() void = {
{
const in = "foo";
let buf = bufio::fixed(strings::to_utf8(in));
let lexer = lex::lexer_init(buf, "<test>");
- let ident = identifier(&lexer) as ast::identifier;
- defer ast::identifier_finish(&ident);
+ let ident = ident(&lexer) as ast::ident;
+ defer ast::ident_finish(&ident);
assert(ident.name == "foo");
assert(ident.ns == null);
assert(lex::lex(&lexer) is io::EOF);
@@ -19,12 +19,12 @@ use strings;
const in = "foo::bar";
let buf = bufio::fixed(strings::to_utf8(in));
let lexer = lex::lexer_init(buf, "<test>");
- let ident = identifier(&lexer) as ast::identifier;
- defer ast::identifier_finish(&ident);
+ let ident = ident(&lexer) as ast::ident;
+ defer ast::ident_finish(&ident);
assert(ident.name == "foo");
match (ident.ns) {
null => abort(),
- ns: *ast::identifier => {
+ ns: *ast::ident => {
assert(ns.name == "bar");
assert(ns.ns == null);
},
@@ -36,16 +36,16 @@ use strings;
const in = "foo::bar::baz";
let buf = bufio::fixed(strings::to_utf8(in));
let lexer = lex::lexer_init(buf, "<test>");
- let ident = identifier(&lexer) as ast::identifier;
- defer ast::identifier_finish(&ident);
+ let ident = ident(&lexer) as ast::ident;
+ defer ast::ident_finish(&ident);
assert(ident.name == "foo");
match (ident.ns) {
null => abort(),
- ns: *ast::identifier => {
+ ns: *ast::ident => {
assert(ns.name == "bar");
match (ns.ns) {
null => abort(),
- ns: *ast::identifier => {
+ ns: *ast::ident => {
assert(ns.name == "baz");
assert(ns.ns == null);
},
@@ -59,12 +59,12 @@ use strings;
const in = "foo::bar;";
let buf = bufio::fixed(strings::to_utf8(in));
let lexer = lex::lexer_init(buf, "<test>");
- let ident = identifier(&lexer) as ast::identifier;
- defer ast::identifier_finish(&ident);
+ let ident = ident(&lexer) as ast::ident;
+ defer ast::ident_finish(&ident);
assert(ident.name == "foo");
match (ident.ns) {
null => abort(),
- ns: *ast::identifier => {
+ ns: *ast::ident => {
assert(ns.name == "bar");
assert(ns.ns == null);
},
diff --git a/hare/parse/parse.ha b/hare/parse/parse.ha
@@ -8,8 +8,8 @@ export type error = lex::error;
export fn errstr(err: error) const str = lex::errstr(err: lex::error);
// Parses a single identifier, i.e. foo::bar::baz
-export fn identifier(lexer: *lex::lexer) (ast::identifier | error) = {
- let ident = ast::identifier { ... }, cur = &ident;
+export fn ident(lexer: *lex::lexer) (ast::ident | error) = {
+ let ident = ast::ident { ... }, cur = &ident;
for (true) {
let tok = lex::lex(lexer);
match (tok) {
@@ -31,8 +31,8 @@ export fn identifier(lexer: *lex::lexer) (ast::identifier | error) = {
t: (lex::token, lex::location) => match (t.0) {
b: lex::btoken => switch (b) {
hare::lex::btoken::DOUBLE_COLON => {
- let new = alloc(*ast::identifier,
- ast::identifier { ... });
+ let new = alloc(*ast::ident,
+ ast::ident { ... });
cur.ns = new;
cur = new;
},