mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -04:00
FEATURE: Check bindings against the reserved word list for imports and let bindings.
This commit is contained in:
parent
5e07f24d91
commit
1365a38700
@ -8,8 +8,10 @@ assert |=|;
|
||||
assert |let |;
|
||||
assert |let foo |;
|
||||
assert |let foo =|;
|
||||
//assert |import |;
|
||||
//assert |import foo |;
|
||||
//assert |out |;
|
||||
//assert |out "|;
|
||||
//assert |out json|;
|
||||
assert |import |;
|
||||
assert |import foo |;
|
||||
assert |out |;
|
||||
assert |out "|;
|
||||
assert |out json|;
|
||||
|
||||
assert |let env = 1;|;
|
@ -24,7 +24,7 @@ let embedded_mod = module {
|
||||
deep_value = "None",
|
||||
env = "None",
|
||||
} => {
|
||||
let env = select mod.env, "qa", {
|
||||
let env_name = select mod.env, "qa", {
|
||||
None = "qa",
|
||||
prod = "prod",
|
||||
qa = "qa",
|
||||
@ -46,7 +46,7 @@ assert |
|
||||
|;
|
||||
|
||||
assert |
|
||||
embedded_default_params.env == "qa";
|
||||
embedded_default_params.env_name == "qa";
|
||||
|;
|
||||
|
||||
let embedded_with_params = embedded_mod{deep_value = "Some"};
|
||||
|
@ -303,8 +303,27 @@ impl<'a> Builder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_reserved_word(name: &str) -> bool {
|
||||
match name {
|
||||
"self" | "assert" | "true" | "false" | "let" | "import" | "as" | "select" | "macro"
|
||||
| "module" | "env" | "map" | "filter" | "NULL" | "out" => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_import(&mut self, def: &ImportDef) -> Result<Rc<Val>, Box<Error>> {
|
||||
let sym = &def.name;
|
||||
// TODO(jwall): Enforce reserved word restriction here.
|
||||
if Self::check_reserved_word(&sym.fragment) {
|
||||
return Err(Box::new(error::BuildError::new(
|
||||
format!(
|
||||
"Import {} binding collides with reserved word",
|
||||
sym.fragment
|
||||
),
|
||||
error::ErrorType::ReservedWordError,
|
||||
sym.pos.clone(),
|
||||
)));
|
||||
}
|
||||
let mut normalized = self.file.clone();
|
||||
let import_path = PathBuf::from(&def.path.fragment);
|
||||
if import_path.is_relative() {
|
||||
@ -344,6 +363,14 @@ impl<'a> Builder<'a> {
|
||||
fn build_let(&mut self, def: &LetDef) -> Result<Rc<Val>, Box<Error>> {
|
||||
let val = try!(self.eval_expr(&def.value));
|
||||
let name = &def.name;
|
||||
// TODO(jwall): Enforce the reserved words list here.
|
||||
if Self::check_reserved_word(&name.fragment) {
|
||||
return Err(Box::new(error::BuildError::new(
|
||||
format!("Let {} binding collides with reserved word", name.fragment),
|
||||
error::ErrorType::ReservedWordError,
|
||||
name.pos.clone(),
|
||||
)));
|
||||
}
|
||||
match self.build_output.entry(name.into()) {
|
||||
Entry::Occupied(e) => {
|
||||
return Err(Box::new(error::BuildError::new(
|
||||
|
@ -31,6 +31,7 @@ pub enum ErrorType {
|
||||
NoSuchSymbol,
|
||||
BadArgLen,
|
||||
FormatError,
|
||||
ReservedWordError,
|
||||
// Parsing Errors
|
||||
ParseError,
|
||||
AssertError,
|
||||
@ -45,6 +46,7 @@ impl fmt::Display for ErrorType {
|
||||
&ErrorType::NoSuchSymbol => "NoSuchSymbol",
|
||||
&ErrorType::BadArgLen => "BadArgLen",
|
||||
&ErrorType::FormatError => "FormatError",
|
||||
&ErrorType::ReservedWordError => "ReservedWordError",
|
||||
&ErrorType::ParseError => "ParseError",
|
||||
&ErrorType::AssertError => "AssertError",
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user