Skip to content

Commit

Permalink
refactor: prettify grammars (#128)
Browse files Browse the repository at this point in the history
* refactor: prettify clickhouse grammar

* refactor: prettify mysql grammar

* refactor: prettify postgresql grammar
  • Loading branch information
NikitaShkaruba authored Feb 15, 2024
1 parent 46429d0 commit 46d2824
Show file tree
Hide file tree
Showing 17 changed files with 54,578 additions and 62,193 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/autocomplete/clickhouse/clickHouseAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import {ClickHouseLexer} from './generated/ClickHouseLexer.js';
import {
ClickHouseParser,
TableExprAliasContext,
TableExpressionAliasContext,
TableIdentifierContext,
} from './generated/ClickHouseParser.js';
import {ClickHouseParserVisitor} from './generated/ClickHouseParserVisitor.js';
Expand Down Expand Up @@ -112,12 +112,12 @@ class ClickHouseSymbolTableVisitor
return this.visitChildren(context) as {};
};

visitTableExprAlias = (context: TableExprAliasContext): {} => {
visitTableExpressionAlias = (context: TableExpressionAliasContext): {} => {
try {
this.symbolTable.addNewSymbolOfType(
TableSymbol,
this.scope,
context.tableExpr()?.getText(),
context.tableExpression()?.getText(),
context.alias()?.getText() || context.identifier()?.getText() || undefined,
);
} catch (error) {
Expand Down Expand Up @@ -146,8 +146,8 @@ function generateSuggestionsFromRules(
case ClickHouseParser.RULE_tableIdentifier: {
if (
cursorTokenIndex === ruleData.startTokenIndex &&
!ruleData.ruleList.includes(ClickHouseParser.RULE_createStmt) &&
!ruleData.ruleList.includes(ClickHouseParser.RULE_columnsExpr)
!ruleData.ruleList.includes(ClickHouseParser.RULE_createStatement) &&
!ruleData.ruleList.includes(ClickHouseParser.RULE_columnsExpression)
) {
if (
hasPreviousToken(
Expand All @@ -174,7 +174,7 @@ function generateSuggestionsFromRules(
break;
}
case ClickHouseParser.RULE_identifier: {
if (ruleData.ruleList.includes(ClickHouseParser.RULE_columnExpr)) {
if (ruleData.ruleList.includes(ClickHouseParser.RULE_columnExpression)) {
suggestFunctions = true;
// TODO Not sure yet how to specifically find aggregate functions
suggestAggregateFunctions = true;
Expand Down Expand Up @@ -217,10 +217,10 @@ function getParseTree(parser: ClickHouseParser, type?: TableQueryPosition['type'
case 'from':
return parser.fromClause();
case 'alter':
return parser.alterStmt();
return parser.alterStatement();
case 'insert':
// INSERT doesn't work for now: for some reason any INSERT statement throws error
return parser.insertStmt();
return parser.insertStatement();
}
}

Expand Down
122 changes: 61 additions & 61 deletions src/autocomplete/clickhouse/generated/ClickHouseParser.interp
Original file line number Diff line number Diff line change
Expand Up @@ -479,30 +479,30 @@ root
statements
statement
notInsertStatement
ctes
commonTableExpressionStatement
namedQuery
columnAliases
alterStmt
alterStatement
alterTableClause
assignmentExprList
assignmentExpr
assignmentExpressionList
assignmentExpression
tableColumnPropertyType
partitionClause
attachStmt
checkStmt
attachStatement
checkStatement
deleteStatement
createTableStatement
createDatabaseStatement
createDictionaryStatement
createLiveViewStatement
createMaterializedViewStatement
createViewStatement
createStmt
createStatement
dictionarySchemaClause
dictionaryAttrDfnt
dictionaryAttributeDefinition
dictionaryEngineClause
dictionaryPrimaryKeyClause
dictionaryArgExpr
dictionaryArgumentExpression
sourceClause
lifetimeClause
layoutClause
Expand All @@ -518,30 +518,30 @@ partitionByClause
primaryKeyClause
sampleByClause
ttlClause
engineExpr
tableElementExpr
tableColumnDfnt
tableColumnPropertyExpr
tableIndexDfnt
tableProjectionDfnt
codecExpr
codecArgExpr
ttlExpr
describeStmt
dropStmt
existsStmt
explainStmt
insertStmt
engineExpression
tableElementExpression
tableColumnDefinition
tableColumnPropertyExpression
tableIndexDefinition
tableProjectionDefinition
codecExpression
codecArgExpression
ttlExpression
describeStatement
dropStatement
existsStatement
explainStatement
insertStatement
columnsClause
dataClause
valuesStatement
killStmt
optimizeStmt
renameStmt
projectionSelectStmt
selectUnionStmt
selectStmtWithParens
selectStmt
killStatement
optimizeStatement
renameStatement
projectionSelectStatement
selectUnionStatement
selectStatementWithParentheses
selectStatement
withClause
topClause
fromClause
Expand All @@ -556,42 +556,42 @@ projectionOrderByClause
limitByClause
limitClause
settingsClause
joinExpr
joinOp
joinOpCross
joinExpression
joinOperator
joinOperatorCross
joinConstraintClause
sampleClause
limitExpr
orderExprList
orderExpr
ratioExpr
settingExprList
settingExpr
windowExpr
winPartitionByClause
winOrderByClause
winFrameClause
winFrameExtend
winFrameBound
setStmt
showStmt
systemStmt
truncateStmt
useStmt
watchStmt
columnTypeExpr
columnExprList
columnsExpr
columnExpr
columnArgList
columnArgExpr
columnLambdaExpr
limitExpression
orderExpressionList
orderExpression
ratioExpression
settingExpressionList
settingExpression
windowExpression
windowPartitionByClause
windowOrderByClause
windowFrameClause
windowFrameExtend
windowFrameBound
setStatement
showStatement
systemStatement
truncateStatement
useStatement
watchStatement
columnTypeExpression
columnExpressionList
columnsExpression
columnExpression
columnArgumentList
columnArgumentExpression
columnLambdaExpression
columnIdentifier
tableExpr
tableFunctionExpr
tableExpression
tableFunctionExpression
tableIdentifier
tableArgList
tableArgExpr
tableArgExpression
databaseIdentifier
floatingLiteral
numberLiteral
Expand Down
Loading

0 comments on commit 46d2824

Please sign in to comment.