[antlr-interest] MismatchedTokenExeption vs xml processing

Sergey Staroletov sergey.staroletov at gmail.com
Mon Feb 28 11:59:13 PST 2011


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


More information about the antlr-interest mailing list