oracle-plsql-parser
Advanced tools
Comparing version
@@ -10,2 +10,5 @@ import { GlobalObjects, PackageDef, VariableDef } from './types'; | ||
objectDeclaration(ctx: any): any; | ||
funcSpec(ctx: any): any; | ||
procSpec(ctx: any): any; | ||
packageObjSpec(ctx: any): any; | ||
argumentList(ctx: any): any[]; | ||
@@ -12,0 +15,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const noRecoveryParser_1 = require("../mainParser/noRecoveryParser"); | ||
const recusiveGetToken_1 = require("./recusiveGetToken"); | ||
const recusiveGetTokenString_1 = require("./recusiveGetTokenString"); | ||
const types_1 = require("./types"); | ||
@@ -34,3 +34,3 @@ const BaseCstVisitor = noRecoveryParser_1.parserInstance.getBaseCstVisitorConstructorWithDefaults(); | ||
pkg.position = getPosition(ps.location); | ||
pkg.name = (0, recusiveGetToken_1.recusiveGetTokenString)(ps.children.package_name); | ||
pkg.name = (0, recusiveGetTokenString_1.default)(ps.children.package_name); | ||
pkg.content = {}; | ||
@@ -48,4 +48,5 @@ if (ps.children.variableDeclaration) { | ||
pkg.position = getPosition(pb.location); | ||
pkg.name = (0, recusiveGetToken_1.recusiveGetTokenString)(pb.children.package_name); | ||
pkg.name = (0, recusiveGetTokenString_1.default)(pb.children.package_name); | ||
pkg.content = {}; | ||
pkg.content.objects = []; | ||
if (pb.children.variableDeclaration) { | ||
@@ -57,2 +58,5 @@ pkg.content.variables = pb.children.variableDeclaration.map((p) => this.visit(p)); | ||
} | ||
if (pb.children.packageObjSpec) { | ||
pb.children.packageObjSpec.forEach((p) => pkg.content.objects?.push(this.visit(p))); | ||
} | ||
} | ||
@@ -68,6 +72,6 @@ return pkg; | ||
v.position = getPosition(sv.location); | ||
v.name = (0, recusiveGetToken_1.recusiveGetTokenString)(sv.children.variable_name); | ||
v.name = (0, recusiveGetTokenString_1.default)(sv.children.variable_name); | ||
v.constant = !!sv.children.ConstantKw; | ||
if (sv.children.variableSpec) { | ||
v.type = (0, recusiveGetToken_1.recusiveGetTokenString)(sv.children.variableSpec); | ||
v.type = (0, recusiveGetTokenString_1.default)(sv.children.variableSpec); | ||
} | ||
@@ -82,45 +86,67 @@ if (sv.children.value) { | ||
value(ctx) { | ||
const values = (0, recusiveGetToken_1.recusiveGetToken)(ctx); | ||
return values.join(' '); | ||
return (0, recusiveGetTokenString_1.default)(ctx); | ||
} | ||
objectDeclaration(ctx) { | ||
// TODO: type | ||
const obj = {}; | ||
if (ctx.funcSpec && ctx.funcSpec[0]) { | ||
const fs = ctx.funcSpec[0]; | ||
obj.type = types_1.ObjectType.fc; | ||
obj.context = types_1.ObjectContext.spec; | ||
obj.position = getPosition(fs.location); | ||
if (fs?.children?.function_name) { | ||
obj.name = (0, recusiveGetToken_1.recusiveGetTokenString)(fs.children.function_name); | ||
} | ||
if (fs?.children?.argumentList) { | ||
obj.arguments = this.visit(fs.children.argumentList); | ||
} | ||
if (fs?.children?.dataType) { | ||
obj.return = (0, recusiveGetToken_1.recusiveGetTokenString)(fs.children.dataType); | ||
} | ||
else if (fs?.children?.objType) { | ||
obj.return = (0, recusiveGetToken_1.recusiveGetTokenString)(fs.children.objType); | ||
} | ||
obj.deterministic = !!fs?.children?.DeterministicKw; | ||
obj.resultCache = !!fs?.children?.ResultCacheKw; | ||
obj.pipelined = !!fs?.children?.PipelinedKw; | ||
return obj; | ||
const fc = this.visit(ctx.funcSpec[0]); | ||
fc.position = getPosition(ctx.funcSpec[0].location); | ||
return fc; | ||
} | ||
if (ctx.procSpec && ctx.procSpec[0]) { | ||
const ps = ctx.procSpec[0]; | ||
obj.type = types_1.ObjectType.prc; | ||
obj.context = types_1.ObjectContext.spec; | ||
obj.position = getPosition(ps.location); | ||
if (ps?.children?.procedure_name) { | ||
obj.name = (0, recusiveGetToken_1.recusiveGetTokenString)(ps.children.procedure_name); | ||
} | ||
if (ps?.children?.argumentList) { | ||
obj.arguments = this.visit(ps.children.argumentList); | ||
} | ||
return obj; | ||
//debugger; | ||
const prc = this.visit(ctx.procSpec[0]); | ||
prc.position = getPosition(ctx.procSpec[0].location); | ||
return prc; | ||
} | ||
} | ||
funcSpec(ctx) { | ||
const obj = {}; | ||
obj.type = types_1.ObjectType.fc; | ||
obj.context = types_1.ObjectContext.spec; | ||
//obj.position = getPosition(ctx.location); | ||
if (ctx?.function_name) { | ||
obj.name = (0, recusiveGetTokenString_1.default)(ctx.function_name); | ||
} | ||
if (ctx?.argumentList) { | ||
obj.arguments = this.visit(ctx.argumentList); | ||
} | ||
if (ctx?.dataType) { | ||
obj.return = (0, recusiveGetTokenString_1.default)(ctx.dataType); | ||
} | ||
else if (ctx?.objType) { | ||
obj.return = (0, recusiveGetTokenString_1.default)(ctx.objType); | ||
} | ||
obj.deterministic = !!ctx?.DeterministicKw; | ||
obj.resultCache = !!ctx?.ResultCacheKw; | ||
obj.pipelined = !!ctx?.PipelinedKw; | ||
return obj; | ||
} | ||
procSpec(ctx) { | ||
const obj = {}; | ||
obj.type = types_1.ObjectType.prc; | ||
obj.context = types_1.ObjectContext.spec; | ||
// obj.position = getPosition(ctx.location); | ||
if (ctx?.procedure_name) { | ||
obj.name = (0, recusiveGetTokenString_1.default)(ctx.procedure_name); | ||
} | ||
if (ctx?.argumentList) { | ||
obj.arguments = this.visit(ctx.argumentList); | ||
} | ||
return obj; | ||
} | ||
packageObjSpec(ctx) { | ||
if (ctx.funcBody && ctx.funcBody[0] && ctx.funcBody[0].children.funcSpec) { | ||
const fc = this.visit(ctx.funcBody[0].children.funcSpec); | ||
fc.context = types_1.ObjectContext.body; | ||
fc.position = getPosition(ctx.funcBody[0].location); | ||
return fc; | ||
} | ||
else if (ctx.procBody && | ||
ctx.procBody[0] && | ||
ctx.procBody[0].children.procSpec) { | ||
const prc = this.visit(ctx.procBody[0].children.procSpec); | ||
prc.context = types_1.ObjectContext.body; | ||
prc.position = getPosition(ctx.procBody[0].location); | ||
return prc; | ||
} | ||
} | ||
argumentList(ctx) { | ||
@@ -130,4 +156,9 @@ const args = []; | ||
const a = {}; | ||
a.name = (0, recusiveGetToken_1.recusiveGetTokenString)(arg.children.Identifier); | ||
a.dataType = (0, recusiveGetToken_1.recusiveGetTokenString)(arg.children.dataType); | ||
a.name = (0, recusiveGetTokenString_1.default)(arg.children.Identifier); | ||
if (arg.children.dataType) { | ||
a.dataType = (0, recusiveGetTokenString_1.default)(arg.children.dataType); | ||
} | ||
else if (arg.children.objType) { | ||
a.dataType = (0, recusiveGetTokenString_1.default)(arg.children.objType); | ||
} | ||
if (!arg.children.inOut) { | ||
@@ -134,0 +165,0 @@ a.direction = types_1.ArgumentDirection.in; |
@@ -1,2 +0,7 @@ | ||
export declare function recusiveGetToken(ctx: any | any[]): string[]; | ||
declare type IdentifierArray = { | ||
value: string; | ||
startPos: number; | ||
}; | ||
export declare function recusiveGetToken(ctx: any | any[]): IdentifierArray[]; | ||
export declare function recusiveGetTokenString(ctx: any | any[]): string; | ||
export {}; |
@@ -18,3 +18,6 @@ "use strict"; | ||
if (c.image) { | ||
values.push(c.image); | ||
values.push({ | ||
value: c.image, | ||
startPos: c.startOffset ?? c.location.startOffset, | ||
}); | ||
} | ||
@@ -30,3 +33,6 @@ else if (c.children) { | ||
if (v.image) { | ||
values.push(v.image); | ||
values.push({ | ||
value: v.image, | ||
startPos: v.startOffset ?? v.location.startOffset, | ||
}); | ||
} | ||
@@ -52,5 +58,6 @@ else if (v.children) { | ||
const values = recusiveGetToken(ctx); | ||
return values.join(' '); | ||
const sorted = values.sort((a, b) => a.startPos - b.startPos); | ||
return sorted.map((v) => v.value).join(''); | ||
} | ||
exports.recusiveGetTokenString = recusiveGetTokenString; | ||
//# sourceMappingURL=recusiveGetToken.js.map |
@@ -652,3 +652,3 @@ "use strict"; | ||
{ | ||
ALT: () => $.CONSUME(tokens_1.tokenVocabulary.String, { LABEL: 'String' }), // xpath | ||
ALT: () => $.CONSUME(tokens_1.tokenVocabulary.StringTk, { LABEL: 'String' }), // xpath | ||
}, | ||
@@ -664,3 +664,3 @@ ]); | ||
{ | ||
ALT: () => $.CONSUME1(tokens_1.tokenVocabulary.String, { LABEL: 'String' }), // namespace | ||
ALT: () => $.CONSUME1(tokens_1.tokenVocabulary.StringTk, { LABEL: 'String' }), // namespace | ||
}, | ||
@@ -685,3 +685,3 @@ ]); | ||
{ | ||
ALT: () => $.CONSUME(tokens_1.tokenVocabulary.String, { LABEL: 'String' }), // xpath | ||
ALT: () => $.CONSUME(tokens_1.tokenVocabulary.StringTk, { LABEL: 'String' }), // xpath | ||
}, | ||
@@ -697,3 +697,3 @@ ]); | ||
{ | ||
ALT: () => $.CONSUME1(tokens_1.tokenVocabulary.String, { LABEL: 'String' }), // namespace | ||
ALT: () => $.CONSUME1(tokens_1.tokenVocabulary.StringTk, { LABEL: 'String' }), // namespace | ||
}, | ||
@@ -716,4 +716,10 @@ ]); | ||
{ | ||
ALT: () => $.CONSUME(tokens_1.tokenVocabulary.String, { LABEL: 'String' }), | ||
ALT: () => $.CONSUME(tokens_1.tokenVocabulary.StringTk, { LABEL: 'String' }), | ||
}, | ||
// { | ||
// ALT: () => | ||
// $.CONSUME(tokenVocabulary.AlternateQuotingMechanism, { | ||
// LABEL: 'String', | ||
// }), | ||
// }, | ||
{ ALT: () => $.SUBRULE($.number, { LABEL: 'Number' }) }, | ||
@@ -752,3 +758,3 @@ // { | ||
// $.OR([ | ||
// { ALT: () => $.CONSUME(tokenVocabulary.String) }, | ||
// { ALT: () => $.CONSUME(tokenVocabulary.StringTk) }, | ||
// { ALT: () => $.SUBRULE($.number) }, | ||
@@ -774,3 +780,3 @@ // { | ||
{ ALT: () => $.CONSUME(tokens_1.tokenVocabulary.ValueSeperator) }, | ||
{ ALT: () => $.CONSUME(tokens_1.tokenVocabulary.String) }, | ||
{ ALT: () => $.CONSUME(tokens_1.tokenVocabulary.StringTk) }, | ||
{ ALT: () => $.SUBRULE($.number) }, | ||
@@ -897,3 +903,3 @@ // { | ||
$.OR([ | ||
{ ALT: () => $.CONSUME(tokens_1.tokenVocabulary.String) }, | ||
{ ALT: () => $.CONSUME(tokens_1.tokenVocabulary.StringTk) }, | ||
{ ALT: () => $.CONSUME(tokens_1.tokenVocabulary.CompilationFlag) }, | ||
@@ -900,0 +906,0 @@ { ALT: () => $.SUBRULE($.functionCall) }, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chevrotain_1 = require("chevrotain"); | ||
const strings_1 = require("./strings"); | ||
// does not work because identifier will always be this token | ||
@@ -13,6 +14,6 @@ // const AnyValue = createToken({ | ||
name: 'Identifier', | ||
pattern: /[a-zA-Z][a-zA-Z0-9_$]*/, // first must be a letter than also numbers, "_" and "$" | ||
// longer_alt: AnyValue, | ||
pattern: /[a-zA-Z][a-zA-Z0-9_$]*/, | ||
longer_alt: strings_1.default.find((t) => t.name === 'AlternateQuotingMechanism'), | ||
}); | ||
exports.default = Identifier; | ||
//# sourceMappingURL=Identifier.js.map |
@@ -18,2 +18,3 @@ "use strict"; | ||
const values_1 = require("./values"); | ||
const strings_1 = require("./strings"); | ||
/* ===== Keywords ===== */ | ||
@@ -89,3 +90,2 @@ const Declare = (0, chevrotain_1.createToken)({ | ||
}); | ||
const String = (0, chevrotain_1.createToken)({ name: 'String', pattern: /'((?:''|[^'])*)'/ }); | ||
const Quote = (0, chevrotain_1.createToken)({ | ||
@@ -133,3 +133,3 @@ name: 'Quote', | ||
Integer, | ||
String, | ||
...strings_1.default, | ||
]; | ||
@@ -136,0 +136,0 @@ const SelectLexer = new chevrotain_1.Lexer(allTokens, { positionTracking: 'full' }); |
@@ -84,2 +84,7 @@ "use strict"; | ||
}); | ||
const Pipe = (0, chevrotain_1.createToken)({ | ||
name: 'Pipe', | ||
pattern: /\|/, | ||
longer_alt: Concat, | ||
}); | ||
const Percent = (0, chevrotain_1.createToken)({ | ||
@@ -117,2 +122,3 @@ name: 'Percent', | ||
Concat, | ||
Pipe, | ||
Percent, | ||
@@ -119,0 +125,0 @@ Dollar, |
@@ -142,3 +142,38 @@ "use strict"; | ||
}); | ||
test('alternate quoting string 1', () => { | ||
const code = ` | ||
declare | ||
l_str varchar2(255 char); | ||
begin | ||
l_str := q'[ what is ' up ' here ' ?']'; | ||
end; | ||
`; | ||
const result = (0, recoveryParser_1.default)(code, false); | ||
expect(result.errors).toStrictEqual([]); | ||
}); | ||
test('alternate quoting string 2', () => { | ||
const code = ` | ||
declare | ||
l_str varchar2(255 char); | ||
begin | ||
l_str := q'! what is ' up ' here ' ?'!'; | ||
end; | ||
`; | ||
const result = (0, recoveryParser_1.default)(code, false); | ||
expect(result.errors).toStrictEqual([]); | ||
}); | ||
test('alternate quoting string multiline', () => { | ||
const code = ` | ||
declare | ||
l_str varchar2(255 char); | ||
begin | ||
l_str := q'( | ||
what is ' | ||
up ' here ' ?')'; | ||
end; | ||
`; | ||
const result = (0, recoveryParser_1.default)(code, false); | ||
expect(result.errors).toStrictEqual([]); | ||
}); | ||
}); | ||
//# sourceMappingURL=values.test.js.map |
{ | ||
"name": "oracle-plsql-parser", | ||
"description": "Parser for Oracle PL/SQL", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"repository": "https://github.com/phartenfeller/plsql-parser.git", | ||
@@ -6,0 +6,0 @@ "website": "https://github.com/phartenfeller/plsql-parser", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
315913
4.27%129
4.88%4916
4.6%