From e27adcdce55dc15c97bb0ac6d5bc0b082d2232c2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 9 Mar 2019 14:32:07 +0100 Subject: Use new Label type instead of &str in parser --- dhall_core/src/core.rs | 57 +++++++++++++++++++--- dhall_core/src/grammar_util.rs | 4 -- dhall_core/src/lib.rs | 1 - dhall_core/src/parser.rs | 104 +++++++++++++++++++++-------------------- 4 files changed, 105 insertions(+), 61 deletions(-) delete mode 100644 dhall_core/src/grammar_util.rs (limited to 'dhall_core/src') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index eed9e0c..7bd1318 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -68,6 +68,41 @@ pub struct Import { pub hash: Option<()>, } +// The type for labels throughout the AST +// It owns the data because otherwise lifetimes would make recursive imports impossible +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct Label(String); + +impl From for Label { + fn from(s: String) -> Self { + Label(s) + } +} + +impl From<&'static str> for Label { + fn from(s: &'static str) -> Self { + Label(s.to_owned()) + } +} + +impl From