The following grammar (in the ANLTR parser generator notation) defines the syntax of promotion selection expressions.

grammar SentinelPromotionScript;

promotionCondition
    : predicate EOF
    ;

predicate
    : andPred ('||' andPred)*
    ;

andPred
    : condition ('&&' condition)*
    ;

condition
    : '(' predicate ')'
    | '!' condition
    | comparison
    ;

comparison
    : expression (COMPARATOR expression)?
    ;

expression
    : ID ('.' ID)* '(' argumentList? ')'
    | id=ID ('.' ID)* (pathExpr)? //a variable is a function without args
    | LONG
    | STRING
    ;


argumentList
    : expression (',' expression )*
    ;

pathExpr
    : '/'  relativePathExpr?
    | '//' relativePathExpr
    |      relativePathExpr
    ;

relativePathExpr:
    stepExpr
    (( '/' | '//' ) stepExpr )*
    ;

stepExpr:
    ( '.'
         | abbrevForwardStep
         ) (xpathpredicate)?
    ;

abbrevForwardStep
    :    attributeFlag = '@'? (stQName = qName | stNodeExpansion =  '*')
    ;

xpathpredicate
    :    '[' orExpr ']'
    ;

orExpr  :  andExpr ('or' andExpr)*
  ;

andExpr  :  comparisonexpr ('and' comparisonexpr)*
  ;

comparisonexpr: primaryExpr (COMPARATOR  literal)?;

primaryExpr
    :    pathExpr | '(' pathExpr ')' | LONG
    ;

literal : STRING | numericLiteral | varRef;

numericLiteral: LONG DECIMALLITERAL | DOUBLELITERAL;

qName: (ID ':' ID) | ID;

varRef: '$' nCName;

nCName: ID ('.' ID)*;


COMPARATOR : '==' | '<' | '>' | '!=' | '<=' | '>=';

ID  : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;

LONG :  ('-')? '0'..'9'+ ;

DECIMALLITERAL :  ('.' ('0'..'9')+)  | (('0'..'9')+ '.' '0'..'9'*);
DOUBLELITERAL  :  (('.' ('0'..'9')+) | (('0'..'9')+ ('.' '0'..'9'*)?)) ('e' | 'E') ('+' | '-')? ('0'..'9')+;

STRING
    :  '"' ~('\\'|'"')* '"'
    ;


WS  :   ( ' '
    | '\t'
    | '\r'
    | '\n'
    )
;
Previous page Next page
Sentinel Express Version 3.1.0