Major updates/cleanup.
This commit is contained in:
@@ -11,12 +11,9 @@ void Parser::operation() {
|
||||
if (len == 0)
|
||||
throw ed_error("Function not found.");
|
||||
functions::Function *function = bed.functions.get_ptr(peek_str(len));
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + len,
|
||||
.type = io::Token::Function}
|
||||
);
|
||||
token(io::Token::Function);
|
||||
advance(len);
|
||||
end_token();
|
||||
command->function = function;
|
||||
char suffix = '\0';
|
||||
switch (command->function->argument_kind) {
|
||||
@@ -32,21 +29,15 @@ void Parser::operation() {
|
||||
command->argument = peek();
|
||||
else
|
||||
throw ed_error("Valid mark needed.");
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + (uint64_t)1,
|
||||
.type = io::Token::Mark}
|
||||
);
|
||||
token(io::Token::Mark);
|
||||
advance();
|
||||
end_token();
|
||||
break;
|
||||
case functions::Function::ArgumentKind::Any:
|
||||
command->argument = std::string(peek_str());
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + peek_str().size(),
|
||||
.type = io::Token::Any}
|
||||
);
|
||||
token(io::Token::Data);
|
||||
advance(peek_str().size());
|
||||
end_token();
|
||||
break;
|
||||
case functions::Function::ArgumentKind::Global: {
|
||||
char delim;
|
||||
@@ -123,31 +114,22 @@ void Parser::operation() {
|
||||
skip_ws();
|
||||
switch (peek()) {
|
||||
case '!':
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = (uint64_t)i + 1,
|
||||
.type = io::Token::Error}
|
||||
);
|
||||
token(io::Token::Error);
|
||||
advance();
|
||||
end_token();
|
||||
token(io::Token::Shell);
|
||||
command->argument = functions::Function::ShellArg(std::string(peek_str()));
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + peek_str().size(),
|
||||
.type = io::Token::Shell}
|
||||
);
|
||||
advance(peek_str().size());
|
||||
end_token();
|
||||
break;
|
||||
case '\0':
|
||||
command->argument = std::monostate();
|
||||
break;
|
||||
default:
|
||||
token(io::Token::File);
|
||||
command->argument = std::filesystem::path(peek_str());
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + peek_str().size(),
|
||||
.type = io::Token::File}
|
||||
);
|
||||
advance(peek_str().size());
|
||||
end_token();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -163,7 +145,7 @@ void Parser::operation() {
|
||||
char delim = peek();
|
||||
if (delim == '\0')
|
||||
throw ed_error("regex expected");
|
||||
uint16_t start = i;
|
||||
token(io::Token::Regexp);
|
||||
advance();
|
||||
uint16_t j = 0;
|
||||
while (true) {
|
||||
@@ -203,20 +185,13 @@ void Parser::operation() {
|
||||
advance(j);
|
||||
options = "p";
|
||||
}
|
||||
tokens->push_back(
|
||||
{.start = start,
|
||||
.end = i,
|
||||
.type = io::Token::Regexp}
|
||||
);
|
||||
end_token();
|
||||
token(io::Token::Suffix);
|
||||
if (peek() != '\0') {
|
||||
options = std::string(peek_str());
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + peek_str().size(),
|
||||
.type = io::Token::Suffix}
|
||||
);
|
||||
advance(peek_str().size());
|
||||
}
|
||||
end_token();
|
||||
std::erase_if(options, [&](char c) {
|
||||
if (bed.suffixes[c - 'a'].has_value()) {
|
||||
suffix = c;
|
||||
@@ -243,22 +218,16 @@ void Parser::operation() {
|
||||
} break;
|
||||
case functions::Function::ArgumentKind::Shell:
|
||||
command->argument = functions::Function::ShellArg(std::string(peek_str()));
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + peek_str().size(),
|
||||
.type = io::Token::Shell}
|
||||
);
|
||||
token(io::Token::Shell);
|
||||
advance(peek_str().size());
|
||||
end_token();
|
||||
break;
|
||||
}
|
||||
if (!suffix) {
|
||||
suffix = peek();
|
||||
tokens->push_back(
|
||||
{.start = i,
|
||||
.end = i + (uint64_t)1,
|
||||
.type = io::Token::Suffix}
|
||||
);
|
||||
token(io::Token::Suffix);
|
||||
advance();
|
||||
end_token();
|
||||
}
|
||||
if (suffix) {
|
||||
auto &s = bed.suffixes[suffix - 'a'];
|
||||
|
||||
Reference in New Issue
Block a user