| 1 | hash typeMap |
|---|
| 2 | "VARCHAR" -> "VARCHAR", |
|---|
| 3 | "VARCHAR2" -> "VARCHAR2", |
|---|
| 4 | "Varchar2" -> "VARCHAR2", |
|---|
| 5 | "varchar2" -> "VARCHAR2", |
|---|
| 6 | "char" -> "CHAR", |
|---|
| 7 | "CHAR" -> "CHAR", |
|---|
| 8 | "NUMBER" -> "NUMBER", |
|---|
| 9 | "number" -> "NUMBER", |
|---|
| 10 | "Number" -> "NUMBER", |
|---|
| 11 | "date" -> "DATE", |
|---|
| 12 | default -> "VARCHAR2" |
|---|
| 13 | end_hash |
|---|
| 14 | |
|---|
| 15 | rule 'createPLSQLDefinition' |
|---|
| 16 | from package_spec ps |
|---|
| 17 | to PLSQLDefinition |
|---|
| 18 | queries |
|---|
| 19 | seqt : //#seq_of_statements; |
|---|
| 20 | mappings |
|---|
| 21 | triggers = execute createTriggerBlock seqt; |
|---|
| 22 | end_rule |
|---|
| 23 | |
|---|
| 24 | rule 'createTriggerBlock' |
|---|
| 25 | from seq_of_statements seqt |
|---|
| 26 | context createPLSQLDefinition |
|---|
| 27 | to TriggerBlock |
|---|
| 28 | queries |
|---|
| 29 | father: //#Trigger/seq_of_statements{this.check(seqt)}; |
|---|
| 30 | block : /seqt/statement/#plsql_block; |
|---|
| 31 | decls : /block/#declare_spec; |
|---|
| 32 | stats1: /block/seq_of_statements/#statement; |
|---|
| 33 | stats2: /seqt/#statement; |
|---|
| 34 | mappings |
|---|
| 35 | if(father.hasResults) then |
|---|
| 36 | name = father.father_name + "::" + father.trigger_name; |
|---|
| 37 | end_if |
|---|
| 38 | statements = stats2; |
|---|
| 39 | end_rule |
|---|
| 40 | |
|---|
| 41 | rule 'createPackageFromSpec' |
|---|
| 42 | from package_spec ps |
|---|
| 43 | to Package |
|---|
| 44 | queries |
|---|
| 45 | n : /ps/package_name[0]/#identifier; |
|---|
| 46 | specs : /ps/#package_obj_spec; |
|---|
| 47 | mappings |
|---|
| 48 | name = n.ID; |
|---|
| 49 | declarations = specs; |
|---|
| 50 | end_rule |
|---|
| 51 | |
|---|
| 52 | rule 'createPackageFromBody' |
|---|
| 53 | from package_body pb |
|---|
| 54 | to Package |
|---|
| 55 | queries |
|---|
| 56 | n : /pb/package_name[0]/#identifier; |
|---|
| 57 | decls : /pb/#package_obj_body; |
|---|
| 58 | mappings |
|---|
| 59 | name = n.ID; |
|---|
| 60 | declarations = decls; |
|---|
| 61 | end_rule |
|---|
| 62 | |
|---|
| 63 | ------------------------------------------------------------------------ |
|---|
| 64 | -- Normal Declarations |
|---|
| 65 | ------------------------------------------------------------------------ |
|---|
| 66 | |
|---|
| 67 | rule 'createVariableDeclaration' |
|---|
| 68 | from declare_spec[unique]/variable_declaration ds |
|---|
| 69 | to VariableDeclaration |
|---|
| 70 | queries |
|---|
| 71 | varDec : /ds/#variable_declaration; |
|---|
| 72 | n : /varDec/variable_name/#identifier; |
|---|
| 73 | t1 : /varDec/type_spec/#datatype; |
|---|
| 74 | t2 : /varDec/type_spec/type_name/#identifier; |
|---|
| 75 | r2 : /varDec/#type_spec/type_name; |
|---|
| 76 | exp : /varDec/plsql_expression/#expr_bool; |
|---|
| 77 | mappings |
|---|
| 78 | if(t1.hasResults) then |
|---|
| 79 | type = new Datatype; |
|---|
| 80 | type.name = map typeMap(t1.TOKEN); |
|---|
| 81 | type.range = t1.NUMBER; |
|---|
| 82 | else |
|---|
| 83 | if(t2.hasResults) then |
|---|
| 84 | type = new IndirectType; |
|---|
| 85 | type.identifier = t2.ID; |
|---|
| 86 | if(r2.hasResults) then |
|---|
| 87 | type.range = r2.NUMBER; |
|---|
| 88 | end_if |
|---|
| 89 | end_if |
|---|
| 90 | end_if |
|---|
| 91 | name = n.ID; |
|---|
| 92 | assign = exp; |
|---|
| 93 | end_rule |
|---|
| 94 | |
|---|
| 95 | rule 'createCursorDeclaration' |
|---|
| 96 | from declare_spec[unique]/cursor_declaration ds |
|---|
| 97 | to CursorDeclaration |
|---|
| 98 | queries |
|---|
| 99 | curDec : /ds/#cursor_declaration; |
|---|
| 100 | n : /curDec/cursor_name/#identifier; |
|---|
| 101 | args : /curDec//#parameter_spec; |
|---|
| 102 | s : /curDec//#select_statement; |
|---|
| 103 | mappings |
|---|
| 104 | name = n.ID; |
|---|
| 105 | select = s; |
|---|
| 106 | arguments = args; |
|---|
| 107 | end_rule |
|---|
| 108 | ------------------------------------------------------------------------ |
|---|
| 109 | -- Statements |
|---|
| 110 | ------------------------------------------------------------------------ |
|---|
| 111 | |
|---|
| 112 | rule 'createBlockStatement' |
|---|
| 113 | from statement/plsql_block st |
|---|
| 114 | to BlockStatement |
|---|
| 115 | queries |
|---|
| 116 | block : /st/#plsql_block; |
|---|
| 117 | decls : /block/#declare_spec; |
|---|
| 118 | stats : /block/seq_of_statements/#statement; |
|---|
| 119 | mappings |
|---|
| 120 | declarations = decls; |
|---|
| 121 | statements = stats; |
|---|
| 122 | end_rule |
|---|
| 123 | |
|---|
| 124 | rule 'createIfStatement' |
|---|
| 125 | from statement/if_statement st |
|---|
| 126 | to IfStatement |
|---|
| 127 | queries |
|---|
| 128 | is : /st/#if_statement; |
|---|
| 129 | ifexp : /is/plsql_condition/#expr_bool; |
|---|
| 130 | ifstat : /is/seq_of_statements[0]/#statement; |
|---|
| 131 | elstat : /is/seq_of_statements[1]/#statement; |
|---|
| 132 | mappings |
|---|
| 133 | condition = ifexp; |
|---|
| 134 | ifStatements = ifstat; |
|---|
| 135 | elseStatements = elstat; |
|---|
| 136 | end_rule |
|---|
| 137 | |
|---|
| 138 | rule 'createReturnStatement' |
|---|
| 139 | from statement/return_statement st |
|---|
| 140 | to ReturnStatement |
|---|
| 141 | queries |
|---|
| 142 | mappings |
|---|
| 143 | end_rule |
|---|
| 144 | |
|---|
| 145 | rule 'createAssignment' |
|---|
| 146 | from statement/assignment_statement st |
|---|
| 147 | to AssignmentStatement |
|---|
| 148 | queries |
|---|
| 149 | as : /st/#assignment_statement; |
|---|
| 150 | value : /as/#lvalue; |
|---|
| 151 | exp : /as/plsql_expression/#expr_bool; |
|---|
| 152 | mappings |
|---|
| 153 | receptor = value; |
|---|
| 154 | expression = exp; |
|---|
| 155 | end_rule |
|---|
| 156 | |
|---|
| 157 | skip_rule 'skiptoSelectStatement' |
|---|
| 158 | from statement/sql_statement//select_statement sqlc |
|---|
| 159 | to SelectStatement |
|---|
| 160 | queries |
|---|
| 161 | s : /sqlc//#select_statement; |
|---|
| 162 | do |
|---|
| 163 | skip s; |
|---|
| 164 | end_rule |
|---|
| 165 | |
|---|
| 166 | rule 'createOpenStatement' |
|---|
| 167 | from statement/sql_statement//open_statement sqlc |
|---|
| 168 | to OpenStatement |
|---|
| 169 | queries |
|---|
| 170 | openSt : /sqlc//#open_statement; |
|---|
| 171 | cname : /openSt//cursor_name/#identifier; |
|---|
| 172 | cloc : //#declare_spec/cursor_declaration/cursor_name/identifier{ID.eq(cname.ID)}; |
|---|
| 173 | ebools : /openSt/plsql_expressions//#expr_bool; |
|---|
| 174 | mappings |
|---|
| 175 | cursor = cloc; |
|---|
| 176 | exprs = ebools; |
|---|
| 177 | end_rule |
|---|
| 178 | |
|---|
| 179 | rule 'createCloseStatement' |
|---|
| 180 | from statement/sql_statement//close_statement sqlc |
|---|
| 181 | to CloseStatement |
|---|
| 182 | queries |
|---|
| 183 | closeSt : /sqlc//#close_statement; |
|---|
| 184 | cname : /closeSt//cursor_name/#identifier; |
|---|
| 185 | cloc : //#declare_spec/cursor_declaration/cursor_name/identifier{ID.eq(cname.ID)}; |
|---|
| 186 | mappings |
|---|
| 187 | cursor = cloc; |
|---|
| 188 | end_rule |
|---|
| 189 | |
|---|
| 190 | rule 'createFetchStatement' |
|---|
| 191 | from statement/sql_statement//fetch_statement sqlc |
|---|
| 192 | to FetchStatement |
|---|
| 193 | queries |
|---|
| 194 | fetchSt : /sqlc//#fetch_statement; |
|---|
| 195 | cname : /fetchSt//cursor_name/#identifier; |
|---|
| 196 | cloc : //#declare_spec/cursor_declaration/cursor_name/identifier{ID.eq(cname.ID)}; |
|---|
| 197 | vs : /fetchSt/variable_names/#variable_name; |
|---|
| 198 | mappings |
|---|
| 199 | cursor = cloc; |
|---|
| 200 | into = vs; |
|---|
| 201 | end_rule |
|---|
| 202 | |
|---|
| 203 | rule 'createRaiseStatement' |
|---|
| 204 | from statement/raise_statement sqlc |
|---|
| 205 | to RaiseStatement |
|---|
| 206 | queries |
|---|
| 207 | raiseSt : /sqlc//#raise_statement; |
|---|
| 208 | ename : /raiseSt/#exception_name; |
|---|
| 209 | mappings |
|---|
| 210 | exception = extractID ename; |
|---|
| 211 | end_rule |
|---|
| 212 | |
|---|
| 213 | skip_rule 'createFunctionCallStatement' |
|---|
| 214 | from statement/function_call st |
|---|
| 215 | to FunctionCallStatement |
|---|
| 216 | queries |
|---|
| 217 | s : /st/#function_call; |
|---|
| 218 | do |
|---|
| 219 | skip s; |
|---|
| 220 | end_rule |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | ------------------------------------------------------------------------ |
|---|
| 224 | -- Working with variable references |
|---|
| 225 | ------------------------------------------------------------------------ |
|---|
| 226 | |
|---|
| 227 | rule 'createReceptorFromVariable' |
|---|
| 228 | from variable_name v |
|---|
| 229 | to SQLVariable |
|---|
| 230 | queries |
|---|
| 231 | block : //#plsql_block//variable_name{this.check(v)}; |
|---|
| 232 | iden : /v/#identifier; |
|---|
| 233 | dec : /block//#declare_spec/variable_declaration/variable_name/identifier{ID.eq(iden.ID)}; |
|---|
| 234 | mappings |
|---|
| 235 | reference = dec; |
|---|
| 236 | end_rule |
|---|
| 237 | |
|---|
| 238 | rule 'createSQLVariableFromLValue' |
|---|
| 239 | from lvalue/variable_name l |
|---|
| 240 | context createAssignment, createSelectStatement |
|---|
| 241 | to SQLVariable |
|---|
| 242 | queries |
|---|
| 243 | v : /l/#variable_name; |
|---|
| 244 | block : //#plsql_block//variable_name{this.check(v)}; |
|---|
| 245 | iden : /v/#identifier; |
|---|
| 246 | dec : /block//#declare_spec/variable_declaration/variable_name/identifier{ID.eq(iden.ID)}; |
|---|
| 247 | mappings |
|---|
| 248 | reference = dec; |
|---|
| 249 | end_rule |
|---|
| 250 | |
|---|
| 251 | rule 'createFormsVariableFromLValue' |
|---|
| 252 | from lvalue{COLON[0].exists} v |
|---|
| 253 | context createAssignment, createSelectStatement |
|---|
| 254 | to FormsVarRef |
|---|
| 255 | queries |
|---|
| 256 | ref : /v{COLON[0].exists}/#host_variable; |
|---|
| 257 | mappings |
|---|
| 258 | reference = extractID ref; |
|---|
| 259 | end_rule |
|---|
| 260 | |
|---|
| 261 | rule 'createFormsVariableFromLValue' |
|---|
| 262 | from lvalue/record_name v |
|---|
| 263 | context createAssignment, createSelectStatement |
|---|
| 264 | to SQLVariable |
|---|
| 265 | queries |
|---|
| 266 | v : /l/#variable_name; |
|---|
| 267 | mappings |
|---|
| 268 | end_rule |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | ------------------------------------------------------------------------ |
|---|
| 272 | -- Specifications |
|---|
| 273 | ------------------------------------------------------------------------ |
|---|
| 274 | |
|---|
| 275 | rule 'createVariableSpecification' |
|---|
| 276 | from package_obj_spec/variable_declaration pos |
|---|
| 277 | to VariableDeclaration |
|---|
| 278 | queries |
|---|
| 279 | vd : /pos/#variable_declaration; |
|---|
| 280 | n : /vd/variable_name/#identifier; |
|---|
| 281 | mappings |
|---|
| 282 | type = new Datatype; |
|---|
| 283 | type.name = "VARCHAR2"; |
|---|
| 284 | name = n.ID; |
|---|
| 285 | end_rule |
|---|
| 286 | |
|---|
| 287 | rule 'createFunctionSpecification' |
|---|
| 288 | from package_obj_spec/function_spec pos |
|---|
| 289 | to FunctionDeclaration |
|---|
| 290 | queries |
|---|
| 291 | fs : /pos/#function_spec; |
|---|
| 292 | n : /fs/function_name/#identifier; |
|---|
| 293 | mappings |
|---|
| 294 | type = new Datatype; |
|---|
| 295 | type.name = "VARCHAR2"; |
|---|
| 296 | name = n.ID; |
|---|
| 297 | end_rule |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | ------------------------------------------------------------------------ |
|---|
| 301 | -- Expressions (FROM expr_bool) |
|---|
| 302 | ------------------------------------------------------------------------ |
|---|
| 303 | |
|---|
| 304 | skip_rule 'skipAllBooleanRules' |
|---|
| 305 | from expr_bool{!TOKEN.exists}/expr_or{!TOKEN.exists}/expr_and{!TOKEN.exists} exp |
|---|
| 306 | to Expression |
|---|
| 307 | queries |
|---|
| 308 | s : /exp/expr_or/expr_and/#expr_not; |
|---|
| 309 | do |
|---|
| 310 | skip s; |
|---|
| 311 | end_rule |
|---|
| 312 | |
|---|
| 313 | skip_rule 'bridgeBooleanFromExprBool' |
|---|
| 314 | from expr_bool{!TOKEN.exists} exp |
|---|
| 315 | to Expression |
|---|
| 316 | queries |
|---|
| 317 | s : /exp/#expr_or; |
|---|
| 318 | do |
|---|
| 319 | skip s; |
|---|
| 320 | end_rule |
|---|
| 321 | |
|---|
| 322 | rule 'createBooleanFromExprBool' |
|---|
| 323 | from expr_bool{TOKEN.exists} exp |
|---|
| 324 | to BooleanExpression |
|---|
| 325 | queries |
|---|
| 326 | expo1 : /exp/#expr_or[0]; |
|---|
| 327 | expo2 : /exp/#expr_or[1]; |
|---|
| 328 | mappings |
|---|
| 329 | expr1 = expo1; |
|---|
| 330 | type = "OR"; |
|---|
| 331 | expr2 = expo2; |
|---|
| 332 | end_rule |
|---|
| 333 | |
|---|
| 334 | skip_rule 'bridgeBooleanFromExprOr' |
|---|
| 335 | from expr_or{!TOKEN.exists} exp |
|---|
| 336 | to Expression |
|---|
| 337 | queries |
|---|
| 338 | s : /exp/#expr_and; |
|---|
| 339 | do |
|---|
| 340 | skip s; |
|---|
| 341 | end_rule |
|---|
| 342 | |
|---|
| 343 | rule 'createBooleanFromExprOr' |
|---|
| 344 | from expr_or{TOKEN.exists} exp |
|---|
| 345 | to BooleanExpression |
|---|
| 346 | queries |
|---|
| 347 | expa1 : /exp/#expr_and[0]; |
|---|
| 348 | expa2 : /exp/#expr_and[1]; |
|---|
| 349 | mappings |
|---|
| 350 | expr1 = expa1; |
|---|
| 351 | type = "AND"; |
|---|
| 352 | expr2 = expa2; |
|---|
| 353 | end_rule |
|---|
| 354 | |
|---|
| 355 | skip_rule 'createArithmeticFromExpAnd' |
|---|
| 356 | from expr_and{!TOKEN.exists} exp |
|---|
| 357 | to Expression |
|---|
| 358 | queries |
|---|
| 359 | s : /exp/#expr_not; |
|---|
| 360 | do |
|---|
| 361 | skip s; |
|---|
| 362 | end_rule |
|---|
| 363 | |
|---|
| 364 | rule 'createBooleanFromExpAnd' |
|---|
| 365 | from expr_and{TOKEN.exists} exp |
|---|
| 366 | to NotExpression |
|---|
| 367 | queries |
|---|
| 368 | expa1 : /exp/#expr_not; |
|---|
| 369 | mappings |
|---|
| 370 | expr = expa1; |
|---|
| 371 | end_rule |
|---|
| 372 | |
|---|
| 373 | rule 'createBooleanFromRelationalOp4' |
|---|
| 374 | from expr_not/relational_op exp |
|---|
| 375 | to BooleanExpression |
|---|
| 376 | queries |
|---|
| 377 | op : /exp/#relational_op; |
|---|
| 378 | expl1 : /exp/#expr_add[0]; |
|---|
| 379 | expl2 : /exp/#expr_add[1]; |
|---|
| 380 | eqOp : /#op{EQ.exists}; |
|---|
| 381 | orOp : /#op{OR.exists}; |
|---|
| 382 | lthOp : /#op{LTH.exists}; |
|---|
| 383 | gthOp : /#op{GTH.exists}; |
|---|
| 384 | notEqOp : /#op{NOT_EQ.exists}; |
|---|
| 385 | leqOp : /#op{LEQ.exists}; |
|---|
| 386 | geqOp : /#op{GEQ.exists}; |
|---|
| 387 | mappings |
|---|
| 388 | expr1 = expl1; |
|---|
| 389 | expr2 = expl2; |
|---|
| 390 | if(eqOp.hasResults) then |
|---|
| 391 | type = "EQUALS"; |
|---|
| 392 | else |
|---|
| 393 | if(orOp.hasResults) then |
|---|
| 394 | type = "OR"; |
|---|
| 395 | else |
|---|
| 396 | if(lthOp.hasResults) then |
|---|
| 397 | type = "LESSTHAN"; |
|---|
| 398 | else |
|---|
| 399 | if(gthOp.hasResults) then |
|---|
| 400 | type = "GREATERTHAN"; |
|---|
| 401 | else |
|---|
| 402 | if(notEqOp.hasResults) then |
|---|
| 403 | type = "NOTEQUALS"; |
|---|
| 404 | else |
|---|
| 405 | if(leqOp.hasResults) then |
|---|
| 406 | type = "LESSEQUALS"; |
|---|
| 407 | else |
|---|
| 408 | if(geqOp.hasResults) then |
|---|
| 409 | type = "GREATEREQUALS"; |
|---|
| 410 | end_if |
|---|
| 411 | end_if |
|---|
| 412 | end_if |
|---|
| 413 | end_if |
|---|
| 414 | end_if |
|---|
| 415 | end_if |
|---|
| 416 | end_if |
|---|
| 417 | end_rule |
|---|
| 418 | |
|---|
| 419 | rule 'createIsNotNull' |
|---|
| 420 | from expr_not{TOKEN[0].exists && TOKEN[0].eq("is") && TOKEN[1].exists && TOKEN[1].eq("not")} exp |
|---|
| 421 | to NotExpression |
|---|
| 422 | queries |
|---|
| 423 | expa : /exp/#expr_add; |
|---|
| 424 | mappings |
|---|
| 425 | expr = new IsNullExpression; |
|---|
| 426 | expr.expr = expa; |
|---|
| 427 | end_rule |
|---|
| 428 | |
|---|
| 429 | rule 'createIsNull' |
|---|
| 430 | from expr_not{TOKEN[0].exists && TOKEN[0].eq("is")} exp |
|---|
| 431 | to IsNullExpression |
|---|
| 432 | queries |
|---|
| 433 | expa : /exp/#expr_add; |
|---|
| 434 | mappings |
|---|
| 435 | expr = expa; |
|---|
| 436 | end_rule |
|---|
| 437 | |
|---|
| 438 | rule 'createNotRangeExpression' |
|---|
| 439 | from expr_not{TOKEN[0].exists && TOKEN[0].eq("not") && TOKEN[1].exists && TOKEN[1].eq("in")} exp |
|---|
| 440 | to NotExpression |
|---|
| 441 | queries |
|---|
| 442 | expa : /exp/#expr_add; |
|---|
| 443 | l : /exp/nested_expressions/nested_expression[0]//#expr_bool; |
|---|
| 444 | u : /exp/nested_expressions/nested_expression[1]//#expr_bool; |
|---|
| 445 | mappings |
|---|
| 446 | expr = new InRangeExpression; |
|---|
| 447 | expr.expr = expa; |
|---|
| 448 | expr.upper = u; |
|---|
| 449 | expr.lower = l; |
|---|
| 450 | end_rule |
|---|
| 451 | |
|---|
| 452 | rule 'createRangeExpression' |
|---|
| 453 | from expr_not{TOKEN[0].exists && TOKEN[0].eq("in")} exp |
|---|
| 454 | to InRangeExpression |
|---|
| 455 | queries |
|---|
| 456 | expa : /exp/#expr_add; |
|---|
| 457 | l : /exp/nested_expressions/nested_expression[0]//#expr_bool; |
|---|
| 458 | u : /exp/nested_expressions/nested_expression[1]//#expr_bool; |
|---|
| 459 | mappings |
|---|
| 460 | expr = expa; |
|---|
| 461 | upper = u; |
|---|
| 462 | lower = l; |
|---|
| 463 | end_rule |
|---|
| 464 | |
|---|
| 465 | rule 'createFoundExpression' |
|---|
| 466 | from expr_not{FOUND_ATTR.exists} exp |
|---|
| 467 | to FoundExpression |
|---|
| 468 | queries |
|---|
| 469 | expa : /exp/expr_add//#identifier; |
|---|
| 470 | cloc : //#declare_spec/cursor_declaration/cursor_name/identifier{ID.eq(expa.ID)}; |
|---|
| 471 | mappings |
|---|
| 472 | cursor = cloc; |
|---|
| 473 | end_rule |
|---|
| 474 | |
|---|
| 475 | skip_rule 'skipFromExprNotToExprAdd' |
|---|
| 476 | from expr_not exp |
|---|
| 477 | to Expression |
|---|
| 478 | queries |
|---|
| 479 | s : /exp/#expr_add; |
|---|
| 480 | do |
|---|
| 481 | skip s; |
|---|
| 482 | end_rule |
|---|
| 483 | |
|---|
| 484 | ------------------------------------------------------------------------ |
|---|
| 485 | -- Expressions (FROM expr_add) |
|---|
| 486 | ------------------------------------------------------------------------ |
|---|
| 487 | |
|---|
| 488 | skip_rule 'skipAllArithmeticRules' |
|---|
| 489 | from expr_add{!PLUS.exists && !MINUS.exists && !DOUBLEVERTBAR.exists}/expr_mul{!ASTERISK.exists && !DIVIDE.exists}/expr_sign{!PLUS.exists && !MINUS.exists}/expr_pow{!EXPONENT.exists} exp |
|---|
| 490 | to Expression |
|---|
| 491 | queries |
|---|
| 492 | s : /exp//#expr_expr; |
|---|
| 493 | do |
|---|
| 494 | skip s; |
|---|
| 495 | end_rule |
|---|
| 496 | |
|---|
| 497 | rule 'createArithmeticFromAddPlus' |
|---|
| 498 | from expr_add{PLUS.exists} exp |
|---|
| 499 | to ArithmeticExpression |
|---|
| 500 | queries |
|---|
| 501 | expa1 : /exp/#expr_mul[0]; |
|---|
| 502 | expa2 : /exp/#expr_mul[1]; |
|---|
| 503 | mappings |
|---|
| 504 | expr1 = expa1; |
|---|
| 505 | type = "PLUS"; |
|---|
| 506 | expr2 = expa2; |
|---|
| 507 | end_rule |
|---|
| 508 | |
|---|
| 509 | rule 'createArithmeticFromAddMinus' |
|---|
| 510 | from expr_add{MINUS.exists} exp |
|---|
| 511 | to ArithmeticExpression |
|---|
| 512 | queries |
|---|
| 513 | expa1 : /exp/#expr_mul[0]; |
|---|
| 514 | expa2 : /exp/#expr_mul[1]; |
|---|
| 515 | mappings |
|---|
| 516 | expr1 = expa1; |
|---|
| 517 | type = "MINUS"; |
|---|
| 518 | expr2 = expa2; |
|---|
| 519 | end_rule |
|---|
| 520 | |
|---|
| 521 | rule 'createArithmeticFromAddDoubleBar' |
|---|
| 522 | from expr_add{DOUBLEVERTBAR.exists} exp |
|---|
| 523 | to ConcatString |
|---|
| 524 | queries |
|---|
| 525 | exps : /exp/#expr_mul; |
|---|
| 526 | mappings |
|---|
| 527 | exprs = exps; |
|---|
| 528 | end_rule |
|---|
| 529 | |
|---|
| 530 | skip_rule 'skipToExprMul' |
|---|
| 531 | from expr_add{!PLUS.exists && !MINUS.exists && !DOUBLEVERTBAR.exists} exp |
|---|
| 532 | to Expression |
|---|
| 533 | queries |
|---|
| 534 | s : /exp/#expr_mul; |
|---|
| 535 | do |
|---|
| 536 | skip s; |
|---|
| 537 | end_rule |
|---|
| 538 | |
|---|
| 539 | rule 'createArithmeticFromMulAsterisk' |
|---|
| 540 | from expr_mul{ASTERISK.exists} exp |
|---|
| 541 | to ArithmeticExpression |
|---|
| 542 | queries |
|---|
| 543 | expa1 : /exp/#expr_sign[0]; |
|---|
| 544 | expa2 : /exp/#expr_sign[1]; |
|---|
| 545 | mappings |
|---|
| 546 | expr1 = expa1; |
|---|
| 547 | type = "MULTIPLICATION"; |
|---|
| 548 | expr2 = expa2; |
|---|
| 549 | end_rule |
|---|
| 550 | |
|---|
| 551 | rule 'createArithmeticFromMulDivide' |
|---|
| 552 | from expr_mul{DIVIDE.exists} exp |
|---|
| 553 | to ArithmeticExpression |
|---|
| 554 | queries |
|---|
| 555 | expa1 : /exp/#expr_sign[0]; |
|---|
| 556 | expa2 : /exp/#expr_sign[1]; |
|---|
| 557 | mappings |
|---|
| 558 | expr1 = expa1; |
|---|
| 559 | type = "DIVISION"; |
|---|
| 560 | expr2 = expa2; |
|---|
| 561 | end_rule |
|---|
| 562 | |
|---|
| 563 | skip_rule 'skipToExprSign' |
|---|
| 564 | from expr_mul{!ASTERISK.exists && !DIVIDE.exists} exp |
|---|
| 565 | to Expression |
|---|
| 566 | queries |
|---|
| 567 | s : /exp/#expr_sign; |
|---|
| 568 | do |
|---|
| 569 | skip s; |
|---|
| 570 | end_rule |
|---|
| 571 | |
|---|
| 572 | rule 'createArithmeticFromSignPositive' |
|---|
| 573 | from expr_sign{PLUS.exists} exp |
|---|
| 574 | to ArithmeticExpression |
|---|
| 575 | queries |
|---|
| 576 | expa1 : /exp/#expr_pow[0]; |
|---|
| 577 | mappings |
|---|
| 578 | expr1 = expa1; |
|---|
| 579 | type = "POSITIVE"; |
|---|
| 580 | end_rule |
|---|
| 581 | |
|---|
| 582 | rule 'createArithmeticFromSignNegative' |
|---|
| 583 | from expr_sign{MINUS.exists} exp |
|---|
| 584 | to ArithmeticExpression |
|---|
| 585 | queries |
|---|
| 586 | expa1 : /exp/#expr_pow[0]; |
|---|
| 587 | mappings |
|---|
| 588 | expr1 = expa1; |
|---|
| 589 | type = "NEGATIVE"; |
|---|
| 590 | end_rule |
|---|
| 591 | |
|---|
| 592 | skip_rule 'skipToExprPow' |
|---|
| 593 | from expr_sign{!PLUS.exists && !MINUS.exists} exp |
|---|
| 594 | to Expression |
|---|
| 595 | queries |
|---|
| 596 | s : /exp/#expr_pow; |
|---|
| 597 | do |
|---|
| 598 | skip s; |
|---|
| 599 | end_rule |
|---|
| 600 | |
|---|
| 601 | rule 'createArithmethicFromPow' |
|---|
| 602 | from expr_pow{EXPONENT.exists} exp |
|---|
| 603 | to ArithmeticExpression |
|---|
| 604 | queries |
|---|
| 605 | expa1 : /exp/#expr_expr[0]; |
|---|
| 606 | expa2 : /exp/#expr_expr[1]; |
|---|
| 607 | mappings |
|---|
| 608 | expr1 = expa1; |
|---|
| 609 | type = "EXPONENT"; |
|---|
| 610 | expr2 = expa2; |
|---|
| 611 | end_rule |
|---|
| 612 | |
|---|
| 613 | skip_rule 'skipToExprExpr' |
|---|
| 614 | from expr_pow{!EXPONENT.exists} exp |
|---|
| 615 | to Expression |
|---|
| 616 | queries |
|---|
| 617 | s : /exp/#expr_expr; |
|---|
| 618 | do |
|---|
| 619 | skip s; |
|---|
| 620 | end_rule |
|---|
| 621 | |
|---|
| 622 | rule 'createFormsVariableFromExpAdd' |
|---|
| 623 | from expr_expr/simple_expression{COLON.exists} ea |
|---|
| 624 | to FormsVarRef |
|---|
| 625 | queries |
|---|
| 626 | se : /ea//simple_expression/#host_variable; |
|---|
| 627 | mappings |
|---|
| 628 | reference = extractID se; |
|---|
| 629 | end_rule |
|---|
| 630 | |
|---|
| 631 | skip_rule 'createFunctionCallFromExprAddFunctionExpr' |
|---|
| 632 | from expr_expr/function_expression exp |
|---|
| 633 | to Expression |
|---|
| 634 | queries |
|---|
| 635 | s : /exp//function_expression/#function_call; |
|---|
| 636 | block : //#plsql_block///expr_expr{this.check(exp)}; |
|---|
| 637 | iden : /s//#identifier; |
|---|
| 638 | dec : /block//#declare_spec/variable_declaration/variable_name/identifier{ID.eq(iden.ID)}; |
|---|
| 639 | cast1 : (variable_name) /s//#sql_identifier/identifier; |
|---|
| 640 | cast2 : /s//#variable_name/identifier; |
|---|
| 641 | do |
|---|
| 642 | if(dec.hasResults) then |
|---|
| 643 | if(cast1.hasResults) then |
|---|
| 644 | skip cast1; |
|---|
| 645 | else |
|---|
| 646 | skip cast2; |
|---|
| 647 | end_if |
|---|
| 648 | else |
|---|
| 649 | skip s; |
|---|
| 650 | end_if |
|---|
| 651 | end_rule |
|---|
| 652 | |
|---|
| 653 | rule 'createLiteralFromExprAddQuotedString' |
|---|
| 654 | from expr_expr/simple_expression{QUOTED_STRING.exists || TOKEN.exists || NUMBER.exists} exp |
|---|
| 655 | to LiteralExpression |
|---|
| 656 | queries |
|---|
| 657 | st : /exp//#simple_expression; |
|---|
| 658 | stringExists : /exp//#simple_expression{QUOTED_STRING.exists}; |
|---|
| 659 | nullExists : /exp//#simple_expression{TOKEN.exists}; |
|---|
| 660 | numberExists : /exp//#simple_expression{NUMBER.exists}; |
|---|
| 661 | mappings |
|---|
| 662 | if(stringExists.hasResults) then |
|---|
| 663 | type = "STRING"; |
|---|
| 664 | else |
|---|
| 665 | if(nullExists.hasResults) then |
|---|
| 666 | type = "NULL"; |
|---|
| 667 | else |
|---|
| 668 | if(numberExists.hasResults) then |
|---|
| 669 | type = "INTEGER"; |
|---|
| 670 | end_if |
|---|
| 671 | end_if |
|---|
| 672 | end_if |
|---|
| 673 | value = extract st; |
|---|
| 674 | end_rule |
|---|
| 675 | |
|---|
| 676 | skip_rule 'skipToExprBoolFromExprParen' |
|---|
| 677 | from expr_expr/expr_paren exp |
|---|
| 678 | to Expression |
|---|
| 679 | queries |
|---|
| 680 | s : /exp//#expr_bool; |
|---|
| 681 | do |
|---|
| 682 | skip s; |
|---|
| 683 | end_rule |
|---|
| 684 | |
|---|
| 685 | ------------------------------------------------------------------------ |
|---|
| 686 | -- Function Call |
|---|
| 687 | ------------------------------------------------------------------------ |
|---|
| 688 | |
|---|
| 689 | rule 'createFunctionCallGeneral' |
|---|
| 690 | from function_call fc |
|---|
| 691 | to FunctionCallStatement |
|---|
| 692 | queries |
|---|
| 693 | iden : /fc/user_defined_function//#identifier; |
|---|
| 694 | params : /fc/call_parameters/#call_parameter; |
|---|
| 695 | exp : /fc//#nested_expression; |
|---|
| 696 | mappings |
|---|
| 697 | name = iden.ID; |
|---|
| 698 | parameters = params; |
|---|
| 699 | --expr = exp; |
|---|
| 700 | end_rule |
|---|
| 701 | |
|---|
| 702 | rule 'createFunctionCallParamForFunctionCall' |
|---|
| 703 | from call_parameter cp |
|---|
| 704 | to FunctionCallParameter |
|---|
| 705 | queries |
|---|
| 706 | iden : /cp/parameter_name/#identifier; |
|---|
| 707 | exp : /cp//plsql_expression/#expr_bool; |
|---|
| 708 | mappings |
|---|
| 709 | name = iden.ID; |
|---|
| 710 | expr = exp; |
|---|
| 711 | end_rule |
|---|
| 712 | |
|---|
| 713 | |
|---|
| 714 | ------------------------------------------------------------------------ |
|---|
| 715 | -- Select Statement |
|---|
| 716 | ------------------------------------------------------------------------ |
|---|
| 717 | |
|---|
| 718 | rule 'createSelectStatement' |
|---|
| 719 | from select_statement sel |
|---|
| 720 | to SelectStatement |
|---|
| 721 | queries |
|---|
| 722 | sexpr : /sel/#select_expression; |
|---|
| 723 | list : /sexpr//#displayed_column; |
|---|
| 724 | isCount : /list//#keyCOUNT; |
|---|
| 725 | lvals : /sexpr//lvalues/#lvalue; |
|---|
| 726 | fromn : /sexpr/#table_reference_list; |
|---|
| 727 | fromj : /sexpr/#join_clause; |
|---|
| 728 | w : /sexpr//where_clause/#sql_condition; |
|---|
| 729 | mappings |
|---|
| 730 | if(isCount.hasResults) then |
|---|
| 731 | isCount = "true"; |
|---|
| 732 | end_if |
|---|
| 733 | selectList = extractID list; |
|---|
| 734 | into = lvals; |
|---|
| 735 | if(fromn.hasResults) then |
|---|
| 736 | _from = extractID fromn; |
|---|
| 737 | else |
|---|
| 738 | _from = extractID fromj; |
|---|
| 739 | end_if |
|---|
| 740 | where = w; |
|---|
| 741 | end_rule |
|---|
| 742 | |
|---|
| 743 | ------------------------------------------------------------------------ |
|---|
| 744 | -- Conditions |
|---|
| 745 | ------------------------------------------------------------------------ |
|---|
| 746 | |
|---|
| 747 | rule 'createConditionComparison' |
|---|
| 748 | from sql_condition//condition_comparison sc |
|---|
| 749 | to ConditionComparison |
|---|
| 750 | queries |
|---|
| 751 | compar : /sc//#condition_comparison; |
|---|
| 752 | exp1 : /compar/sql_expression[0]/#expr_add; |
|---|
| 753 | exp2 : /compar/sql_expression[1]/#expr_add; |
|---|
| 754 | eqOp : /#compar{EQ.exists}; |
|---|
| 755 | orOp : /#compar{OR.exists}; |
|---|
| 756 | lthOp : /#compar{LTH.exists}; |
|---|
| 757 | gthOp : /#compar{GTH.exists}; |
|---|
| 758 | notEqOp : /#compar{NOT_EQ.exists}; |
|---|
| 759 | leqOp : /#compar{LEQ.exists}; |
|---|
| 760 | geqOp : /#compar{GEQ.exists}; |
|---|
| 761 | mappings |
|---|
| 762 | expr1 = exp1; |
|---|
| 763 | expr2 = exp2; |
|---|
| 764 | if(eqOp.hasResults) then |
|---|
| 765 | type = "EQUALS"; |
|---|
| 766 | else |
|---|
| 767 | if(orOp.hasResults) then |
|---|
| 768 | type = "OR"; |
|---|
| 769 | else |
|---|
| 770 | if(lthOp.hasResults) then |
|---|
| 771 | type = "LESSTHAN"; |
|---|
| 772 | else |
|---|
| 773 | if(gthOp.hasResults) then |
|---|
| 774 | type = "GREATERTHAN"; |
|---|
| 775 | else |
|---|
| 776 | if(notEqOp.hasResults) then |
|---|
| 777 | type = "NOTEQUALS"; |
|---|
| 778 | else |
|---|
| 779 | if(leqOp.hasResults) then |
|---|
| 780 | type = "LESSEQUALS"; |
|---|
| 781 | else |
|---|
| 782 | if(geqOp.hasResults) then |
|---|
| 783 | type = "GREATEREQUALS"; |
|---|
| 784 | end_if |
|---|
| 785 | end_if |
|---|
| 786 | end_if |
|---|
| 787 | end_if |
|---|
| 788 | end_if |
|---|
| 789 | end_if |
|---|
| 790 | end_if |
|---|
| 791 | end_rule |
|---|