0

我已经修改了 [Porcelli] ( https://github.com/porcelli/plsql-parser ) 给出的 PLSQL 解析器。我正在使用这个解析器来解析 PlSql 文件。我在解析 FOR 循环语句时遇到问题,例如

for i in 1..l_line_tbl.count
LOOP
l_line_tbl(i).schedule_ship_date := l_max_ship_date;
l_line_tbl(i).ship_set_id := x_ship_set_id;
END LOOP;

上面的语句没有解析并且它抛出 EarlyExitException。

现在,如果我修改此语句并在 1 和双点 (..) 之间放置一个空格,它将解析该语句。我不确定如何处理第一种情况。

for i in 1 ..l_line_tbl.count
LOOP
l_line_tbl(i).schedule_ship_date := l_max_ship_date;
l_line_tbl(i).ship_set_id := x_ship_set_id;
END LOOP;

解析器语法:

loop_statement
@init    {    int mode = 0;    } 
:    label_name?
    (while_key condition {mode = 1;} | for_key cursor_loop_param {mode = 2;})?
    loop_key
    seq_of_statements
    end_key loop_key label_name?
    -> {mode == 1}? ^(WHILE_LOOP[$while_key.start] label_name* 
    ^(LOGIC_EXPR condition) seq_of_statements)
    -> {mode == 2}? ^(FOR_LOOP[$for_key.start] label_name* cursor_loop_param seq_of_statements)
    -> ^(loop_key label_name* seq_of_statements)
;

// $<Loop - Specific Clause

cursor_loop_param
@init    {    int mode = 0;    }
:    (index_name in_key reverse_key? lower_bound DOUBLE_PERIOD)=> 
        index_name in_key reverse_key? lower_bound DOUBLE_PERIOD upper_bound
    -> ^(INDEXED_FOR index_name reverse_key? ^(SIMPLE_BOUND lower_bound upper_bound))
|     record_name in_key ( cursor_name expression_list? {mode = 1;} | LEFT_PAREN 
select_statement RIGHT_PAREN)
    ->{mode == 1}? ^(CURSOR_BASED_FOR record_name cursor_name expression_list?)
    -> ^(SELECT_BASED_FOR record_name select_statement)
;

// $>

词法分析器语法:

FOR_NOTATION
:    UNSIGNED_INTEGER
    {state.type = UNSIGNED_INTEGER; emit(); advanceInput();}
    '..'
    {state.type = DOUBLE_PERIOD; emit(); advanceInput();}
    UNSIGNED_INTEGER
    {state.type = UNSIGNED_INTEGER; emit(); advanceInput(); $channel=HIDDEN;}
;

fragment
UNSIGNED_INTEGER
:    ('0'..'9')+ 
;
4

0 回答 0