Antlr4 - 条款的排序

时间:2016-04-27 13:12:33

标签: java parsing antlr antlr4

我有这条规则:

query
    : SELECT  selectAttribute (',' selectAttribute)*
      FROM from
      (WHERE where=booleanExpression)?
      (ORDER BY sortItem (',' sortItem)*)?
      (LIMIT limit=(INTEGER_VALUE | ALL))?
      (IGNOREHIDDENFILES ignoreHiddenFiles=booleanValue)?
      (FOLLOWSYMLINKS followSymlinks=booleanValue)?
      SEMICOLON
    ;

这是有效的;

SELECT name FROM /tmp 
IGNOREHIDDENFILES true
FOLLOWSYMLINKS true

但是,这是无效的:

SELECT name FROM /tmp 
FOLLOWSYMLINKS true
IGNOREHIDDENFILES true

我想告诉规则,订单与IGNOREHIDDENFILESFOLLOWSYMLINKS

无关

1 个答案:

答案 0 :(得分:2)

从我的头脑中 - 创建一个子规则,并在query中使用*。

编辑 @NiloPaim在评论中指出,我已做出更改,不使用*通配符。如:

query: query_first SEMICOLON
     | query_first ignoreHiddenFilesPart (followSymlinksPArt)? SEMICOLON
     | query_first followSymlinksPArt (ignoreHiddenFilesPart)? SEMICOLON
     ;
query_first : SELECT  selectAttribute (',' selectAttribute)*
      FROM from
      (WHERE where=booleanExpression)?
      (ORDER BY sortItem (',' sortItem)*)?
      (LIMIT limit=(INTEGER_VALUE | ALL))?
            ;
ignoreHiddenFilesPart: IGNOREHIDDENFILES ignoreHiddenFiles=booleanValue ;
followSymlinksPArt: FOLLOWSYMLINKS followSymlinks=booleanValue ;