Let locations be ranges, not just specific indexes.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
use std::fmt;
|
||||
use std::hash::Hash;
|
||||
|
||||
use internment::ArcIntern;
|
||||
|
||||
pub use crate::syntax::tokens::ConstantType;
|
||||
use crate::syntax::Location;
|
||||
|
||||
@@ -14,6 +19,50 @@ pub struct Program {
|
||||
pub statements: Vec<Statement>,
|
||||
}
|
||||
|
||||
/// A Name.
|
||||
///
|
||||
/// This is basically a string, but annotated with the place the string
|
||||
/// is in the source file.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Name {
|
||||
pub name: String,
|
||||
pub location: Location,
|
||||
}
|
||||
|
||||
impl Name {
|
||||
pub fn new<S: ToString>(n: S, location: Location) -> Name {
|
||||
Name{ name: n.to_string(), location }
|
||||
}
|
||||
|
||||
pub fn manufactured<S: ToString>(n: S) -> Name {
|
||||
Name{ name: n.to_string(), location: Location::manufactured() }
|
||||
}
|
||||
|
||||
pub fn intern(self) -> ArcIntern<String> {
|
||||
ArcIntern::new(self.name)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Name {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Name {}
|
||||
|
||||
impl Hash for Name {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.name.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Name {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.name.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// A parsed statement.
|
||||
///
|
||||
/// Statements are guaranteed to be syntactically valid, but may be
|
||||
@@ -27,8 +76,8 @@ pub struct Program {
|
||||
/// thing, not if they are the exact same statement.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Statement {
|
||||
Binding(Location, String, Expression),
|
||||
Print(Location, String),
|
||||
Binding(Location, Name, Expression),
|
||||
Print(Location, Name),
|
||||
}
|
||||
|
||||
impl PartialEq for Statement {
|
||||
|
||||
Reference in New Issue
Block a user