[antlr-interest] MismatchedTokenExeption vs xml processing

Scott Stanchfield scott at javadude.com
Mon Feb 28 12:06:31 PST 2011


You may want to have a peek at ANTXR, my ANTLR derivative for XML
processing. It may make your parsing much simpler (especially with the
"any tag" processing I describe on the web page).

See http://javadude.com/tools/antxr
-- Scott

----------------------------------------
Scott Stanchfield
http://javadude.com



On Mon, Feb 28, 2011 at 2:59 PM, Sergey Staroletov
<sergey.staroletov at gmail.com> wrote:
> Hi everyone here.
> I want to process my custom xml (just for theses annotation)
>
> part of grammar there (some was cut):
>
>
> grammar testg;
>
> options {
>  language = Java;
> }
>
> component: (state)* ;
> state: oneState|subAutomaton ;
> oneState:  TAG_OPEN 'state' stateAttribs TAG_CLOSE stateBody TAG_OPEN
> '/state' TAG_CLOSE;
> stateAttribs: (stateAttrib '=' Value)* ;
> stateAttrib: 'threadId' | 'srcFile' | 'srcLineFrom' | 'srcLineTo' |
> 'name' | 'N' | 'subAutomatonId' | 'firstState' | 'finalState'|'active';
> stateBody: (state|operation|transition)* ;
> subAutomaton: TAG_OPEN 'subAutomaton' subAutomatonAttribs TAG_CLOSE
> subAutomatonBody TAG_OPEN '/subAutomaton' TAG_CLOSE ;
> subAutomatonAttribs: (subAutomatonAttrib '=' Value)* ;
> subAutomatonAttrib: 'name'|'firstState'|'parent' ;
> subAutomatonBody: (finalState|oneState)* ;
> finalState: TAG_OPEN 'final' 'state' '=' Value TAG_CLOSE_WITHOUT_BODY;
> transition: (TAG_OPEN 'jump' transitionAttribs) (TAG_CLOSE_WITHOUT_BODY |
> (TAG_CLOSE transitionBody TAG_OPEN '/jump' TAG_CLOSE)) ;
> transitionAttribs: (transitionAttrib '=' Value)* ;
> transitionAttrib: 'transitionString' | 'p' | 'toState';
> transitionBody: (event)* ;
> operation: (fork|join) ;
> operationAttribs: (operationAttrib '=' Value)*;
> operationAttrib: 'p'|'nextState' ;
> fork: TAG_OPEN 'fork' operationAttribs TAG_CLOSE forkBody TAG_OPEN '/fork'
> TAG_CLOSE ;
> forkBody: 'body';
> join: TAG_OPEN 'join' operationAttribs TAG_CLOSE joinBody TAG_OPEN '/join'
> TAG_CLOSE;
> joinBody: 'body' ;
> event: TAG_OPEN 'event' eventAttribs  (TAG_CLOSE_WITHOUT_BODY |( TAG_CLOSE
> eventBody TAG_OPEN '/event' TAG_CLOSE)) ;
> eventAttribs: (eventAttrib '=' Value)* ;
> eventAttrib: 'eventState'|'eventSubautomaton'|'p' | 'warn' | 'iFlag' |
> 'returnState'|'timeout';
> eventBody: (state)* ;
> Value: '"' Identifier '"' ;
> TAG_OPEN : '<'  ;
> TAG_CLOSE: '>' ;
> TAG_CLOSE_WITHOUT_BODY : '/>' ;
> Identifier :
>  Letter (Letter | Digit)*;
>  fragment
>  Letter :
>      'a'..'z' |
>    'A'..'Z'|'_';
>    fragment
>   Digit :
>      '0'..'9';
>  WS  : (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;};
>
>
>
> Testcase #1
> <state name="test">
> <subAutomaton name="test" firstState="connect">
> <final state="connect"/>
> <state name="connect">
> </state>
> </subAutomaton>
> </state>
> result: OK
> Testcase #2 (just rotated <final and  <state , but rule
> is: subAutomatonBody: (finalState|oneState)* ; that matter no change?
> <state name="test">
> <subAutomaton name="test" firstState="connect">
> <state name="connect">
> </state>
> <final state="connect"/>
> </subAutomaton>
> </state>
> result: Error, mismatch input 'state' expecting '\u001A'
> Why?
>
> Testcase #3
> <state name="test">
> <subAutomaton name="test" firstState="connect">
> <final state="connect"/>
> <state name="connect">
>  <fork>body</fork>
> </state>
> </subAutomaton>
> </state>
> result: error
>
> Testcase #4 (just add <state></state>)
> <state name="test">
> <subAutomaton name="test" firstState="connect">
> <final state="connect"/>
> <state name="connect">
> <state></state>
> <fork>body</fork>
> </state>
> </subAutomaton>
> </state>
> result:ok
>
> (a|b)* works as i haven't realized...
>
> The grammar works in my mind, but it can't work in practice:(
>
>
>
>
>
>
>
>
> --
> Sergey
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list