mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:37:35 +00:00
Shell: Use the correct range for named variable expansions
Previously we were starting the variable expansions before the starting '$' and calculating the wrong length, this commit makes it so we calculate the right range for them.
This commit is contained in:
parent
79c76d67ce
commit
93413f8682
2 changed files with 12 additions and 12 deletions
|
@ -41,7 +41,7 @@ ErrorOr<Vector<Token>> Lexer::batch_next(Optional<Reduction> starting_reduction)
|
||||||
ExpansionRange Lexer::range(ssize_t offset) const
|
ExpansionRange Lexer::range(ssize_t offset) const
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
m_state.position.end_offset - m_state.position.start_offset + offset - 1,
|
m_state.position.end_offset - m_state.position.start_offset + offset,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -358,15 +358,15 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_double_quoted_string()
|
||||||
};
|
};
|
||||||
case '$':
|
case '$':
|
||||||
if (m_lexer.next_is("("))
|
if (m_lexer.next_is("("))
|
||||||
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range(-1) });
|
||||||
else
|
else
|
||||||
m_state.expansions.empend(ParameterExpansion { .parameter = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(ParameterExpansion { .parameter = StringBuilder {}, .range = range(-1) });
|
||||||
return ReductionResult {
|
return ReductionResult {
|
||||||
.tokens = {},
|
.tokens = {},
|
||||||
.next_reduction = Reduction::Expansion,
|
.next_reduction = Reduction::Expansion,
|
||||||
};
|
};
|
||||||
case '`':
|
case '`':
|
||||||
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range(-1) });
|
||||||
return ReductionResult {
|
return ReductionResult {
|
||||||
.tokens = {},
|
.tokens = {},
|
||||||
.next_reduction = Reduction::CommandExpansion,
|
.next_reduction = Reduction::CommandExpansion,
|
||||||
|
@ -498,9 +498,9 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_heredoc_contents()
|
||||||
if (!m_state.escaping && consume_specific('$')) {
|
if (!m_state.escaping && consume_specific('$')) {
|
||||||
m_state.buffer.append('$');
|
m_state.buffer.append('$');
|
||||||
if (m_lexer.next_is("("))
|
if (m_lexer.next_is("("))
|
||||||
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range(-1) });
|
||||||
else
|
else
|
||||||
m_state.expansions.empend(ParameterExpansion { .parameter = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(ParameterExpansion { .parameter = StringBuilder {}, .range = range(-1) });
|
||||||
|
|
||||||
return ReductionResult {
|
return ReductionResult {
|
||||||
.tokens = {},
|
.tokens = {},
|
||||||
|
@ -510,7 +510,7 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_heredoc_contents()
|
||||||
|
|
||||||
if (!m_state.escaping && consume_specific('`')) {
|
if (!m_state.escaping && consume_specific('`')) {
|
||||||
m_state.buffer.append('`');
|
m_state.buffer.append('`');
|
||||||
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range(-1) });
|
||||||
return ReductionResult {
|
return ReductionResult {
|
||||||
.tokens = {},
|
.tokens = {},
|
||||||
.next_reduction = Reduction::CommandExpansion,
|
.next_reduction = Reduction::CommandExpansion,
|
||||||
|
@ -682,9 +682,9 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_start()
|
||||||
if (!m_state.escaping && consume_specific('$')) {
|
if (!m_state.escaping && consume_specific('$')) {
|
||||||
m_state.buffer.append('$');
|
m_state.buffer.append('$');
|
||||||
if (m_lexer.next_is("("))
|
if (m_lexer.next_is("("))
|
||||||
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range(-1) });
|
||||||
else
|
else
|
||||||
m_state.expansions.empend(ParameterExpansion { .parameter = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(ParameterExpansion { .parameter = StringBuilder {}, .range = range(-1) });
|
||||||
|
|
||||||
return ReductionResult {
|
return ReductionResult {
|
||||||
.tokens = {},
|
.tokens = {},
|
||||||
|
@ -694,7 +694,7 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_start()
|
||||||
|
|
||||||
if (!m_state.escaping && consume_specific('`')) {
|
if (!m_state.escaping && consume_specific('`')) {
|
||||||
m_state.buffer.append('`');
|
m_state.buffer.append('`');
|
||||||
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range() });
|
m_state.expansions.empend(CommandExpansion { .command = StringBuilder {}, .range = range(-1) });
|
||||||
return ReductionResult {
|
return ReductionResult {
|
||||||
.tokens = {},
|
.tokens = {},
|
||||||
.next_reduction = Reduction::CommandExpansion,
|
.next_reduction = Reduction::CommandExpansion,
|
||||||
|
@ -749,7 +749,7 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_special_parameter_expansion()
|
||||||
m_state.buffer.append(ch);
|
m_state.buffer.append(ch);
|
||||||
m_state.expansions.last() = ParameterExpansion {
|
m_state.expansions.last() = ParameterExpansion {
|
||||||
.parameter = StringBuilder {},
|
.parameter = StringBuilder {},
|
||||||
.range = range(-1),
|
.range = range(-2),
|
||||||
};
|
};
|
||||||
auto& expansion = m_state.expansions.last().get<ParameterExpansion>();
|
auto& expansion = m_state.expansions.last().get<ParameterExpansion>();
|
||||||
expansion.parameter.append(ch);
|
expansion.parameter.append(ch);
|
||||||
|
|
|
@ -417,7 +417,7 @@ Vector<Token> Parser::perform_expansions(Vector<Token> tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResolvedParameterExpansion {
|
return ResolvedParameterExpansion {
|
||||||
.parameter = {},
|
.parameter = String::from_code_point(text[0]),
|
||||||
.argument = {},
|
.argument = {},
|
||||||
.range = expansion.range,
|
.range = expansion.range,
|
||||||
.op = op,
|
.op = op,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue