allow dashes in member access

This commit is contained in:
damirka 2021-08-05 17:53:08 +03:00
parent 55f110b6b6
commit 9d3d76fc63
4 changed files with 49 additions and 1 deletions

View File

@ -173,7 +173,19 @@ impl ParserContext {
if let Some(SpannedToken { span, .. }) = self.eat(Token::Mul) {
Ok(PackageAccess::Star { span })
} else {
let name = self.expect_ident()?;
let mut name = self.expect_ident()?;
// Allow dashes in the accessed members (should only be used for directories).
// If imported member does not exist, code will fail on ASG level.
if let Token::Minus = self.peek_token().as_ref() {
let span = self.expect(Token::Minus)?;
name.span = name.span + span;
let next = self.expect_ident()?;
name.span = name.span + next.span;
name.name = format_tendril!("{}-{}", name.name, next.name);
}
// let name = self.parse_package_name()?;
if self.peek_token().as_ref() == &Token::Dot {
self.backtrack(SpannedToken {
token: Token::Ident(name.name),

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
cwd: local_imports
*/
import a-9.nested.c-d.*;
function main(y: bool) -> bool {
return y == cd();
}

View File

@ -0,0 +1,3 @@
function cd() -> bool {
return true;
}

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 98debe360fb6fbede5a9db625cbc2e4e4dfddcb23f40e3914e909157334e1d70
canonicalized_ast: 98debe360fb6fbede5a9db625cbc2e4e4dfddcb23f40e3914e909157334e1d70
type_inferenced_ast: 50c06c3666a830c7f1fd533c412a4e8054fdb494845f4f5d85414b08f1c1a8dd