Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nls/src/analyzer/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ pub struct VarDeclExpr {
pub type_: Type,
pub be_capture: bool,
pub heap_ident: Option<String>,
pub is_private: bool,
}

#[derive(Debug, Clone)]
Expand All @@ -1060,6 +1061,7 @@ pub struct AstConstDef {
pub symbol_id: NodeId,
pub symbol_start: usize,
pub symbol_end: usize,
pub is_private: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1177,6 +1179,7 @@ pub struct TypedefStmt {
pub is_tagged_union: bool,
pub impl_interfaces: Vec<Type>,
pub method_table: HashMap<String, Arc<Mutex<AstFnDef>>>, // key = ident, value = ast_fndef_t
pub is_private: bool,

pub symbol_start: usize,
pub symbol_end: usize,
Expand Down
2 changes: 2 additions & 0 deletions nls/src/analyzer/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ impl<'a> Semantic<'a> {
symbol_start: fndef.symbol_start,
symbol_end: fndef.symbol_end,
symbol_id: 0,
is_private: false,
};

new_params.push(Arc::new(Mutex::new(self_vardecl)));
Expand Down Expand Up @@ -1740,6 +1741,7 @@ impl<'a> Semantic<'a> {
symbol_start: start,
symbol_end: end,
symbol_id: 0,
is_private: false,
}));

Box::new(Stmt {
Expand Down
1 change: 1 addition & 0 deletions nls/src/analyzer/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ impl SymbolTable {
is_tagged_union: false,
impl_interfaces: Vec::new(),
method_table: HashMap::new(),
is_private: false,
symbol_start: 0,
symbol_end: 0,
symbol_id: 0,
Expand Down
48 changes: 46 additions & 2 deletions nls/src/analyzer/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ impl<'a> Syntax {
impl_interfaces,
method_table: HashMap::new(),
symbol_id: 0,
is_private: false,
})));
stmt.end = self.prev().unwrap().end;

Expand Down Expand Up @@ -1524,6 +1525,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
})))
}

Expand Down Expand Up @@ -1833,6 +1835,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
};

let catch_body = self.parser_body(true)?;
Expand Down Expand Up @@ -2360,6 +2363,7 @@ impl<'a> Syntax {
be_capture: false,
symbol_id: 0,
heap_ident: None,
is_private: false,
};

let second = if self.consume(TokenType::Comma) {
Expand All @@ -2372,6 +2376,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
})))
} else {
None
Expand Down Expand Up @@ -2926,6 +2931,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
})));
expr.end = self.prev().unwrap().end;
expr
Expand Down Expand Up @@ -2971,6 +2977,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
})),
self.parser_expr()?,
);
Expand Down Expand Up @@ -3004,6 +3011,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
})),
self.parser_expr()?,
);
Expand All @@ -3027,6 +3035,7 @@ impl<'a> Syntax {
symbol_start: const_ident.start,
symbol_end: const_ident.end,
symbol_id: 0,
is_private: false,
})));

Ok(stmt)
Expand Down Expand Up @@ -3321,6 +3330,7 @@ impl<'a> Syntax {

fn parser_label(&mut self) -> Result<Box<Stmt>, SyntaxError> {
let mut fndef = AstFnDef::default();
let mut is_private = false;

while self.is(TokenType::Label) {
let token = self.must(TokenType::Label)?;
Expand All @@ -3334,6 +3344,7 @@ impl<'a> Syntax {
fndef.linkid = Some(literal.literal.clone());
}
} else if token.literal == "local" {
is_private = true;
fndef.is_private = true;
} else if token.literal == "where" {
if fndef.pending_where_params.is_some() {
Expand Down Expand Up @@ -3368,14 +3379,44 @@ impl<'a> Syntax {
if fndef.pending_where_params.is_some() {
return Err(SyntaxError(self.peek().start, self.peek().end, "#where can only be applied to fn".to_string()));
}
self.parser_typedef_stmt()
let result = self.parser_typedef_stmt()?;
if is_private {
if let AstNode::Typedef(ref typedef) = result.node {
typedef.lock().unwrap().is_private = true;
}
}
Ok(result)
} else if self.is(TokenType::Fn) {
self.parser_fndef_stmt(fndef)
} else if self.is(TokenType::Const) {
let result = self.parser_constdef_stmt()?;
if is_private {
if let AstNode::ConstDef(ref constdef) = result.node {
constdef.lock().unwrap().is_private = true;
}
}
Ok(result)
} else if self.is(TokenType::Var) {
let result = self.parser_var_begin_stmt()?;
if is_private {
if let AstNode::VarDef(ref var_decl, _) = result.node {
var_decl.lock().unwrap().is_private = true;
}
}
Ok(result)
} else if self.is_type_begin_stmt() {
let result = self.parser_type_begin_stmt()?;
if is_private {
if let AstNode::VarDef(ref var_decl, _) = result.node {
var_decl.lock().unwrap().is_private = true;
}
}
Ok(result)
} else {
Err(SyntaxError(
self.peek().start,
self.peek().end,
format!("the label can only be used in type alias or fn"),
format!("the label can only be applied to type, fn, const, or var"),
))
}
}
Expand Down Expand Up @@ -3731,6 +3772,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
})),
call_expr.clone(),
);
Expand Down Expand Up @@ -3807,6 +3849,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
}));

let catch_body = self.parser_body(false)?;
Expand Down Expand Up @@ -3905,6 +3948,7 @@ impl<'a> Syntax {
be_capture: false,
heap_ident: None,
symbol_id: 0,
is_private: false,
})));
}

Expand Down
Loading