tamer: Air{Token=>}

Consistency with `Nir` et al.

DEV-13430
main
Mike Gerwitz 2022-12-13 14:36:38 -05:00
parent be41d056bb
commit 56d1ecf0a3
6 changed files with 44 additions and 46 deletions

View File

@ -59,7 +59,7 @@ pub type DepSym = SymbolId;
/// populating the ASG with the raw data that that will be
/// subsequently analyzed and rewritten.
#[derive(Debug, PartialEq)]
pub enum AirToken {
pub enum Air {
/// Placeholder token for objects that do not yet have a proper place on
/// the ASG.
Todo,
@ -76,7 +76,7 @@ pub enum AirToken {
IdentRoot(IdentSym),
}
impl Token for AirToken {
impl Token for Air {
fn ir_name() -> &'static str {
"AIR"
}
@ -88,11 +88,11 @@ impl Token for AirToken {
}
}
impl parse::Object for AirToken {}
impl parse::Object for Air {}
impl Display for AirToken {
impl Display for Air {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use AirToken::*;
use Air::*;
match self {
Todo => write!(f, "TODO"),
@ -127,7 +127,7 @@ pub enum AirAggregate {
}
impl ParseState for AirAggregate {
type Token = AirToken;
type Token = Air;
type Object = ();
type Error = AsgError;
@ -141,8 +141,8 @@ impl ParseState for AirAggregate {
tok: Self::Token,
asg: &mut Self::Context,
) -> crate::parse::TransitionResult<Self> {
use Air::*;
use AirAggregate::*;
use AirToken::*;
match (self, tok) {
(Empty, Todo) => Transition(Empty).incomplete(),

View File

@ -40,8 +40,7 @@ fn ident_decl() {
..Default::default()
};
let toks =
vec![AirToken::IdentDecl(sym, kind.clone(), src.clone())].into_iter();
let toks = vec![Air::IdentDecl(sym, kind.clone(), src.clone())].into_iter();
let mut sut = Sut::parse(toks);
assert_eq!(Some(Ok(Parsed::Incomplete)), sut.next());
@ -62,7 +61,7 @@ fn ident_decl() {
// Re-instantiate the parser and test an error by attempting to
// redeclare the same identifier.
let bad_toks = vec![AirToken::IdentDecl(sym, kind, src)].into_iter();
let bad_toks = vec![Air::IdentDecl(sym, kind, src)].into_iter();
let mut sut = Sut::parse_with_context(bad_toks, asg);
assert_matches!(
@ -80,8 +79,8 @@ fn ident_extern_decl() {
..Default::default()
};
let toks = vec![AirToken::IdentExternDecl(sym, kind.clone(), src.clone())]
.into_iter();
let toks =
vec![Air::IdentExternDecl(sym, kind.clone(), src.clone())].into_iter();
let mut sut = Sut::parse(toks);
assert_eq!(Some(Ok(Parsed::Incomplete)), sut.next());
@ -104,7 +103,7 @@ fn ident_extern_decl() {
// redeclare with a different kind.
let different_kind = IdentKind::Meta;
let bad_toks =
vec![AirToken::IdentExternDecl(sym, different_kind, src)].into_iter();
vec![Air::IdentExternDecl(sym, different_kind, src)].into_iter();
let mut sut = Sut::parse_with_context(bad_toks, asg);
assert_matches!(
@ -118,7 +117,7 @@ fn ident_dep() {
let ident = "foo".into();
let dep = "dep".into();
let toks = vec![AirToken::IdentDep(ident, dep)].into_iter();
let toks = vec![Air::IdentDep(ident, dep)].into_iter();
let mut sut = Sut::parse(toks);
assert_eq!(Some(Ok(Parsed::Incomplete)), sut.next());
@ -146,8 +145,8 @@ fn ident_fragment() {
let toks = vec![
// Identifier must be declared before it can be given a
// fragment.
AirToken::IdentDecl(sym, kind.clone(), src.clone()),
AirToken::IdentFragment(sym, frag),
Air::IdentDecl(sym, kind.clone(), src.clone()),
Air::IdentFragment(sym, frag),
]
.into_iter();
@ -173,7 +172,7 @@ fn ident_fragment() {
// Re-instantiate the parser and test an error by attempting to
// re-set the fragment.
let bad_toks = vec![AirToken::IdentFragment(sym, frag)].into_iter();
let bad_toks = vec![Air::IdentFragment(sym, frag)].into_iter();
let mut sut = Sut::parse_with_context(bad_toks, asg);
assert_matches!(
@ -188,7 +187,7 @@ fn ident_fragment() {
fn ident_root_missing() {
let sym = "toroot".into();
let toks = vec![AirToken::IdentRoot(sym)].into_iter();
let toks = vec![Air::IdentRoot(sym)].into_iter();
let mut sut = Sut::parse(toks);
assert_eq!(Some(Ok(Parsed::Incomplete)), sut.next());
@ -222,8 +221,8 @@ fn ident_root_existing() {
assert!(!kind.is_auto_root());
let toks = vec![
AirToken::IdentDecl(sym, kind.clone(), src.clone()),
AirToken::IdentRoot(sym),
Air::IdentDecl(sym, kind.clone(), src.clone()),
Air::IdentRoot(sym),
]
.into_iter();

View File

@ -35,7 +35,7 @@ use std::{
};
use tamer::{
asg::{
air::{AirAggregate, AirToken as Air},
air::{Air, AirAggregate},
AsgError, DefaultAsg,
},
diagnose::{

View File

@ -27,7 +27,7 @@ use super::xmle::{
};
use crate::{
asg::{
air::{AirAggregate, AirToken},
air::{Air, AirAggregate},
Asg, AsgError, DefaultAsg, Ident, Object,
},
diagnose::{AnnotatedSpan, Diagnostic},
@ -286,7 +286,7 @@ pub enum TameldError {
XirfParseError(ParseError<XirToken, XirToXirfError>),
XmloParseError(ParseError<XirfToken<Text>, XmloError>),
XmloLowerError(ParseError<XmloToken, XmloAirError>),
AirLowerError(ParseError<AirToken, AsgError>),
AirLowerError(ParseError<Air, AsgError>),
XirWriterError(XirWriterError),
FinalizeError(FinalizeError),
CycleError(Vec<Vec<SymbolId>>),
@ -329,8 +329,8 @@ impl From<ParseError<XmloToken, XmloAirError>> for TameldError {
}
}
impl From<ParseError<AirToken, AsgError>> for TameldError {
fn from(e: ParseError<AirToken, AsgError>) -> Self {
impl From<ParseError<Air, AsgError>> for TameldError {
fn from(e: ParseError<Air, AsgError>) -> Self {
Self::AirLowerError(e)
}
}

View File

@ -21,9 +21,7 @@
use std::{error::Error, fmt::Display};
use crate::{
asg::air::AirToken as Air, diagnose::Diagnostic, parse::prelude::*,
};
use crate::{asg::air::Air, diagnose::Diagnostic, parse::prelude::*};
use super::Nir;

View File

@ -27,7 +27,7 @@ use std::{
use fxhash::FxHashSet;
use crate::{
asg::{air::AirToken, IdentKind, Source},
asg::{air::Air, IdentKind, Source},
diagnose::{AnnotatedSpan, Diagnostic},
obj::xmlo::{SymAttrs, SymType},
parse::{ParseState, ParseStatus, Transition, Transitionable},
@ -100,7 +100,7 @@ pub enum XmloToAir {
impl ParseState for XmloToAir {
type Token = XmloToken;
type Object = AirToken;
type Object = Air;
type Error = XmloAirError;
type Context = XmloAirContext;
@ -138,8 +138,9 @@ impl ParseState for XmloToAir {
(
Package(pkg_name, span),
XmloToken::PkgEligClassYields(pkg_elig, _),
) => Transition(Package(pkg_name, span))
.ok(AirToken::IdentRoot(pkg_elig)),
) => {
Transition(Package(pkg_name, span)).ok(Air::IdentRoot(pkg_elig))
}
(
st @ (PackageExpected | Package(..)),
@ -156,7 +157,7 @@ impl ParseState for XmloToAir {
(SymDep(pkg_name, span, sym), XmloToken::Symbol(dep_sym, _)) => {
Transition(SymDep(pkg_name, span, sym))
.ok(AirToken::IdentDep(sym, dep_sym))
.ok(Air::IdentDep(sym, dep_sym))
}
(
@ -199,11 +200,11 @@ impl ParseState for XmloToAir {
}
if extern_ {
Ok(ParseStatus::Object(AirToken::IdentExternDecl(
Ok(ParseStatus::Object(Air::IdentExternDecl(
sym, kindval, src,
)))
} else {
Ok(ParseStatus::Object(AirToken::IdentDecl(
Ok(ParseStatus::Object(Air::IdentDecl(
sym, kindval, src,
)))
}
@ -215,7 +216,7 @@ impl ParseState for XmloToAir {
Package(pkg_name, span) | SymDep(pkg_name, span, _),
XmloToken::Fragment(sym, text, _),
) => Transition(Package(pkg_name, span))
.ok(AirToken::IdentFragment(sym, text)),
.ok(Air::IdentFragment(sym, text)),
// We don't need to read any further than the end of the
// header (symtable, sym-deps, fragments).
@ -443,7 +444,7 @@ mod test {
assert_eq!(
Ok(vec![
Parsed::Incomplete, // PkgName
Parsed::Object(AirToken::IdentRoot(elig_sym)),
Parsed::Object(Air::IdentRoot(elig_sym)),
Parsed::Incomplete, // Eoh
]),
Sut::parse(toks.into_iter()).collect(),
@ -468,8 +469,8 @@ mod test {
Ok(vec![
Parsed::Incomplete, // PkgName
Parsed::Incomplete, // SymDepStart
Parsed::Object(AirToken::IdentDep(sym_from, sym_to1)),
Parsed::Object(AirToken::IdentDep(sym_from, sym_to2)),
Parsed::Object(Air::IdentDep(sym_from, sym_to1)),
Parsed::Object(Air::IdentDep(sym_from, sym_to2)),
Parsed::Incomplete, // Eoh
]),
Sut::parse(toks.into_iter()).collect(),
@ -576,7 +577,7 @@ mod test {
// since this is considered to be the first package encountered.
assert_eq!(Some(Ok(Parsed::Incomplete)), sut.next()); // PkgName
assert_eq!(
Some(Ok(Parsed::Object(AirToken::IdentExternDecl(
Some(Ok(Parsed::Object(Air::IdentExternDecl(
sym_extern,
IdentKind::Meta,
Source {
@ -587,7 +588,7 @@ mod test {
sut.next(),
);
assert_eq!(
Some(Ok(Parsed::Object(AirToken::IdentDecl(
Some(Ok(Parsed::Object(Air::IdentDecl(
sym_non_extern,
IdentKind::Meta,
Source {
@ -598,7 +599,7 @@ mod test {
sut.next(),
);
assert_eq!(
Some(Ok(Parsed::Object(AirToken::IdentDecl(
Some(Ok(Parsed::Object(Air::IdentDecl(
sym_map,
IdentKind::Map,
Source {
@ -609,7 +610,7 @@ mod test {
sut.next(),
);
assert_eq!(
Some(Ok(Parsed::Object(AirToken::IdentDecl(
Some(Ok(Parsed::Object(Air::IdentDecl(
sym_retmap,
IdentKind::RetMap,
Source {
@ -660,7 +661,7 @@ mod test {
assert_eq!(
Ok(vec![
Parsed::Incomplete, // PkgName
Parsed::Object(AirToken::IdentDecl(
Parsed::Object(Air::IdentDecl(
sym,
IdentKind::Meta,
Source {
@ -703,7 +704,7 @@ mod test {
assert_eq!(
Ok(vec![
Parsed::Incomplete, // PkgName
Parsed::Object(AirToken::IdentDecl(
Parsed::Object(Air::IdentDecl(
sym,
IdentKind::Meta,
Source {
@ -747,7 +748,7 @@ mod test {
assert_eq!(
Ok(vec![
Parsed::Incomplete, // PkgName
Parsed::Object(AirToken::IdentFragment(sym, frag)),
Parsed::Object(Air::IdentFragment(sym, frag)),
Parsed::Incomplete, // Eoh
]),
Sut::parse(toks.into_iter()).collect(),