Fix context bug
This commit is contained in:
parent
0edb42836d
commit
0aebd81665
@ -176,6 +176,8 @@ impl<'a> Analyzer<'a> {
|
|||||||
expression: &Expression,
|
expression: &Expression,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
) -> Result<(), ContextError> {
|
) -> Result<(), ContextError> {
|
||||||
|
log::trace!("Analyzing expression {expression}");
|
||||||
|
|
||||||
match expression {
|
match expression {
|
||||||
Expression::Block(block_expression) => {
|
Expression::Block(block_expression) => {
|
||||||
self.analyze_block(&block_expression.inner, context)?;
|
self.analyze_block(&block_expression.inner, context)?;
|
||||||
@ -343,6 +345,8 @@ impl<'a> Analyzer<'a> {
|
|||||||
Expression::Identifier(identifier) => {
|
Expression::Identifier(identifier) => {
|
||||||
let context_data = context.get_data(&identifier.inner)?;
|
let context_data = context.get_data(&identifier.inner)?;
|
||||||
|
|
||||||
|
println!("{:?}", context_data);
|
||||||
|
|
||||||
if let Some(ContextData::Reserved) | None = context_data {
|
if let Some(ContextData::Reserved) | None = context_data {
|
||||||
self.errors.push(AnalysisError::UndefinedVariable {
|
self.errors.push(AnalysisError::UndefinedVariable {
|
||||||
identifier: identifier.clone(),
|
identifier: identifier.clone(),
|
||||||
|
@ -42,7 +42,14 @@ impl Context {
|
|||||||
|
|
||||||
/// Returns the number of associated identifiers in the context.
|
/// Returns the number of associated identifiers in the context.
|
||||||
pub fn association_count(&self) -> Result<usize, ContextError> {
|
pub fn association_count(&self) -> Result<usize, ContextError> {
|
||||||
Ok(self.associations.read()?.len())
|
let own_count = self.associations.read()?.len();
|
||||||
|
let ancestor_count = if let Some(parent) = &self.parent {
|
||||||
|
parent.association_count()?
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(own_count + ancestor_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a boolean indicating whether the identifier is in the context.
|
/// Returns a boolean indicating whether the identifier is in the context.
|
||||||
@ -274,7 +281,7 @@ impl Context {
|
|||||||
if found {
|
if found {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if let Some(parent) = &self.parent {
|
} else if let Some(parent) = &self.parent {
|
||||||
let found_in_ancestor = parent.update_last_position(identifier, position)?;
|
let found_in_ancestor = parent.update_position_if_found(identifier, position)?;
|
||||||
|
|
||||||
if !found_in_ancestor {
|
if !found_in_ancestor {
|
||||||
let mut associations = self.associations.write()?;
|
let mut associations = self.associations.write()?;
|
||||||
|
@ -1018,9 +1018,16 @@ impl<'src> Parser<'src> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let context = context.create_child();
|
||||||
|
|
||||||
|
log::trace!(
|
||||||
|
"Creating new block context with {} associations",
|
||||||
|
context.association_count()?
|
||||||
|
);
|
||||||
|
|
||||||
let mut ast = AbstractSyntaxTree {
|
let mut ast = AbstractSyntaxTree {
|
||||||
statements: VecDeque::new(),
|
statements: VecDeque::new(),
|
||||||
context: context.create_child(),
|
context,
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
Loading…
Reference in New Issue
Block a user