mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-08-15 14:50:42 +03:00
Dont allow variable names contain '__'
This commit is contained in:
parent
cdbaf66da6
commit
20a20027d3
@ -372,7 +372,10 @@ some_var
|
||||
foo/bar
|
||||
```
|
||||
|
||||
A variable can be anything matching the regex `[A-Za-z0-9_.-/]+`.
|
||||
A variable can be anything matching the regex `[A-Za-z0-9_.-/]+` but with some restrictions:
|
||||
|
||||
- It can not start with `//`
|
||||
- It can not contain `__`
|
||||
|
||||
A variable is a name for some immutable expression. It is possible to rebind variables with the same name.
|
||||
|
||||
@ -681,7 +684,10 @@ The constructors inherit the name of their types and become functions (`Tree/Nod
|
||||
|
||||
### Variables
|
||||
|
||||
A variable can be anything matching the regex `[A-Za-z0-9_.-/]+`.
|
||||
A variable can be anything matching the regex `[A-Za-z0-9_.-/]+` but with some restrictions:
|
||||
|
||||
- It can not start with `//`
|
||||
- It can not contain `__`
|
||||
|
||||
A variable is a name for some immutable expression. It is possible to rebind variables with the same name.
|
||||
|
||||
|
@ -821,8 +821,17 @@ pub trait ParserCommons<'a>: Parser<'a> {
|
||||
}
|
||||
|
||||
fn parse_bend_name(&mut self) -> ParseResult<Name> {
|
||||
let ini_idx = *self.index();
|
||||
let name = self.take_while(|c| c.is_ascii_alphanumeric() || c == '_' || c == '.' || c == '-' || c == '/');
|
||||
if name.is_empty() { self.expected("name") } else { Ok(Name::new(name.to_owned())) }
|
||||
let end_idx = *self.index();
|
||||
if name.contains("__") {
|
||||
let msg = "Variable names are not allowed to contain \"__\".".to_string();
|
||||
self.with_ctx(Err(msg), ini_idx, end_idx)
|
||||
} else if name.is_empty() {
|
||||
self.expected("name")
|
||||
} else {
|
||||
Ok(Name::new(name.to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes exactly the text without skipping.
|
||||
|
@ -0,0 +1,2 @@
|
||||
def main:
|
||||
return __this_should_fail__(*)
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/compile_file/variable_name_double_underscore.bend
|
||||
---
|
||||
[4m[1m[31mErrors:[0m
|
||||
In tests/golden_tests/compile_file/variable_name_double_underscore.bend :
|
||||
[1m- expected:[0m expression
|
||||
[1m- detected:[0m
|
||||
[0m 2 | return __this_should_fail__[4m[31m([0m*)[0m
|
Loading…
Reference in New Issue
Block a user