How to parse block with with single markup element

13 views
Skip to first unread message

kulmam

unread,
Sep 18, 2017, 11:48:40 AM9/18/17
to antlr-discussion
Hi 

I'm trying to parse below text but having trouble. Can someone help me out?

--+block1:
    select * from emp
    where 1=2
--+block2:
    select 1 from dept
    ddvggh
--+block3:
    set nocount on
    set nocount on;
    dfdfdf;
    dfdfd
    
    dfdfdf;
    dfdfdf;


Desired output
  1. Use --+ .*? : as block separator
  2. Get between --+ and : as name of the block
  3. Get multiline text between block separator as script that belongs to previous block separator


lexer grammar multilexer;

CODE: 'code';
LCURLY: '--+' .*? ':' -> pushMode(CODE_0);
WS1: WS -> skip;
NL1: NL -> skip;

mode CODE_0;

CODE_0_LCURLY: '--+' .*? ':' -> type(OTHER), pushMode(CODE_N);
RCURLY: ( WS1 | NL1 )* (LCURLY | EOF) -> popMode; // Close for LCURLY
CODE_0_OTHER: ~('-')+ -> type(OTHER);
CODE_0_TAG: '--+' .*? ':' -> type(TAG);

mode CODE_N;

CODE_N_LCURLY: LCURLY -> type(OTHER), pushMode(CODE_N);
CODE_N_RCURLY: ( WS1 | NL1 )* (LCURLY | EOF) -> type(OTHER), popMode;
OTHER: ~('-')+;
TAG: '--+' .*? ':';

fragment WS : [ \t\f]+ ;
fragment NL : '\r'? '\n' ;

parser grammar multiparser;
options { tokenVocab = multilexer ; }

skip_code: LCURLY OTHER* RCURLY;

Current output



Error
line 14:11 mismatched input '<EOF>' expecting {RCURLY, OTHER}

Problem
  • error message
  • need to get block name
  • need to put select and set statement under each block

Thanks.

Reply all
Reply to author
Forward
0 new messages