@@ -33,6 +33,7 @@ export class SoqlParser extends CstParser {
3333 private $_aggregateFunction : any = undefined ;
3434 private $_otherFunction : any = undefined ;
3535 private $_atomicExpression : any = undefined ;
36+ private $_apexBindVariableExpression : any = undefined ;
3637 private $_arrayExpression : any = undefined ;
3738 private $_relationalOperator : any = undefined ;
3839 private $_selectClause : any = undefined ;
@@ -617,7 +618,79 @@ export class SoqlParser extends CstParser {
617618
618619 private apexBindVariableExpression = this . RULE ( 'apexBindVariableExpression' , ( ) => {
619620 this . CONSUME ( lexer . Colon ) ;
621+ // First item in list could optionally be a new instantiation
622+ this . OPTION ( ( ) => {
623+ this . SUBRULE ( this . apexBindVariableNewInstantiation , { LABEL : 'apex' } ) ;
624+ this . OPTION1 ( ( ) => {
625+ this . CONSUME ( lexer . Decimal ) ;
626+ } ) ;
627+ } ) ;
628+ // Chained function calls or nested arguments with function calls at the end
629+ this . MANY_SEP ( {
630+ SEP : lexer . Decimal ,
631+ DEF : ( ) => {
632+ this . OR (
633+ this . $_apexBindVariableExpression ||
634+ ( this . $_apexBindVariableExpression = [
635+ { ALT : ( ) => this . SUBRULE ( this . apexBindVariableFunctionCall , { LABEL : 'apex' } ) } ,
636+ { ALT : ( ) => this . SUBRULE ( this . apexBindVariableIdentifier , { LABEL : 'apex' } ) } ,
637+ ] ) ,
638+ ) ;
639+ } ,
640+ } ) ;
641+ } ) ;
642+
643+ private apexBindVariableIdentifier = this . RULE ( 'apexBindVariableIdentifier' , ( ) => {
620644 this . CONSUME ( lexer . Identifier ) ;
645+ this . OPTION ( ( ) => this . SUBRULE ( this . apexBindVariableFunctionArrayAccessor ) ) ;
646+ } ) ;
647+
648+ private apexBindVariableNewInstantiation = this . RULE ( 'apexBindVariableNewInstantiation' , ( ) => {
649+ this . CONSUME ( lexer . ApexNew , { LABEL : 'new' } ) ;
650+ this . CONSUME ( lexer . Identifier , { LABEL : 'function' } ) ;
651+ this . OPTION ( ( ) => {
652+ this . SUBRULE ( this . apexBindVariableGeneric ) ;
653+ } ) ;
654+ this . SUBRULE ( this . apexBindVariableFunctionParams ) ;
655+ this . OPTION1 ( ( ) => this . SUBRULE ( this . apexBindVariableFunctionArrayAccessor ) ) ;
656+ } ) ;
657+
658+ private apexBindVariableFunctionCall = this . RULE ( 'apexBindVariableFunctionCall' , ( ) => {
659+ this . CONSUME ( lexer . Identifier , { LABEL : 'function' } ) ;
660+ this . SUBRULE ( this . apexBindVariableFunctionParams ) ;
661+ this . OPTION ( ( ) => this . SUBRULE ( this . apexBindVariableFunctionArrayAccessor ) ) ;
662+ } ) ;
663+
664+ private apexBindVariableGeneric = this . RULE ( 'apexBindVariableGeneric' , ( ) => {
665+ this . CONSUME ( lexer . LessThan ) ;
666+ this . AT_LEAST_ONE_SEP ( {
667+ SEP : lexer . Comma ,
668+ DEF : ( ) => {
669+ this . CONSUME ( lexer . Identifier , { LABEL : 'parameter' } ) ;
670+ } ,
671+ } ) ;
672+ this . CONSUME ( lexer . GreaterThan ) ;
673+ } ) ;
674+
675+ private apexBindVariableFunctionParams = this . RULE ( 'apexBindVariableFunctionParams' , ( ) => {
676+ this . CONSUME ( lexer . LParen ) ;
677+ this . MANY_SEP ( {
678+ SEP : lexer . Comma ,
679+ DEF : ( ) => {
680+ this . CONSUME ( lexer . Identifier , { LABEL : 'parameter' } ) ;
681+ } ,
682+ } ) ;
683+ this . CONSUME ( lexer . RParen ) ;
684+ } ) ;
685+
686+ // foo[3] or foo[somIntVariable]
687+ private apexBindVariableFunctionArrayAccessor = this . RULE ( 'apexBindVariableFunctionArrayAccessor' , ( ) => {
688+ this . CONSUME ( lexer . LSquareBracket ) ;
689+ this . OR ( [
690+ { ALT : ( ) => this . CONSUME ( lexer . UnsignedInteger , { LABEL : 'value' } ) } ,
691+ { ALT : ( ) => this . CONSUME ( lexer . Identifier , { LABEL : 'value' } ) } ,
692+ ] ) ;
693+ this . CONSUME ( lexer . RSquareBracket ) ;
621694 } ) ;
622695
623696 private arrayExpression = this . RULE ( 'arrayExpression' , ( ) => {
0 commit comments