Skip to content

Conversation

@asfernandes
Copy link
Member

This is a work preparing ISQL for schemas support which I prefer to be done first and separated from the schemas branch.

@asfernandes asfernandes self-assigned this Dec 23, 2024
@asfernandes asfernandes force-pushed the work/isql-frontend-parser branch 2 times, most recently from 9dfa495 to 4894def Compare December 30, 2024 14:31
@asfernandes asfernandes force-pushed the work/isql-frontend-parser branch from 4894def to 7357355 Compare December 30, 2024 14:45
@asfernandes asfernandes merged commit 797781d into master Dec 30, 2024
48 checks passed
@asfernandes asfernandes deleted the work/isql-frontend-parser branch December 30, 2024 16:55
Copy link
Contributor

@TreeHunter9 TreeHunter9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review to an already merged PR.

std::string rawText;
std::string processedText;

std::string getProcessedString() const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better return const std::string&, NRVO or move constructor won't apply here, we will always make a copy, and as I can see in code, we use this function for simple read.

Comment on lines +251 to +240
(!first && c >= '0' && c <= '9') ||
(!first && c == '$') ||
(!first && c == '_')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better would be

			  (!first && ((c >= '0' && c <= '9') ||
			              (c == '$') ||
			              (c == '_')))

So we don't have to check first every time


const auto commandToken = lexer.getToken();

if (commandToken.type == Token::TYPE_OTHER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe invert this if statement to reduce nesting?

if (commandToken.type != Token::TYPE_OTHER)
    return InvalidNode();

Comment on lines +631 to +648
const auto objectTypeText = std::string(objectType->c_str());

if ((objectTypeText.length() >= 7 && std::string(TOKEN_COLLATES).find(objectTypeText) == 0) ||
(objectTypeText.length() >= 9 && std::string(TOKEN_COLLATIONS).find(objectTypeText) == 0))
{
node.objType = obj_collation;
}
else if (objectTypeText.length() >= 4 && std::string(TOKEN_FUNCTIONS).find(objectTypeText) == 0)
node.objType = obj_udf;
else if (objectTypeText.length() >= 5 && std::string(TOKEN_TABLES).find(objectTypeText) == 0)
node.objType = obj_relation;
else if (objectTypeText.length() >= 4 && std::string(TOKEN_ROLES).find(objectTypeText) == 0)
node.objType = obj_sql_role;
else if (objectTypeText.length() >= 4 && std::string(TOKEN_PROCEDURES).find(objectTypeText) == 0)
node.objType = obj_procedure;
else if (objectTypeText.length() >= 4 && std::string(TOKEN_PACKAGES).find(objectTypeText) == 0)
node.objType = obj_package_header;
else if (objectTypeText.length() >= 3 && std::string(TOKEN_PUBLICATIONS).find(objectTypeText) == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using std::string here? std::string_view has find() too.

Comment on lines +57 to +60
if (const auto tableName = parseName())
{
AddNode node;
node.tableName = std::move(tableName.value());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC std::move() on const object will return const T&& which needs to be handled with different approach and default move ctor or assignment operator will not kick in because they expect T&&. You have a lot of std::move with const object, so I guess it's better to test it, maybe I'm wrong.

if (parseEof())
return ShowUsersNode();
}
else if (text == TOKEN_VER || text == TOKEN_VERSION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a bit inconsistent, previousif()'s used different approach to calculate short version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command used to be different, only VER or VERSION was recognized.

{
node.objType = obj_collation;
}
else if (objectTypeText.length() >= 4 && std::string(TOKEN_FUNCTIONS).find(objectTypeText) == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move objectTypeText.length() >= 4 && std::string(TOKEN_FUNCTIONS).find(objectTypeText) == 0 to a separate function, this pattern occurs frequently?

if (first)
return std::nullopt;

return FrontendLexer::trim(std::string(startPos, lastPos));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm got a little bit confused when I saw std::string(startPos, lastPos), maybe add suffix It for iterators?

Comment on lines +214 to +218
FrontendParser(std::string_view statement, const Options& aOptions)
: lexer(statement),
options(aOptions)
{
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it should be private, no?

asfernandes added a commit that referenced this pull request Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants