Skip to content

Commit

Permalink
Add source_info to VariableDefinition AST struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Nov 19, 2024
1 parent ac90de8 commit d955752
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/hurl_core/src/ast/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ pub enum DurationOption {

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VariableDefinition {
pub source_info: SourceInfo,
pub name: String,
pub space0: Whitespace,
pub space1: Whitespace,
Expand Down
18 changes: 10 additions & 8 deletions packages/hurl_core/src/parser/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,19 @@ fn duration_option(reader: &mut Reader) -> ParseResult<DurationOption> {
}

fn variable_definition(reader: &mut Reader) -> ParseResult<VariableDefinition> {
let start = reader.cursor();
let name = variable_name(reader)?;
let space0 = zero_or_more_spaces(reader)?;
literal("=", reader)?;
let space1 = zero_or_more_spaces(reader)?;
let value = variable_value(reader)?;
let end = reader.cursor();
let source_info = SourceInfo {
start: start.pos,
end: end.pos,
};
Ok(VariableDefinition {
source_info,
name,
space0,
space1,
Expand Down Expand Up @@ -631,20 +638,15 @@ mod tests {
assert_eq!(
variable_definition(&mut reader).unwrap(),
VariableDefinition {
source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 4)),
name: "a".to_string(),
space0: Whitespace {
value: String::new(),
source_info: SourceInfo {
start: Pos { line: 1, column: 2 },
end: Pos { line: 1, column: 2 },
},
source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 2)),
},
space1: Whitespace {
value: String::new(),
source_info: SourceInfo {
start: Pos { line: 1, column: 3 },
end: Pos { line: 1, column: 3 },
},
source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 3)),
},
value: VariableValue::Number(Number::Integer(1)),
}
Expand Down

0 comments on commit d955752

Please sign in to comment.