Skip to content

Commit

Permalink
feat: add comment and update params' name
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoge committed Jul 4, 2024
1 parent ac0bdb2 commit 22a9454
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/parser/common/entityCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isToken, ParserRuleContext, Token } from 'antlr4ng';
import { SimpleStack } from './simpleStack';
import {
ctxToText,
isWordRange,
TextPosition,
TextSlice,
tokenToWord,
Expand Down Expand Up @@ -108,23 +109,25 @@ export interface FuncEntityContext extends BaseEntityContext {
export type EntityContext = CommonEntityContext | FuncEntityContext | ColumnEntityContext;

export function isCommonEntityContext(entity: EntityContext): entity is CommonEntityContext {
if (!entity) return false;
return 'relatedEntities' in entity && !('arguments' in entity);
}

export function isFuncEntityContext(entity: EntityContext): entity is FuncEntityContext {
if (!entity) return false;
return 'arguments' in entity;
}

export function isColumnEntityContext(entity: EntityContext): entity is ColumnEntityContext {
if (!entity) return false;
return AttrName.colType in entity;
}

export function isWordRange(textOrWord: TextSlice | WordRange): textOrWord is WordRange {
return 'line' in textOrWord;
}

/**
* what we need when collect attribute information
* */
interface AttrInfo {
attrList: AttrName[];
attrNameList: AttrName[];
endContext: string;
}

Expand Down Expand Up @@ -165,8 +168,8 @@ export function toEntityContext(
break;
}
if (attrInfo) {
for (let k = 0; k < attrInfo?.attrList?.length; k++) {
const attributeName: AttrName = attrInfo?.attrList[k];
for (let k = 0; k < attrInfo?.attrNameList?.length; k++) {
const attributeName: AttrName = attrInfo?.attrNameList[k];
const attrToken = findAttribute(ctx, attributeName, attrInfo?.endContext);
if (attrToken) {
const attrVal: WordRange | TextSlice | null = isToken(attrToken)
Expand Down
9 changes: 9 additions & 0 deletions src/parser/common/textAndWord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ export function ctxToText(
endColumn: ctx.stop.column + 1 + (ctx.stop.text?.length ?? 0),
};
}

/**
* judge whether the context is a WordRange
* @param textOrWord TextSlice or WordRange object
* */
export function isWordRange(textOrWord: TextSlice | WordRange): textOrWord is WordRange {
if (!textOrWord) return false;
return 'line' in textOrWord;
}
8 changes: 4 additions & 4 deletions src/parser/flink/flinkEntityCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class FlinkEntityCollector extends EntityCollector implements FlinkSqlPar

exitDatabasePathCreate(ctx: DatabasePathCreateContext) {
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE, {
attrList: [AttrName.comment],
attrNameList: [AttrName.comment],
endContext: CreateDatabaseContext.name,
});
}
Expand All @@ -50,7 +50,7 @@ export class FlinkEntityCollector extends EntityCollector implements FlinkSqlPar

exitTablePathCreate(ctx: TablePathCreateContext) {
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, {
attrList: [AttrName.comment],
attrNameList: [AttrName.comment],
endContext: CreateTableContext.name,
});
}
Expand All @@ -61,14 +61,14 @@ export class FlinkEntityCollector extends EntityCollector implements FlinkSqlPar

exitViewPathCreate(ctx: ViewPathCreateContext) {
this.pushEntity(ctx, EntityContextType.VIEW_CREATE, {
attrList: [AttrName.comment],
attrNameList: [AttrName.comment],
endContext: CreateViewContext.name,
});
}

exitColumnNameCreate(ctx: ColumnNameCreateContext) {
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, {
attrList: [AttrName.comment, AttrName.colType],
attrNameList: [AttrName.comment, AttrName.colType],
endContext: PhysicalColumnDefinitionContext.name,
});
}
Expand Down

0 comments on commit 22a9454

Please sign in to comment.