Refactor parse_location
This commit is contained in:
parent
c6b152a6cf
commit
4caa5d2fdc
29
src/main.rs
29
src/main.rs
@ -640,28 +640,23 @@ fn parse_location(
|
|||||||
symbol_tables: &HashMap<String, HashMap<String, Symbol>>,
|
symbol_tables: &HashMap<String, HashMap<String, Symbol>>,
|
||||||
) -> Result<Location, Error> {
|
) -> Result<Location, Error> {
|
||||||
parse::<u32>(location).map(Location::Address).or_else(|_| {
|
parse::<u32>(location).map(Location::Address).or_else(|_| {
|
||||||
let (table_name, symbol_name) = location.split_once(':').unwrap_or(("", location));
|
let (mut table_name, symbol_name) = location.split_once(':').unwrap_or(("", location));
|
||||||
if table_name.is_empty() {
|
if table_name.is_empty() {
|
||||||
for (curr_table_name, table) in symbol_tables.iter() {
|
table_name = symbol_tables
|
||||||
if table.contains_key(symbol_name) {
|
.iter()
|
||||||
return Ok(Location::Symbol((
|
.find(|(_, table)| table.contains_key(symbol_name))
|
||||||
curr_table_name.to_string(),
|
.ok_or(Error::InvalidSymbolName)?
|
||||||
symbol_name.to_string(),
|
.0;
|
||||||
)));
|
} else if !symbol_tables
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(Error::InvalidSymbolName)
|
|
||||||
} else if symbol_tables
|
|
||||||
.get(table_name)
|
.get(table_name)
|
||||||
.ok_or(Error::InvalidSymbolTable)?
|
.ok_or(Error::InvalidSymbolTable)?
|
||||||
.contains_key(symbol_name)
|
.contains_key(symbol_name)
|
||||||
{
|
{
|
||||||
Ok(Location::Symbol((
|
return Err(Error::InvalidSymbolName);
|
||||||
table_name.to_string(),
|
|
||||||
symbol_name.to_string(),
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
Err(Error::InvalidSymbolName)
|
|
||||||
}
|
}
|
||||||
|
Ok(Location::Symbol((
|
||||||
|
table_name.to_string(),
|
||||||
|
symbol_name.to_string(),
|
||||||
|
)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user