All files / src/abap/2_statements/expressions source.ts

100% Statements 147/147
100% Branches 1/1
100% Functions 1/1
100% Lines 147/147

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 1471x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 1x
import {ver, seq, tok, altPrio, optPrio, regex, Expression, starPrio, star, AlsoIn} from "../combi";
import {WParenLeftW, WParenRightW, WDashW, ParenLeftW, WPlus, WPlusW, Dash, ParenRightW, ParenLeft} from "../../1_lexer/tokens";
import {CondBody, SwitchBody, ComponentChain, FieldChain, ReduceBody, TypeNameOrInfer, Cast,
  MethodCallChain, ArithOperator, Cond, Constant, StringTemplate, ConvBody, CorrespondingBody, ValueBody, FilterBody, Arrow} from ".";
import {Release} from "../../../version";
import {IStatementRunnable} from "../statement_runnable";
import {TextElement} from "./text_element";
import {AttributeChain} from "./attribute_chain";
import {Dereference} from "./dereference";
import {dynAttr, dynComp} from "./_dynamic_access";
 
// todo, COND and SWITCH are quite similar?
 
// this class is used quite often, so its nice to have the differentiating tokens part of it
 
export class Source extends Expression {
  public getRunnable(): IStatementRunnable {
    const comp = seq(tok(Dash), ComponentChain);
    const attr = seq(Arrow, AttributeChain);
    const deref = optPrio(ver(Release.v756, Dereference));
 
// below v756 "->*" directly after a functional method call is a syntax error, CAST can be dereferenced
    const dynChain = star(seq(altPrio(dynAttr(), dynComp()), optPrio(Dereference)));
    const castDeref = seq(Cast, Dereference);
 
    const method = seq(MethodCallChain, optPrio(altPrio(attr, comp)), deref, dynChain);
 
    const rparen = tok(WParenRightW);
    const rparenNoSpace = altPrio(tok(ParenRightW), tok(WParenRightW));
    const lparenNoSpace = altPrio(tok(ParenLeft), tok(ParenLeftW));
 
// paren used for eg. "( 2 + 1 ) * 4"
    const paren = seq(tok(WParenLeftW),
                      Source,
                      rparen);
 
    const after = seq(altPrio("&", "&&", ArithOperator), Source);
 
    const bool = seq(altPrio(ver(Release.v702, regex(/^BOOLC$/i), {also: AlsoIn.OpenABAP}),
                             ver(Release.v740sp08, regex(/^XSDBOOL$/i), {also: AlsoIn.OpenABAP})),
                     tok(ParenLeftW),
                     Cond,
                     ")");
 
// the bool parameter of boolx( ) is a logical expression, the parameters can come in any order
    const boolxBool = seq("BOOL", "=", Cond);
    const boolxBit = seq("BIT", "=", Source);
    const boolx = ver(Release.v702, seq(regex(/^BOOLX$/i),
                                        tok(ParenLeftW),
                                        altPrio(seq(boolxBool, optPrio(boolxBit)), seq(boolxBit, boolxBool)),
                                        ")"));
 
// "bit-set" is lexed as three tokens, without space around the dash
    const bitSet = ver(Release.v702, seq(regex(/^BIT$/i),
                                         tok(Dash),
                                         regex(/^SET$/i),
                                         tok(ParenLeftW),
                                         optPrio(seq("VAL", "=")),
                                         Source,
                                         ")"));
 
    const prefix = altPrio(tok(WPlus), "BIT-NOT");
 
    const old = seq(optPrio(prefix), altPrio(Constant,
                                             StringTemplate,
                                             TextElement,
                                             bool,
                                             boolx,
                                             bitSet,
                                             castDeref,
                                             method,
                                             seq(FieldChain, deref),
                                             paren),
                    optPrio(after));
 
    const corr = ver(Release.v740sp05, seq("CORRESPONDING",
                                           TypeNameOrInfer,
                                           tok(ParenLeftW),
                                           CorrespondingBody,
                                           rparen,
                                           optPrio(after)), {also: AlsoIn.OpenABAP});
 
    const conv = ver(Release.v740sp02, seq("CONV",
                                           TypeNameOrInfer,
                                           lparenNoSpace,
                                           ConvBody,
                                           rparenNoSpace,
                                           optPrio(after)), {also: AlsoIn.OpenABAP});
 
    const swit = ver(Release.v740sp02, seq("SWITCH",
                                           TypeNameOrInfer,
                                           tok(ParenLeftW),
                                           SwitchBody,
                                           rparenNoSpace,
                                           optPrio(after)), {also: AlsoIn.OpenABAP});
 
    const value = ver(Release.v740sp02, seq("VALUE",
                                            TypeNameOrInfer,
                                            tok(ParenLeftW),
                                            ValueBody,
                                            rparenNoSpace,
                                            optPrio(after)), {also: AlsoIn.OpenABAP});
 
    const cond = ver(Release.v740sp02, seq("COND",
                                           TypeNameOrInfer,
                                           tok(ParenLeftW),
                                           CondBody,
                                           rparenNoSpace,
                                           optPrio(after)), {also: AlsoIn.OpenABAP});
 
    const reff = ver(Release.v740sp02, seq("REF",
                                           TypeNameOrInfer,
                                           tok(ParenLeftW),
                                           Source,
                                           optPrio("OPTIONAL"),
                                           rparen), {also: AlsoIn.OpenABAP});
 
    const exact = ver(Release.v740sp02, seq("EXACT",
                                            TypeNameOrInfer,
                                            tok(ParenLeftW),
                                            Source,
                                            rparen,
                                            optPrio(after)), {also: AlsoIn.OpenABAP});
 
    const filter = ver(Release.v740sp08,
                       seq("FILTER",
                           TypeNameOrInfer,
                           tok(ParenLeftW),
                           FilterBody,
                           rparen), {also: AlsoIn.OpenABAP});
 
    const reduce = ver(Release.v740sp08,
                       seq("REDUCE",
                           TypeNameOrInfer,
                           tok(ParenLeftW),
                           ReduceBody,
                           rparen,
                           optPrio(after)), {also: AlsoIn.OpenABAP});
 
    const prefix1 = altPrio(tok(WDashW), tok(WPlusW));
 
    const ret = seq(starPrio(prefix1),
                    altPrio(filter, reff, corr, conv, value, cond, exact, swit, reduce, old));
 
    return ret;
  }
}