<!--
   XML In XML  version 2006-04-23

   State-Transition-Action document for parsing XML.
   History:
     Tim Bray		1996	Used for generating tables for Lark XML processor
     Rick Jelliffe	2006 	Convert to XML syntax

    Copyright (C) 1999,2006 Tim Bray, Rick Jelliffe

    Permission granted to use under the terms of the Lesser GNU Public License, the
    MIT public license, the BSD licence or the Artistic license, mutatis mutandis.

    For background information, see 
      http://www.tbray.org/ongoing/When/200x/2006/04/18/XML-Grammar

    This specification can be used to generate various kinds of state/stack machines
    for parsing XML. This can substantially reduce the work involved in creating an
    conforming XML processor; it is important for interoperability to implement the
    full XML specification for a well-formed XML parser or a validating parser. (Of course,
    you can also use this specification to make a custom XML processor that reports or uses
    only a subset of XML, but an XML-subset processor should not be marketed or benchmarked
    as a real XML processor; best practise is to accept all well-formed XML even if only
    parts are used; errors due to incomplete implementations should labelled as non-XML
    errors.)

    For a complete XML processor, the machine specified here will notionally be sandwiched 
    between a prior layer that performs transcoding to Unicode, bad XML character detection, 
    newline handling, and possibly Unicode normalization, and a subsequent layer which 
    performs declaration-dependent well-formedness and validity checking, name nesting
    matching, non-space characters in element content checking, etc. The machine also needs
    to handle references to parameter and general entities and references to characters.

    This specification has the following features:

    * In a state, when a single input character matches the character or character class in
      the @on attribute of a <transition> element, then the @do actions of the <transition> should be performed
      (which may involve pushing and popping), then the actions inside <transition>, 
      then the state specified in the @go attribute becomes the new state.

    * Actions relating to parsing and stack manipulation are in the <transition> (transition)
      elements. There are three notional stacks: the entity stack, the stack for subroutines
      actions such as Keyword, which will have a Pop(), and a stack for content particles 
      when parsing content models which has actions such as PopCP().

    * Actions relating to making use of the parsed information are subelements
      of <transition>; feel free to augment them with subelements of your own. Please use another
      namespace for these elements if you are distributing an augmented version of this file. 
      
    * The existing actions relate to the Lark processor; see the source code for that processor
      to reverse engineer their meaning. For example, <HotStart/> is used for a document or entity that
      has no DOCTYPE declaration.

    * Keywords are usually handled specially by a keyword function rather than by making states
      for each letter in the keyword. You will need to provide a mechanism for this. 

    * Characters may be matched according to character class: $S, $NameStart, $NameC, $Hex. These match
      the classes in the XML spec. $. means any valid XML character.

    * In some cases, the @on patterns may not be mutually exclusive. For example, where $. is used.
      In such a case, the prior (and less general) pattern has priority. Apart from that proviso, you are free
      to re-order the <transition> elements within a <state> to tune performance.

    * Transitions relating to checking for non-XML characters (e.g. U+0000) are assumed.

    * This specification only gives the barest information for handling character references, entities, declarations,
      validation, and namespace checking. You will need to provide your own mechanisms for these. 


-->
<!-- 
  Changelog
   April 2006
   * Mark it up
   * Arrange order and headings
   * Add version="1.1" recognition 
   * Add BustedXmlDecl 
-->

<!-- Conformance Notes

   XML 1.0 First Edition
   	- Complies
	- No handling of xml:space, xml:lang
	- Validity errors requiring use of markup declarations (e.g. non space in element content) not handled
	- No productions to handle newline conversions
	- XML declaration parsing not aimed at encoding detection

   Namespaces for XML
	- Handled by extra layer (i.e. by you!)

   XML 1.0 Second Edition
  	- Does not check for entity with single "<" as suggested

   XML 1.0 Third Edition
	- No check required for compatability classes
	- BOM not handled by this grammar: requires a prior layer
	- Note that <FloatingMSE/> ]]> is an error

   XML 1.1 First Edition
   	- Allows version="1.1" 
 	- Changes to name classes and XML chars are non-grammar: your business!


-->

<!--
   Schema:

   automaton
      state
		en?			information for diagnostic (English)
		@name			name of state
		@fallback		default transition for good XML characters
		transition			Transition
			@on		character in input: $ means class member
			@to?		next state. If not specified, some kind of pop() is called 
			@push?		push @to on stack and do thias first. Or call this state
			@do?		pop() means pop stack. popCP() means pop content particle, Keyword() reads keyword
			
			...		children of <transition> are extra info for particular implementations



-->



<!-- definitions - wired into processor			-->
<automaton>
<!-- Start			-->
<state name="Start" fallback="InProlog"><en>in prolog</en>
	<transition on="&lt;" to="LTatStart"> <MarkLt /></transition>
	<transition on="$S" to="InProlog" />
</state>

<state name="LTatStart" fallback="BustedProlog">
	<transition on="?" push="TryXMLD" to="InProlog"> <ColdStart /></transition>
	<transition on="!" to="MDOinProlog" />
	<transition on="$NameStart" to="StagGI"> <HotStart /></transition>
</state>


<!-- ================================================================= 
     Prolog
     ==================================================================
-->
<state name="InProlog" fallback="BustedProlog">
	<transition on="&lt;" to="LTinProlog"> <MarkLt /></transition>
	<transition on="$S" to="InProlog" />
</state>

<state name="AfterDTD" fallback="AfterDTD"><en>after DTD</en>
	<transition on="&lt;" to="LTafterDTD"> <MarkLt /></transition>
	<transition on="$S" to="AfterDTD" />
</state>

<!-- saw < in prolog			-->
<state name="LTinProlog" fallback="LTinProlog"><en>after &lt;</en>
	<transition on="?" push="InPI" to="InProlog"> <ColdStart /></transition>
	<transition on="!" to="MDOinProlog" />
	<transition on="$NameStart" to="StagGI"> <HotStart /></transition>
</state>

<!-- saw < after DTD in prolog			-->
<state name="LTafterDTD" fallback="AfterDTD"> 
	<transition on="?" push="InPI" to="AfterDTD"> <ColdStart /></transition>
	<transition on="!" to="MDOafterDTD" />
	<transition on="$NameStart" to="StagGI"> <HotStart /></transition>
</state>

<!-- saw < in doc			-->
<state name="SawLT" fallback="BustedMarkup">
	<transition on="?" push="InPI" to="InDoc"> <ColdStart /></transition>
	<transition on="!" to="MDO" />
	<transition on="/" to="ETAGO" />
	<transition on="$NameStart" to="StagGI"> <HotStart /></transition>
</state>

<!-- saw < in internal subset			-->
<state name="LTInSubset" fallback="BustedDecl"> 
	<transition on="!" to="MDOInSubset" />
	<transition on="?" push="InPI" to="InSubset"> <ColdStart /></transition>
</state>

<!-- saw <!			-->
<state name="MDOinProlog" fallback="BustedMarkup"><en>after &lt;!</en>
	<transition on="-" push="PComStart" to="InProlog" />
	<transition on="D" do="Keyword(DOCTYPE,1)" to="InDoctype" />
</state>

<state name="MDOafterDTD" fallback="AfterDTD">
	<transition on="-" push="PComStart" to="AfterDTD" />
</state>

<!-- saw <!			-->
<state name="MDO" fallback="BustedMarkup">
	<transition on="-" push="COMStartHalf" to="InDoc" />
	<transition on="[" to="StartCData1" />
</state>

<!-- <! in internal subset			-->
<state name="MDOInSubset" fallback="BustedDecl"><en>after &lt;!</en>
	<transition on="N" do="Keyword(NOTATION,1)" to="NDecAfterKW"/>
	<transition on="E" to="EDec1" />
	<transition on="A" do="Keyword(ATTLIST,1)" to="EndAttlKW" />
	<transition on="-" to="ComInSub1" />
	<transition on="[" to="MSect1" />
</state>

<!-- Special state for matching keywords...			-->
<state name="Keyword" fallback="Start">
	<transition on="$." to="Keyword"> <InKW /></transition>
</state>

<!-- ================================================================= 
     PIs
     ==================================================================
-->
<!-- after <?			-->
<state name="InPI" fallback="BustedMarkup"><en>in PI</en>
	<transition on="$NameStart" to="PI2" />
</state>
<state name="PI2" fallback="BustedMarkup">
	<transition on="$NameC" to="PI2" />
	<transition on="$S" to="PI3"> <EndSave /></transition>
	<transition on="?" to="PICMustHaveGT"> <EndSave /></transition>
</state>
<state name="PI3" fallback="BustedMarkup">
	<transition on="$S" to="PI3" />
	<transition on="$." to="PI4"> <HotStart /></transition>
	<transition on="?" to="PICwantsGT"> <HotStart /></transition>
</state>
<state name="PI4" fallback="BustedMarkup">
	<transition on="?" to="PICwantsGT" />
	<transition on="$." to="PI4" />
</state>

<!-- require > in PIC			-->
<state name="PICMustHaveGT" fallback="BustedMarkup"> 
	<transition on=">" do="Pop()"> <ReportPI /> </transition>
</state>

<!-- want > in PIC			-->
<state name="PICwantsGT" fallback="BustedMarkup">
	<transition on=">" do="Pop()"> <ReportPI /></transition>
	<transition on="?" to="PICwantsGT" />
	<transition on="$." to="PI4" />
</state>

<!-- ================================================================= 
     COMMENT DECLARATIONS
     ==================================================================
-->
<!-- saw <!-			-->
<state name="COMStartHalf" fallback="BustedMarkup"><en>after &lt;!-</en>
	<transition on="-" to="InComment" />
</state>

<!-- Comment in prolog; only difference is we don't start saving after			-->
<state name="PComStart" fallback="BustedMarkup">
	<transition on="-" to="InPComment" />
</state>

<state name="ComInSub1" fallback="BustedDecl"><en>after &lt;!-</en>
	<transition on="-" to="InSubsetCom" />
</state>

<!-- base comment body			-->
<state name="InComment" fallback="InComment"><en>in comment</en>
	<transition on="-" to="DashInComment" />
	<transition on="$." to="InComment" />
</state>

<!-- base comment body			-->
<state name="InPComment" fallback="InComment">
	<transition on="-" to="DashInPComment" />
	<transition on="$." to="InPComment" />
</state>

<!-- saw - in comment			-->
<state name="DashInComment" fallback="InComment"> 
	<transition on="-" to="DDInComment" />
	<transition on="$." to="InComment" />
</state>

<!-- saw - in comment			-->
<state name="DashInPComment" fallback="InComment">
	<transition on="-" to="DDInPComment" />
	<transition on="$." to="InPComment" />
</state>

<!-- saw two hyphens in comment			-->
<state name="DDInComment" fallback="InComment">
	<transition on=">" do="Pop() "><ColdStart /></transition>
</state>

<!-- saw two hyphens in comment			-->
<state name="DDInPComment" fallback="InComment">
	<transition on=">" do="Pop()" />
</state>

<state name="InSubsetCom" fallback="BustedDecl">
	<transition on="-" to="DashInSubsetCom" />
	<transition on="$." to="InSubsetCom" />
</state>

<state name="DashInSubsetCom" fallback="InSubsetCom"> 
	<transition on="-" to="DoubleDashInSubsetCom" />
	<transition on="$." to="InSubsetCom" />
</state>

<state name="DoubleDashInSubsetCom" fallback="InSubsetCom"> 
	<transition on=">" to="InSubset" />
</state>


<!-- ================================================================= 
     CDATA SECTION
     ==================================================================
-->
<!-- saw <![			-->
<state name="StartCData1" fallback="InCData"><en>in &lt;![CDATA[</en>
	<transition on="C" do="Keyword(CDATA,1)" to="AfterCdataKW" />
</state>
<state name="AfterCdataKW" fallback="InCData"> 
	<transition on="[" to="InCData "><ColdStart /></transition>
</state>

<!-- in CDATA section			-->
<state name="InCData" fallback="BustedMarkup">
	<transition on="]" to="EndCData1"> <ReportText /></transition>
	<transition on="$." to="InCData" />
</state>

<!-- ] in CDATA			-->
<state name="EndCData1" fallback="BustedMarkup">
	<transition on="]" to="EndCData2" />
	<transition on="$." to="InCData"> <SaveExtraRSQB /></transition>
</state>

<!-- ]] in CDATA			-->
<state name="EndCData2" fallback="BustedMarkup">
	<transition on="]" to="EndCData2"> <SaveExtraRSQB /> <ReportText /></transition>
	<transition on=">" to="InDoc"> <ReportText /> <ColdStart /></transition>
	<transition on="$." to="InCData"><SaveExtraRSQB2 /></transition>
</state>


<!-- ================================================================= 
     DOCTYPE DECLARATIONS
     ==================================================================
-->

<!-- after <!doctype			-->
<state name="InDoctype" fallback="InDoctype"><en>after &lt;!DOCTYPE</en>
	<transition on="$NameStart" push="GIGrabber" to="SawDTName"> <HotStart /></transition>
	<transition on="$S" to="InDoctype" />
</state>

<!-- General state for grabbing a space-ended GI,saving it, and popping			-->
<state name="GIGrabber" fallback="InDoctype">
	<transition on="$NameC" to="GIGrabber" />
	<transition on="$S" do="Pop() "><EndGI /></transition>
</state>

<!-- after doctype name			-->
<state name="SawDTName" fallback="SawDTName"><en>after DOCTYPE Name</en>
	<transition on="S" push="System1" to="SawDTypeExternalID" />
	<transition on="P" push="Public1" to="SawDTypeExternalID" />
	<transition on="[" to="InSubset"> <ReportDoctype /></transition>
	<transition on=">" to="AfterDTD" />
	<transition on="$S" to="SawDTName" />
</state>

<!-- <!doctype foo p			-->
<state name="Public1" fallback="SawPublic"><en>in PUBLIC</en>
	<transition on="U" do="Keyword(PUBLIC)" to="AfterPublicKW" />
</state>
<state name="AfterPublicKW" fallback="SawPublic"><en>after PUBLIC</en>
	<transition on="$S" to="SawPublic" />
</state>

<state name="SawPublic" fallback="BustedDecl">
	<transition on="%" push="PERef" to="SawPublic"> <MarkPC /> <ColdStart /></transition>
	<transition on="'" push="SQPublic" to="AfterPublic"><ColdStart /></transition>
	<transition on='"' push="DQPublic" to="AfterPublic"> <ColdStart /></transition>
	<transition on="$S" to="SawPublic" />
</state>

<state name="SQPublic" fallback="BustedDecl"><en>in PUBLIC ID</en>
	<transition on="'" do="Pop()"> <EndSave /></transition>
	<transition on="$PubID" to="SQPublic" />
</state>

<state name="DQPublic" fallback="BustedDecl">
	<transition on='"' do="Pop()"> <EndSave /></transition>
	<transition on="$PubID" to="DQPublic" />
</state>

<state name="AfterPublic" fallback="BustedDecl"><en>after PUBLIC ID</en>
	<transition on="$S" to="SawPubID" />
</state>

<state name="SawPubID" fallback="InDoctype">
	<transition on="$S" to="SawPubID" />
	<transition on="%" push="PERef" to="SawPubID"> <MarkPC /> <ColdStart /></transition>
	<transition on="'" push="SQCData" to="SawSystemID"> <ColdStart /></transition>
	<transition on='"' push="DQCData" to="SawSystemID"> <ColdStart /></transition>
</state>

<state name="SawSystemID" fallback="InDoctype"><en>after SYSTEM ID</en>
	<transition on="$." do="Pop()"> <StuffChar /></transition>
</state>

<!-- <!doctype foo S			-->
<state name="System1" fallback="SawSystem"><en>in SYSTEM</en>
	<transition on="Y" do="Keyword(SYSTEM)" to="AfterSystemKW" />
</state>
<state name="AfterSystemKW SawSystem"><en>after SYSTEM</en>
	<transition on="$S" to="SawSystem" />
</state>

<!-- <!doctype foo system			-->
<state name="SawSystem" fallback="BustedDecl">
	<transition on="%" push="PERef" to="SawSystem"> <MarkPC /> <ColdStart /></transition>
	<transition on="'" push="SQCData" to="SawSystemID"> <ColdStart /></transition>
	<transition on='"' push="DQCData" to="SawSystemID"> <ColdStart /></transition>
	<transition on="$S" to="SawSystem" />
</state>

<!--			-->
<state name="SQCData" fallback="BustedMarkup">
	<transition on="'" do="Pop()"> <EndSave /></transition>
	<transition on="$." to="SQCData" />
</state>

<!--			-->
<state name="DQCData" fallback="BustedMarkup">
	<transition on='"' do="Pop()"> <EndSave /></transition>
	<transition on="$." to="DQCData" />
</state>

<!-- <!doctype foo system "whatever"			-->
<state name="SawDTypeExternalID" fallback="InDoctype"><en>after SYSTEM ID</en>
	<transition on=">" to="AfterDTD"> <ReportDoctype /></transition>
	<transition on="[" to="InSubset"> <ReportDoctype /></transition>
	<transition on="$S" to="SawDTypeExternalID" />
</state>

<!-- saw [ for internal subset			-->
<state name="InSubset" fallback="InSubset"><en>in internal subset</en>
	<transition on="&lt;" to="LTInSubset"> <MarkLt /></transition>
	<transition on="%" push="PERef" to="InSubset"> <MarkPcAtTopLevel /> <ColdStart /></transition>
	<transition on="]" to="RSBInSubset" />
	<transition on="$S" to="InSubset" />
</state>

<state name="RSBInSubset" fallback="InSubset">
	<transition on="]" to="RSB2InSubset" />
	<transition on=">" to="AfterDTD" />
	<transition on="$S" to="AfterSubset" />
</state>
<state name="RSB2InSubset" fallback="InSubset">
	<transition on=">" to="InSubset"> <LeaveMarkedSect /></transition>
</state>



<!--" to="After subset			-->
<state name="AfterSubset" fallback="InDoc"><en>after internal subset</en>
	<transition on=">" to="AfterDTD" />
	<transition on="$S" to="AfterSubset" />
</state>


<!-- ================================================================= 
     PE REFERENCE DECLARATIONS
     ==================================================================
-->

<!-- in PE Ref			-->
<state name="PERef" fallback="InSubset"><en>in PE reference</en>
	<transition on="$NameStart" to="PERef2" />
</state>

<state name="PERef2" fallback="InSubset">
	<transition on="$NameC" to="PERef2" />
	<transition on=";" do="Pop()"> <ReportReference /> </transition>
</state>

<!-- ================================================================= 
     NOTATION DECLARATIONS
     ==================================================================
-->

<!-- <!NOTATION			-->
<state name="NDecAfterKW" fallback="BustedDecl"><en>after &lt;!NOTATION</en>
	<transition on="$S" to="NDecGotKW" />
</state>

<!-- <!NOTATION" to=" need name			-->
<state name="NDecGotKW" fallback="BustedDecl"> 
	<transition on="$S" to="NDecGotKW" />
	<transition on="$NameStart" to="NDecReadName"> <HotStart /></transition>
</state>

<!-- in <!NOTATION name			-->
<state name="NDecReadName" fallback="BustedDecl"> 
	<transition on="$NameC" to="NDecReadName" />
	<transition on="$S" to="NDecGotName"> <EndSave /></transition>
</state>

<!-- after name in <!NOTATION			-->
<state name="NDecGotName" fallback="BustedDecl">
	<transition on="$S" to="NDecGotName" />
	<transition on="S" do="Keyword(SYSTEM,1)" to="NDecAfterSystem"  />
	<transition on="P" do="Keyword(PUBLIC,1)" to="NDecAfterPublic"  />
</state>

<!-- <!NOTATION whateever PUBLIC			-->
<state name="NDecAfterPublic" fallback="BustedDecl"><en>after PUBLIC</en>
	<transition on="$S" to="NDecGotPublic" />
</state>
<state name="NDecGotPublic" fallback="BustedDecl">
	<transition on="'" push="SQPublic" to="NDecSawPubID"><ColdStart /></transition>
	<transition on='"' push="DQPublic" to="NDecSawPubID"> <ColdStart /></transition>
</state>
<state name="NDecSawPubID" fallback="BustedDecl"><en>after PUBLIC ID</en>
	<transition on=">" to="InSubset"> <DeclareNotation /></transition>
</state>
	<transition on="$S" to="NDecGotPubID" />
<state name="NDecGotPubID" fallback="BustedDecl">
	<transition on=">" to="InSubset"> <DeclareNotation /></transition>
	<transition on="'" push="SQCData" to="NDecSawSysID"> <ColdStart /></transition>
	<transition on='"' push="DQCData" to="NDecSawSysID"> <ColdStart /></transition>
</state>

<!-- <!NOTATION whatever SYSTEM			-->
<state name="NDecAfterSystem" fallback="BustedDecl"><en>after SYSTEM</en>
	<transition on="$S" to="NDecGotSystem"> <EndSave /></transition>
</state>

<state name="NDecGotSystem" fallback="BustedDecl">
	<transition on="'" push="SQCData" to="NDecSawSysID"> <ColdStart /></transition>
	<transition on='"' push="DQCData" to="NDecSawSysID"> <ColdStart /></transition>
</state>

<state name="NDecSawSysID" fallback="BustedDecl"><en>after external ID</en>
	<transition on="$S" to="NDecAllDone" />
	<transition on=">" to="InSubset"> <DeclareNotation /></transition>
</state>
<state name="NDecAllDone" fallback="BustedDecl">
	<transition on=">" to="InSubset"> <DeclareNotation /></transition>
</state>

<!-- ================================================================= 
     MARKED SECTION DECLARATIONS
     ==================================================================
-->


<!-- Trying for <![INCLUDE/IGNORE			-->
<state name="MSect1" fallback="BustedDecl"><en>after &lt;![</en>
	<transition on="$S" to="MSect1" />
	<transition on="%" push="PERef" to="MSect1"> <MarkPC /> <ColdStart /></transition>
	<transition on="I" to="MSectI" />
</state>

<state name="MSectI" fallback="BustedDecl"><en>after &lt;[I</en>
	<transition on="N" do="Keyword(INCLUDE,2)" to="MSectINCLUDE"  />
	<transition on="G" do="Keyword(IGNORE,2)" to="MSectIGNORE"  />
</state>

<state name="MSectINCLUDE" fallback="BustedDecl"><en>after &lt;![INCLUDE</en>
	<transition on="$S" to="MSectINCLUDE" />
	<transition on="[" to="InSubset"> <EnterIncludedMS /></transition>
</state>

<state name="MSectIGNORE" fallback="BustedDecl"><en>after &lt;![IGNORE</en>
	<transition on="$S" to="MSectIGNORE" />
	<transition on="[" to="InSubset"> <EnterIgnoredMS /></transition>
</state>


<!-- ================================================================= 
     ATTLIST DECLARATIONS
     ==================================================================
-->

<state name="EndAttlKW" fallback="BustedDecl"><en>after &lt;!ATTLIST</en>
	<transition on="$S" to="AfterAttlKW" />
</state>

<!-- after <!attlist			-->
<state name="AfterAttlKW" fallback="BustedDecl">
	<transition on="$S" to="AfterAttlKW" />
	<transition on="%" push="PERef" to="AfterAttlKW"> <MarkPC /> <ColdStart /></transition>
	<transition on="$NameStart" to="InAttlGI "><HotStart /></transition>
</state>

<!-- in attlist GI			-->
<state name="InAttlGI" fallback="BustedDecl"><en>in element type in &lt;!ATTLIST</en>
	<transition on="$NameC" to="InAttlGI" />
	<transition on="$S" to="InAttlist"> <EndGI /></transition>
<!-- 	<transition on=">" to="InSubset"> <EndGI /> <ReportAttDecl /> <ReportAttlist /></transition>
</state>			-->

<!-- Base Attlist state			-->
<state name="InAttlist" fallback="BustedDecl"><en>in &lt;!ATTLIST</en>
	<transition on=">" to="InSubset"> <ReportAttlist /></transition>
	<transition on="%" push="PERef" to="InAttlist"> <MarkPC /> <ColdStart /></transition>
	<transition on="$NameStart" to="InAttName"> <HotStart /></transition>
	<transition on="$S" to="InAttlist" />
</state>

<!-- in attr name			-->
<state name="InAttName" fallback="BustedDecl"><en>in attribute name</en>
	<transition on="$NameC" to="InAttName" />
	<transition on="$S" to="AfterAttName"> <EndAttribute /></transition>
</state>

<!-- after attr name			-->
<!--  We don't really care about the type, we'll just scoop it up as a  
string			-->
<state name="AfterAttName" fallback="BustedDecl"><en>after attribute name</en>
	<transition on="(" to="StartTokenList"> <HotStart /></transition>
	<transition on="C" do="Keyword(CDATA,1)" to="AttrTypeCDATA" > <HotStart /></transition>
	<transition on="E" do="AttrTypeE"> <HotStart /></transition>
	<transition on="I" to="AttrTypeI"> <HotStart /></transition>
	<transition on="N" to="AttrTypeN"> <HotStart /></transition>
	<transition on="%" push="PERef" to="AfterAttName"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="AfterAttName" />
</state>

<!-- Token list			-->
<state name="StartTokenList" fallback="BustedDecl"><en>in tokenized attribute value</en>
	<transition on="%" push="PERef" to="StartTokenList"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="StartTokenList" />
	<transition on="$NameC" to="FirstToken" />
</state>

<state name="FirstToken" fallback="BustedDecl">
	<transition on="$NameC" to="FirstToken" />
	<transition on="$S" to="AfterToken" />
	<transition on="|" to="BeforeToken" />
	<transition on=")" to="AfterTokList"> <EndSave /></transition>
</state>

<state name="AfterToken" fallback="BustedDecl">
	<transition on="%" push="PERef" to="AfterToken"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="AfterToken" />
	<transition on="|" to="BeforeToken" />
	<transition on=")" to="AfterTokList"> <EndSave /></transition>
</state>

<state name="BeforeToken" fallback="BustedDecl">
	<transition on="%" push="PERef" to="BeforeToken"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="BeforeToken" />
	<transition on="$NameC" to="InToken" />
</state>

<state name="InToken" fallback="BustedDecl">
	<transition on="$NameC" to="InToken" />
	<transition on="$S" to="AfterToken" />
	<transition on="|" to="BeforeToken" />
	<transition on=")" to="AfterTokList "><EndSave /></transition>
</state>

<state name="AfterTokList" fallback="BustedDecl">
	<transition on="$S" to="AfterAttrType" />
</state>

<state name="AttrTypeCDATA" fallback="BustedDecl"><en>after CDATA</en>
	<transition on="$S" to="AfterAttrType"> <EndSave /></transition>
</state>

<state name="AttrTypeE" fallback="BustedDecl"><en>in ENTIT(Y,IES)</en>
	<transition on="N" to="AttrTypeEn" />
</state>
<state name="AttrTypeEn" fallback="BustedDecl">
	<transition on="T" to="AttrTypeEnt" />
</state>
<state name="AttrTypeEnt" fallback="BustedDecl">
	<transition on="I" to="AttrTypeEnti" />
</state>
<state name="AttrTypeEnti" fallback="BustedDecl">
	<transition on="T" to="AttrTypeEntit" />
</state>
<state name="AttrTypeEntit" fallback="BustedDecl">
	<transition on="I" to="AttrTypeEntiti" />
	<transition on="Y" to="AttrTypeEntity" />
</state>
<state name="AttrTypeEntity" fallback="BustedDecl">
	<transition on="$S" to="AfterAttrType"> <EndSave /></transition>
</state>
<state name="AttrTypeEntiti" fallback="BustedDecl">
	<transition on="E " to="AttrTypeEntitie" />
</state>
<state name="AttrTypeEntitie" fallback="BustedDecl">
	<transition on="S" to="AttrTypeEntities" />
</state>
<state name="AttrTypeEntities" fallback="BustedDecl">
	<transition on="$S" to="AfterAttrType"> <EndSave /></transition>
</state>

<state name="AttrTypeI" fallback="BustedDecl"><en>in ID(REF(S))</en>
	<transition on="D" to="AttrTypeId" />
</state>
<state name="AttrTypeId" fallback="BustedDecl">
	<transition on="$S" to="AfterAttrType "><EndSave /></transition>
	<transition on="R" to="AttrTypeIdr" />
</state>
<state name="AttrTypeIdr" fallback="BustedDecl">
	<transition on="E" to="AttrTypeIdre" />
</state>
<state name="AttrTypeIdre" fallback="BustedDecl">
	<transition on="F" to="AttrTypeIdref" />
</state>
<state name="AttrTypeIdref" fallback="BustedDecl">
	<transition on="$S" to="AfterAttrType"> <EndSave /></transition>
	<transition on="S" to="AttrTypeIdrefs" />
</state>
<state name="AttrTypeIdrefs" fallback="BustedDecl">
	<transition on="$S" to="AfterAttrType"> <EndSave /></transition>
</state>

<state name="AttrTypeN" fallback="BustedDecl"><en>in type keyword</en>
	<transition on="O" do="Keyword(NOTATION,2)" to="AttrTypeNotation" />
	<transition on="M" do="Keyword(NMTOKEN,2)" to="AttrTypeNmtoken"  />
</state>

<state name="AttrTypeNotation" fallback="BustedDecl"><en>after NOTATION</en>
	<transition on="$S" to="BeforeNotList" />
</state>

<!-- notation list			-->
<state name="BeforeNotList" fallback="BustedDecl">
	<transition on="%" push="PERef" to="BeforeNotList"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="BeforeNotList" />
	<transition on="(" to="StartNotList" />
</state>

<state name="StartNotList" fallback="BustedDecl"><en>in NOTATION list</en>
	<transition on="%" push="PERef" to="StartNotList "><MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="StartNotList" />
	<transition on="$NameStart" to="FirstNotName" />
</state>

<state name="FirstNotName" fallback="BustedDecl">
	<transition on="$NameC" to="FirstNotName" />
	<transition on="$S" to="AfterNotName" />
	<transition on="|" to="BeforeNotName" />
	<transition on=")" to="AfterAttrType"> <EndSave /></transition>
</state>

<state name="AfterNotName" fallback="BustedDecl">
	<transition on="%" push="PERef" to="AfterNotName"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="AfterNotName" />
	<transition on="|" to="BeforeNotName" />
	<transition on=")" to="AfterAttrType "><EndSave /></transition>
</state>

<state name="BeforeNotName" fallback="BustedDecl">
	<transition on="%" push="PERef" to="BeforeNotName"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="BeforeNotName" />
	<transition on="$NameStart" to="InNotName" />
</state>

<state name="InNotName" fallback="BustedDecl">
	<transition on="$NameC" to="InNotName" />
	<transition on="$S" to="AfterNotName" />
	<transition on="|" to="BeforeNotName" />
	<transition on=")" to="AfterAttrType "><EndSave /></transition>
</state>

<state name="AttrTypeNmtoken" fallback="BustedDecl"><en>after NMTOKEN</en>
	<transition on="$S" to="AfterAttrType"> <EndSave /></transition>
	<transition on="S" to="AttrTypeNmtokens" />
</state>
<state name="AttrTypeNmtokens" fallback="BustedDecl">
	<transition on="$S" to="AfterAttrType"> <EndSave /></transition>
</state>

<!--after attrtype			-->
<!-- NB" to=" may need ColdStart on '#' transition  -->
<state name="AfterAttrType" fallback="BustedDecl"><en>after attribute type</en>
	<transition on="%" push="PERef" to="AfterAttrType"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="AfterAttrType" />
	<transition on="#" to="AttrDefHash"> <ColdStart /></transition>
	<transition on='"' push="DQADef" to="InAttlist"> <ColdStart /> <EnterAttrVal /></transition>
	<transition on="'" push="SQADef" to="InAttlist"> <ColdStart /> <EnterAttrVal /></transition>
</state>

<state name="AttrDefHash" fallback="BustedDecl"><en>in attribute default</en>
	<transition on="R" do="Keyword(REQUIRED,1)" to="AttrDefRequired"  />
	<transition on="I" do="Keyword(IMPLIED,1)" to="AttrDefImplied"  />
	<transition on="F" do="Keyword(FIXED,1)" to="AttrDefFixed"  />
</state>

<state name="AttrDefRequired" fallback="BustedDecl"><en>after #REQUIRED</en>
	<transition on="$S" to="InAttlist"> <ReportDefKW /><ReportAttDecl /></transition>
	<transition on=">" to="InSubset"><ReportDefKW /> <ReportAttDecl /> <ReportAttlist /></transition>
</state>

<state name="AttrDefImplied" fallback="BustedDecl"><en>after #IMPLIED</en>
	<transition on="$S" to="InAttlist"><ReportDefKW /><ReportAttDecl /></transition>
	<transition on=">" to="InSubset"><ReportDefKW /><ReportAttDecl /> <ReportAttlist /></transition>
</state>

<state name="AttrDefFixed" fallback="BustedDecl"><en>after #FIXED</en>
	<transition on="$S" to="AfterFixed"> <ReportDefKW /></transition>
</state>

<state name="AfterFixed" fallback="BustedDecl">
	<transition on="%" push="PERef" to="AfterFixed"><MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="AfterFixed" />
	<transition on="'" push="SQADef" to="InAttlist"> <ColdStart /> <EnterAttrVal /></transition>
	<transition on='"' push="DQADef" to="InAttlist"> <ColdStart /> <EnterAttrVal /></transition>

</state>
<!-- ================================================================= 
     ELEMENT DECLARATIONS
     ==================================================================
-->

<!-- saw <!e in subset			-->
<state name="EDec1" fallback="BustedDecl"><en>after &lt;!E</en>
	<transition on="N" do="Keyword(ENTITY,2)" to="AfterEntityKW"  />
	<transition on="L" do="Keyword(ELEMENT,2)" to="AfterElementKW"  />
</state>
</state>



<!-- DEBUG: 1st line for dumb processing, 2nd 2 for real element parsing			-->
<state name="AfterElementKW" fallback="BustedDecl"><en>after &lt;!ELEMENT</en>
	<transition on="$S" to="InElDec" />
</state>

<!--" to="After <!element			-->
<state name="InElDec" fallback="BustedDecl">
	<transition on="$S" to="InElDec" />
	<transition on="%" push="PERef" to="InElDec"> <MarkPC /> <ColdStart /></transition>
	<transition on="$NameStart" push="GIGrabber" to="ElDecAfterGI"> <HotStart /></transition>
</state>

<state name="ElDecAfterGI" fallback="BustedDecl"><en>after element type</en>
	<transition on="$S" to="ElDecAfterGI" />
	<transition on="%" push="PERef" to="ElDecAfterGI"> <MarkPC /> <ColdStart /></transition>
	<transition on="(" to="ElDecFirstPar" />
	<transition on="E" do="Keyword(EMPTY,1)" to="AfterEMPTY" />
	<transition on="A" do="Keyword(ANY,1)" to="AfterANY" />
</state>

<state name="AfterEMPTY" fallback="BustedDecl"><en>after EMPTY</en>
	<transition on="$S" to="AfterEMPTY" />
	<transition on=">" to="InSubset"> <DoEMPTY /></transition>
<state name="AfterANY" fallback="BustedDecl"><en>after ANY</en>
	<transition on="$S" to="AfterANY" />
	<transition on=">" to="InSubset"> <DoANY /></transition>
</state>

<!-- <!ELEMENT (			-->
<state name="ElDecFirstPar" fallback="BustedDecl"><en>after &lt;!ELEMENT (</en>
	<transition on="$S" to="ElDecFirstPar" />
	<transition on="%" push="PERef" to="ElDecFirstPar"> <MarkPC /> <ColdStart /></transition>
	<transition on="#" do="Keyword(PCDATA, 0)" to="AfterPCDATA"  />
	<transition on="(" push="CPStart" to="AfterFirst"> <StartCM /> <StartCP /></transition>
	<transition on="$NameC" to="FirstType"> <HotStart /> <StartCM /></transition>
</state>

<!-- Done element content" to=" might be a trailing repeat-count			-->
<state name="DoneElementContent" fallback="BustedDecl"><en>after element declaration</en>
	<transition on="*" to="ReallyDoneEC"> <MarkRep /></transition>
	<transition on="+" to="ReallyDoneEC"> <MarkRep /></transition>
	<transition on="?" to="ReallyDoneEC"> <MarkRep /></transition>
	<transition on="$S" to="ReallyDoneEC" />
	<transition on=">" to="InSubset" />
</state>

<!-- Really done element content, no repeat count			-->
<state name="ReallyDoneEC" fallback="BustedDecl"> 
	<transition on="%" push="PERef" to="ReallyDoneEC"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="ReallyDoneEC" />
	<transition on=">" to="InSubset" />
</state>

<!-- Saw ( of a (non-top-level) CP			-->
<state name="CPStart" fallback="BustedMarkup"><en>start of content particle</en>
	<transition on="%" push="PERef" to="CPStart"> <MarkPC /> <ColdStart /></transition>
	<transition on="(" push="CPStart" to="AfterFirst"> <StartCP /></transition>
	<transition on="$S" to="CPStart" />
	<transition on="$NameC" to="FirstType"> <HotStart /></transition>
</state>

<!-- gather lead-off child type			-->
<state name="FirstType" fallback="BustedDecl">
	<transition on="$NameC" to="FirstType" />
	<transition on="$S" to="DoneFirst"> <EndGI /></transition>
	<transition on="*" to="DoneFirst"> <EndGI /> <MarkRep /></transition>
	<transition on="?" to="DoneFirst"> <EndGI /> <MarkRep /></transition>
	<transition on="+" to="DoneFirst"> <EndGI /> <MarkRep /></transition>
	<transition on=")" do="PopCP()"> <EndGI /></transition>
	<transition on="," to="SeqNeedNext"> <EndGI /> <MarkConnector /></transition>
	<transition on="|" to="ChoiceNeedNext"> <EndGI /> <MarkConnector /></transition>
</state>

<!-- have seen first child () of content particle			-->
<state name="AfterFirst" fallback="BustedMarkup"><en>after first member of content particle</en>
	<transition on="$S" to="DoneFirst" />
	<transition on="," to="SeqNeedNext"> <MarkConnector /></transition>
	<transition on="|" to="ChoiceNeedNext"> <MarkConnector /></transition>
	<transition on="*" to="DoneFirst"> <MarkRep /></transition>
	<transition on="+" to="DoneFirst"> <MarkRep /></transition>
	<transition on="?" to="DoneFirst"> <MarkRep /></transition>
	<transition on=")" do="PopCP()" />
</state>

<!-- finshed with first member of cp			-->
<state name="DoneFirst" fallback="BustedMarkup">
	<transition on="%" push="PERef" to="DoneFirst"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="DoneFirst" />
	<transition on="," to="SeqNeedNext"> <MarkConnector /></transition>
	<transition on="|" to="ChoiceNeedNext"> <MarkConnector /></transition>
	<transition on=")" do="PopCP()" />
</state>

<!-- after connector in a seq			-->
<state name="SeqNeedNext" fallback="BustedMarkup"><en>after ,</en>
	<transition on="%" push="PERef" to="SeqNeedNext"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="SeqNeedNext" />
	<transition on="$NameStart" to="SeqType"> <HotStart /></transition>
	<transition on="(" push="CPStart" to="AfterSeqMember"> <StartCP /></transition>
</state>

<!-- child type in a sequence			-->
<state name="SeqType" fallback="BustedMarkup">
	<transition on="$NameC" to="SeqType" />
	<transition on="$S" to="DoneSeqMember"> <EndGI /></transition>
	<transition on="*" to="DoneSeqMember"> <EndGI /> <MarkRep /></transition>
	<transition on="+" to="DoneSeqMember"> <EndGI /> <MarkRep /></transition>
	<transition on="?" to="DoneSeqMember"> <EndGI /> <MarkRep /></transition>
	<transition on=")" do="PopCP()"> <EndGI /></transition>
	<transition on="," to="SeqNeedNext"> <EndGI /></transition>
</state>

<!-- after () child in a seq			-->
<state name="AfterSeqMember" fallback="BustedMarkup"><en>after )</en>
	<transition on="$S" to="DoneSeqMember" />
	<transition on="," to="SeqNeedNext" />
	<transition on="*" to="DoneSeqMember"> <MarkRep /></transition>
	<transition on="?" to="DoneSeqMember"> <MarkRep /></transition>
	<transition on="+" to="DoneSeqMember"> <MarkRep /></transition>
	<transition on=")" do="PopCP()" />
</state>

<!-- all done with member of a seq			-->
<state name="DoneSeqMember" fallback="BustedMarkup"><en>after member of sequence</en>
	<transition on="%" push="PERef" to="DoneSeqMember"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="DoneSeqMember" />
	<transition on="," to="SeqNeedNext" />
	<transition on=")" to="PopCP()" />
</state>

<!-- after connector in a choice			-->
<state name="ChoiceNeedNext" fallback="BustedMarkup"><en>after |</en>
	<transition on="%" push="PERef" to="ChoiceNeedNext"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="ChoiceNeedNext" />
	<transition on="$NameStart" to="ChoiceType"> <HotStart /></transition>
	<transition on="(" push="CPStart" to="AfterChoiceMember"> <StartCP /></transition>
</state>

<!-- child type in a choice			-->
<state name="ChoiceType" fallback="BustedMarkup"> 
	<transition on="$NameC" to="ChoiceType" />
	<transition on="$S" to="DoneChoiceMember"> <EndGI /></transition>
	<transition on="*" to="DoneChoiceMember"> <EndGI /> <MarkRep /></transition>
	<transition on="+" to="DoneChoiceMember"> <EndGI /> <MarkRep /></transition>
	<transition on="?" to="DoneChoiceMember"> <EndGI /> <MarkRep /></transition>
	<transition on=")" do="PopCP()"> <EndGI /></transition>
	<transition on="|" to="ChoiceNeedNext"> <EndGI /></transition>
</state>

<!-- after () child in a Choice			-->
<state name="AfterChoiceMember" fallback="BustedMarkup"><en>after )</en>
	<transition on="$S" to="DoneChoiceMember" />
	<transition on="|" to="ChoiceNeedNext" />
	<transition on="*" to="DoneChoiceMember"> <MarkRep /></transition>
	<transition on="+" to="DoneChoiceMember"> <MarkRep /></transition>
	<transition on="?" to="DoneChoiceMember"> <MarkRep /></transition>
	<transition on=")" do="PopCP()" />
</state>

<!-- all done with member of a choice			-->
<state name="DoneChoiceMember" fallback="BustedMarkup"><en>after member of choice</en>
	<transition on="%" push="PERef" to="DoneChoiceMember"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="DoneChoiceMember" />
	<transition on="|" to="ChoiceNeedNext" />
	<transition on=")" do="PopCP()" />
</state>

<!-- Saw (#PCDATA			-->
<state name="AfterPCDATA" fallback="BustedDecl"><en>after #PCDATA</en>
	<transition on="%" push="PERef" to="AfterPCDATA"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="AfterPCDATA" />
	<transition on=")" to="SimpleMixed" />
	<transition on="|" to="MixedNeedGI" />
</state>

<!-- Saw (#PCDATA|			-->
<state name="MixedNeedGI" fallback="BustedDecl"><en>after (#PCDATA|</en>
	<transition on="$S" to="MixedNeedGI" />
	<transition on="%" push="PERef" to="MixedNeedGI"> <MarkPC /> <ColdStart /></transition>
	<transition on="$NameStart" to="MixedGI"> <HotStart /></transition>
</state>

<state name="MixedGI" fallback="BustedDecl"><en>in element type</en>
	<transition on="$NameC" to="MixedGI" />
	<transition on="$S" to="MixedAfterGI"> <EndGI /></transition>
	<transition on="|" to="MixedNeedGI"> <EndGI /></transition>
	<transition on=")" to="AfterMixed"> <EndGI /></transition>
</state>

<state name="MixedAfterGI" fallback="BustedDecl"><en>after element type</en>
	<transition on="$S" to="MixedAfterGI" />
	<transition on="%" push="PERef" to="MixedAfterGI"> <MarkPC /> <ColdStart /></transition>
	<transition on="|" to="MixedNeedGI" />
	<transition on=")" to="AfterMixed" />
</state>

<state name="AfterMixed" fallback="BustedDecl"><en>after mixed declaration</en>
	<transition on="*" to="DoneMixed"> <DoMixed /></transition>
</state>

<state name="DoneMixed" fallback="BustedDecl">
	<transition on="%" push="PERef" to="DoneMixed"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="DoneMixed" />
	<transition on=">" to="InSubset" />
</state>

<!-- Saw (#PCDATA)			-->
<state name="SimpleMixed" fallback="BustedDecl"><en>after (#PCDATA)</en>
	<transition on="*" to="DoneMixed"> <DoMixed /></transition>
	<transition on="$S" to="DoneMixed"> <DoMixed /></transition>
	<transition on=">" to="InSubset"> <DoMixed /></transition>
</state>



<!-- ================================================================= 
     ENTITY DECLARATIONS
     ==================================================================
-->

<state name="AfterEntityKW" fallback="BustedDecl"><en>after &lt;!ENTITY</en>
	<transition on="$S" to="AfterEntDec" />
</state>

<!-- After <!entity			-->
<state name="AfterEntDec" fallback="BustedDecl">
	<transition on="%" to="PCAfterEntDec" />
	<transition on="$NameStart" to="InEntName"> <HotStart /></transition>
	<transition on="$S" to="AfterEntDec" />
</state>

<!-- Percent sign after <!ENTITY - maybe PERef, maybe PE Decl signal			-->
<state name="PCAfterEntDec" fallback="BustedDecl"><en>after &lt;!ENTITY %</en>
	<transition on="$NameStart" push="PERef" to="AfterEntDec"> <MarkPC /> <HotStart /></transition>
	<transition on="$S" to="BeforeEntName"> <SignalPE /></transition>
</state>

<state name="BeforeEntName" fallback="BustedDecl">
	<transition on="%" push="PERef" to="BeforeEntName"> <MarkPC /> <ColdStart /></transition>
	<transition on="$S" to="BeforeEntName" />
	<transition on="$NameStart" to="InEntName"> <HotStart /></transition>
</state>

<!-- InEntity Name			-->
<state name="InEntName" fallback="BustedDecl"><en>in entity name</en>
	<transition on="$NameC" to="InEntName" />
	<transition on="$S" to="AfterEntName"> <EndSave /></transition>
</state>

<!-- AfterEntity Name			-->
<state name="AfterEntName" fallback="BustedDecl"><en>after entity name</en>
	<transition on="%" push="PERef" to="AfterEntName"> <MarkPC /> <ColdStart /></transition>
	<transition on="'" push="SQEntVal" to="AfterEVal"> <ColdStart /> <EnterEntVal /></transition>
	<transition on='"' push="DQEntVal" to="AfterEVal"> <ColdStart /> <EnterEntVal /></transition>
	<transition on="S" push="System1" to="SawEntExternalID" />
	<transition on="P" push="Public1" to="SawEntExternalID" />
	<transition on="$S" to="AfterEntName" />
</state>

<state name="DQEntVal" fallback="BustedDecl"><en>internal entity declaration</en>
	<transition on='"' do="Pop()"> <EndSave /></transition>
	<transition on="%" push="PERef" to="DQEntVal"> <MarkPC /> <ColdStart /></transition>
	<transition on="&amp;" push="SawAmp" to="DQEntVal"> <MarkAmp /></transition>
	<transition on="$." to="DQEntVal"/>
</state>

<state name="SQEntVal" fallback="BustedDecl">
	<transition on="'" do="Pop()"> <EndSave /></transition>
	<transition on="%" push="PERef" to="SQEntVal"> <MarkPC /> <ColdStart /></transition>
	<transition on="&amp;" push="SawAmp" to="SQEntVal"> <MarkAmp /></transition>
	<transition on="$." to="SQEntVal" />
</state>

<!--AfterEVal			-->
<state name="AfterEVal" fallback="BustedDecl"><en>after enitity value</en>
	<transition on="%" push="PERef" to="AfterEVal"> <MarkPC /> <ColdStart /></transition>
	<transition on=">" to="InSubset"> <ReportInternalEntity /></transition>
	<transition on="$S" to="AfterEVal" />
</state>

<!-- <!entity foo system "bar"			-->
<state name="SawEntExternalID" fallback="BustedDecl"><en>after entity SYSTEM ID</en>
	<transition on="$S" to="DoneEntExternalID" />
	<transition on=">" to="InSubset"> <ReportSystemTextEntity /></transition>
</state>

<state name="DoneEntExternalID" fallback="BustedDecl">
	<transition on="%" push="PERef" to="DoneEntExternalID"> <MarkPC /> <ColdStart /></transition>
	<transition on="N" do="Keyword(NDATA,1)" to="AfterNDATA" />
	<transition on=">" to="InSubset"> <ReportSystemTextEntity /></transition>
	<transition on="$S" to="DoneEntExternalID" />
</state>

<!-- NDATA			-->
<state name="AfterNDATA" fallback="BustedDecl"><en>after NDATA</en>
	<transition on="$S" to="SawNDATA" />
</state>

<!-- Saw NDATA			-->
<state name="SawNDATA" fallback="BustedDecl">
	<transition on="%" push="PERef" to="SawNDATA"> <MarkPC /> <ColdStart /></transition>
	<transition on="$NameStart" to="InNotationName"> <HotStart /></transition>
	<transition on="$S" to="SawNDATA" />
</state>

<!-- Reading notation name after NDATA			-->
<state name="InNotationName" fallback="BustedDecl">
	<transition on="$NameC" to="InNotationName" />
	<transition on="$S" to="AfterNDATADecl" />
	<transition on=">" to="InSubset"> <EndSave /> <DeclareUnparsed /></transition>
</state>

<state name="AfterNDATADecl" fallback="BustedDecl"><en>after NDATA declaration</en>
	<transition on="$S" to="AfterNDATADecl" />
	<transition on=">" to="InSubset"> <EndSave /> <DeclareUnparsed /></transition>
</state>


<!-- ================================================================= 
     INSTANCE
     ==================================================================
-->

<!-- saw </			-->
<state name="ETAGO" fallback="BustedMarkup"><en>after &amp;/</en>
	<transition on="$NameStart" to="EtagGI"> <HotStart /></transition>
</state>

<!--9 GI in end-tag			-->
<state name="EtagGI" fallback="BustedMarkup"><en>in end-tag</en>
	<transition on=">" to="InDoc"> <EndGI /> <ReportETag /></transition>
	<transition on="$NameC" to="EtagGI" />
	<transition on="$S" to="SawEtagGI"> <EndGI /></transition>
</state>

<!--10 S after GI in end-tag			-->
<state name="SawEtagGI" fallback="BustedMarkup">
	<transition on=">" to="InDoc"> <ReportETag /></transition>
	<transition on="$S" to="SawEtagGI" />
</state>

<!-- in Start tag GI			-->
<state name="StagGI" fallback="BustedMarkup"><en>in element type</en>
	<transition on="$NameC" to="StagGI" />
	<transition on="$S" to="InStag"> <EndGI /></transition>
	<transition on=">" to="InDoc"> <EndGI /> <ReportSTag /></transition>
	<transition on="/" to="EmptyClose"> <EndGI /></transition>
</state>

<state name="EmptyClose" fallback="BustedMarkup"><en>after / in start-tag</en>
	<transition on=">" to="InDoc"> <ReportEmpty /></transition>
</state>

<!-- in tag after gi			-->
<state name="InStag" fallback="BustedMarkup"><en>in start-tag</en>
	<transition on=">" to="InDoc"> <ReportSTag /></transition>
	<transition on="/" to="EmptyClose" />
	<transition on="$S" to="InStag" />
	<transition on="$NameStart" to="AttrName"> <HotStart /></transition>
</state>

<!-- Attr name			-->
<state name="AttrName" fallback="BustedMarkup">
	<transition on="=" to="Eq2"> <EndAttribute /></transition>
	<transition on="$NameC" to="AttrName" />
	<transition on="$S" to="Eq1"> <EndAttribute /></transition>
</state>

<!-- ' ' before =			-->
<state name="Eq1" fallback="BustedMarkup">
	<transition on="=" to="Eq2" />
	<transition on="$S" to="Eq1" />
</state>

<!-- = in Eq			-->
<state name="Eq2" fallback="BustedMarkup"><en>after AttrName= in start-tag</en>
	<transition on="'" push="SQAVal" to="InStag"> <ColdStart /> <EnterAttrVal /></transition>
	<transition on='"' push="DQAVal" to="InStag"> <ColdStart /> <EnterAttrVal /></transition>
	<transition on="$S" to="Eq2" />
</state>

<!-- in AttrValue" to=" '-delimited			-->
<state name="SQAVal" fallback="BustedMarkup"> 
	<transition on="&lt;" to="SQAVal"> <MarkLt /></transition>
	<transition on="'" do="Pop()"> <EndAttrVal /></transition>
	<transition on="&amp;" push="SawAmp" to="SQAVal"> <ReportText /> <MarkAmp /> <ColdStart /></transition>
	<transition on="$." to="SQAVal" />
</state>

<!-- in Default AttrValue, '-delimited			-->
<state name="SQADef" fallback="BustedDecl">
	<transition on="'" do="Pop()"> <EndAttrVal /> <ReportAttDecl /></transition>
	<transition on="&amp;" push="SawAmp" to="SQAVal"> <ReportText /> <MarkAmp /> <ColdStart /></transition>
	<transition on="$." to="SQADef" />
</state>

<!-- in AttrValue, "-delimited			-->
<state name="DQAVal" fallback="BustedMarkup">
	<transition on="&lt;" to="DQAVal"> <MarkLt /></transition>
	<transition on='"' do="Pop()"> <EndAttrVal /></transition>
	<transition on="&amp;" push="SawAmp" to="DQAVal"> <ReportText /> <MarkAmp /> <ColdStart /></transition>
	<transition on="$." to="DQAVal" />
</state>

<!-- in Default Attrval			-->
<state name="DQADef" fallback="BustedDecl">
	<transition on='"' do="Pop()"> <EndAttrVal /> <ReportAttDecl /></transition>
	<transition on="&amp;" push="SawAmp" to="DQAVal"> <ReportText /> <MarkAmp /> <ColdStart /></transition>
	<transition on="$." to="DQADef" />
</state>

<!-- scanning in PCData			-->
<state name="InDoc" fallback="InDoc"><en>in character data</en>
	<transition on="&lt;" to="SawLT"> <ReportText /> <MarkLt /></transition>
	<transition on="&amp;" push="SawAmp" to="InDoc"> <ReportText /> <MarkAmp /> <ColdStart /></transition>
	<transition on="$." to="InDoc" />
	<transition on="]" to="RSBInDoc" />
</state>

<!-- ] in doc			-->
<state name="RSBInDoc" fallback="InDoc">
	<transition on="&lt;" to="SawLT"> <ReportText /> <MarkLt /></transition>
	<transition on="&amp;" push="SawAmp" to="InDoc"> <ReportText /> <MarkAmp /> <ColdStart /></transition>
	<transition on="]" to="RSB2InDoc" />
	<transition on="$." to="InDoc" />
</state>

<!-- ]] in doc			-->
<state name="RSB2InDoc" fallback="InDoc">
	<transition on="&lt;" to="SawLT"> <ReportText /> <MarkLt /></transition>
	<transition on="&amp;" push="SawAmp" to="InDoc"> <ReportText /> <MarkAmp /> <ColdStart /></transition>
	<transition on=">" to="InDoc"> <FloatingMSE /></transition>
	<transition on="]" to="RSB2InDoc" />
	<transition on="$." to="InDoc" />
</state>

<!--After root element			-->
<state name="AfterRoot" fallback="AfterRoot"><en>after end of document</en>
	<transition on="$S" to="AfterRoot" />
	<transition on="&lt;" to="LTAfterRoot" />
</state>

<state name="LTAfterRoot" fallback="BustedMarkup"><en>&lt; after document</en>
	<transition on="?" push="InPI" to="AfterRoot"> <ColdStart /></transition>
	<transition on="!" to="ComStartAfter" />
</state>
<state name="ComStartAfter" fallback="BustedMarkup"> 
	<transition on="-" push="COMStartHalf" to="AfterRoot" />
</state>



<!-- ================================================================= 
     REFERENCES
     ==================================================================
-->
<state name="SawAmp" fallback="BustedEntity"><en>after &amp;</en>
	<transition on="a" to="AmpA" />
	<transition on="g" to="AmpG" />
	<transition on="l" to="AmpL" />
	<transition on="q" to="AmpQ" />
	<transition on="#" to="AmpHash" />
	<transition on="$NameStart" to="EntBody" />
</state>

<!-- reading numeric char refs			-->
<state name="AmpHash" fallback="BustedEntity"><en>in &amp;# reference</en>
	<transition on="0123456789" to="AmpHash" />
	<transition on="x" to="HexRef" />
	<transition on=";" do="Pop()"> <HashRef /></transition>
</state>

<!-- hex char refs			-->
<state name="HexRef" fallback="BustedEntity"><en>in &amp;#x reference</en>
	<transition on="$Hex" to="HexRef" />
	<transition on=";" do="Pop()"> <HashRef /></transition>
</state>

<state name="EntBody" fallback="BustedEntity"><en>in entity name</en>
	<transition on=";" do="Pop()"> <ReportReference /></transition>
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpG" fallback="BustedEntity"><en>in entity reference</en>
	<transition on="t" to="AmpGt" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpGt" fallback="BustedEntity">
	<transition on=";" do="Pop()"> <CharRefGT/> </transition>
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpL" fallback="BustedEntity">
	<transition on="t" to="AmpLt" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpLt" fallback="BustedEntity">
	<transition on=";" do="Pop()"> <CharRefLT/> </transition>
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpQ" fallback="BustedEntity">
	<transition on="u" to="AmpQu" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpQu" fallback="BustedEntity">
	<transition on="o" to="AmpQuo" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpQuo" fallback="BustedEntity">
	<transition on="t" to="AmpQuot" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpQuot" fallback="BustedEntity">
	<transition on=";" do="Pop()"> <CharRefQuot/> </transition>
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpA" fallback="BustedEntity">
	<transition on="m" to="AmpAm" />
	<transition on="p" to="AmpAp" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpAp" fallback="BustedEntity">
	<transition on="o" to="AmpApo" />
	<transition on="$NameC" to="EntBody" />
</state>
<state name="AmpApo" fallback="BustedEntity">
	<transition on="s" to="AmpApos" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpApos" fallback="BustedEntity">
	<transition on=";" do="Pop()"> <CharRefApos /> </transition>
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpAm" fallback="BustedEntity">
	<transition on="p" to="AmpAmp" />
	<transition on="$NameC" to="EntBody" />
</state>

<state name="AmpAmp" fallback="BustedEntity">
	<transition on=";" do="Pop()"> <CharRefAmp /> </transition>
	<transition on="$NameC" to="EntBody"/>
</state>

<!-- ================================================================= 
     BUSTED THINGS
     ==================================================================
-->


<state name="BustedProlog" fallback="InProlog"> 
	<transition on=">" to="InProlog" />
	<transition on="$." to="BustedProlog" />
</state>

<!-- Breakage in markup - wait for">"			-->
<state name="BustedMarkup" fallback="InDoc">
	<transition on=">" to="InDoc"> <ColdStart /></transition>
	<transition on="$." to="BustedMarkup" />
</state>

<!-- Breakage in declaration in subset - wait for '>'			-->
<state name="BustedDecl" fallback="InDoc">
	<transition on=">" to="InSubset" />
	<transition on="$." to="BustedDecl" />
</state>


<state name="BustedEntity" fallback="InDoc">
	<transition on=";" do="Pop()"> <ColdStart /></transition>
	<transition on="$." to="BustedEntity" />
</state>


<state name="BustedXmlDecl" fallback="InDoc">
	<transition on=">" to="InDoc" />
	<transition on="$." to="BustedXmlDecl" />
</state>

<!-- ================================================================= 
     XML DECLARATION
     ==================================================================
-->

<!--
# XML declaration is:
# XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
# TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
# VersionInfo ::= S 'version' Eq ('"VersionNum"' | "'VersionNum'")
# Eq ::= S? '=' S?
# VersionNum ::= ([a-zA-Z0-9_.:] | '-')+
# EncodingDecl ::= S 'encoding' Eq '"' EncName '"' | "'" EncName "'"
# EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
# SDDecl ::= S 'standalone' Eq "'" ('yes' | 'no') "'"
#            | S 'standalone' Eq '"' ('yes' | 'no') '"'

-->
<!-- NOTE: Order of transition tests significant below -->
<!-- we start after the <?, with saving on -->
<state name="TryXMLD" fallback="InDoc"><en>trying for &lt;?xml</en>
	<transition on="x" to="TryXMLD2" />
	<transition on="$NameStart" to="PI2" />
</state>
<state name="TryXMLD2" fallback="InDoc">
	<transition on="m" to="TryXMLD3" />
	<transition on="$NameC" to="PI2" />
	<transition on="$S" to="PI3 "><EndSave /></transition>
	<transition on="?" to="PICMustHaveGT"> <EndSave /></transition>
</state>
<state name="TryXMLD3" fallback="InDoc">
	<transition on="l" to="TryXMLD4" />
	<transition on="$NameC" to="PI2" />
	<transition on="$S" to="PI3"> <EndSave /></transition>
	<transition on="?" to="PICMustHaveGT"> <EndSave /></transition>
</state>
<state name="TryXMLD4" fallback="InDoc">
	<transition on="$S" to="XMLDs1"> <EndSave /></transition>
</state>
	<transition on="$NameC" to="PI2" />
<state name="XMLDs1" fallback="BustedXmlDecl"><en>in XML declaration</en>
	<transition on="v" do="Keyword(version,1)" to="AfterVersion" />
	<transition on="$S XMLDs1" />
</state>
<state name="AfterVersion" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterVersion" />
	<transition on="=" to="AfterVersEq" />
</state>
<state name="AfterVersEq" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterVersEq" />
	<transition on="'" do="Keyword('1.',1)" to="GotMajorVerSQ" />
	<transition on='"' do="Keyword('1.', 1)" to="GotMajorVerDQ" />
</state>
<state name="GotMajorVerSQ" fallback="BustedXmlDecl">
	<transition on="0" to="GotMinorVerSQ" ><IsXml1-0 /></transition>
	<transition on="1" to="GotMinorVerSQ" ><IsXml1-1 /></transition>
</state>
<state name="GotMajorVerDQ" fallback="BustedXmlDecl">
	<transition on="0" to="GotMinorVerDQ" ><IsXml1-0 /></transition>
	<transition on="1" to="GotMinorVerDQ" ><IsXml1-1 /></transition>
</state>
<state name="GotMinorVerSQ" fallback="BustedXmlDecl">
	<transition on="'" to="GotVer" />
</state>
<state name="GotMinorVerDQ" fallback="BustedXmlDecl">
	<transition on='"' to="GotVer" />
</state>
<state name="GotVer" fallback="BustedXmlDecl">
	<transition on="$S" to="DoneVer" />
	<transition on="?" to="EndXMLD" />
</state>
<state name="DoneVer" fallback="BustedXmlDecl">
	<transition on="$S" to="DoneVer" />
	<transition on="?" to="EndXMLD" />
	<transition on="e" do="Keyword(encoding, 1)" to="AfterEnc"> <HotStart /></transition>
	<transition on="s" do="Keyword(standalone, 1)" to="AfterStand"> <HotStart /></transition>
</state>
</state>
<state name="AfterEnc" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterEnc2"><EndSave /></transition>
	<transition on="=" to="AfterEncEq"><EndSave /></transition>
</state>
<state name="AfterEnc2" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterEnc2" />
	<transition on="=" to="AfterEncEq" />
</state>

<state name="AfterEncEq" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterEncEq" />
	<transition on="'" to="SQEncName"> <ColdStart /></transition>
	<transition on='"' to="DQEncName"> <ColdStart /></transition>
</state>

<state name="SQEncName" fallback="BustedXmlDecl">
	<transition on="$EncName" to="SQEncName" />
	<transition on="'" to="AfterEncName"> <EndSave /></transition>
</state>
<state name="DQEncName" to="BustedXmlDecl"> 
	<transition on="$EncName" to="DQEncName" />
	<transition on='"' to="AfterEncName "><EndSave /></transition>
</state>

<state name="AfterEncName" fallback="BustedXmlDecl"> 
	<transition on="$S" to="DoneEncName" />
	<transition on="?" to="EndXMLD" />	
</state>
<state name="DoneEncName" fallback="BustedXmlDecl">
	<transition on="$S" to="DoneEncName" />
	<transition on="?" to="EndXMLD" />
	<transition on="s" do="Keyword(standalone,1)" to="AfterStand"> <HotStart /></transition>
</state>

<state name="AfterStand" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterStand2"> <EndSave /></transition>
	<transition on="=" to="AfterStandEq"> <EndSave /></transition>
</state>
<state name="AfterStand2" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterStand2" />
	<transition on="=" to="AfterStandEq" />
</state>
<state name="AfterStandEq" fallback="BustedXmlDecl">
	<transition on="$S" to="AfterStandEq" />
	<transition on="'" to="StandSQ"> <ColdStart /></transition>
	<transition on='"' to="StandDQ"> <ColdStart /></transition>
</state>

<state name="StandSQ" fallback="BustedXmlDecl">
	<transition on="y" do="Keyword('yes', 2)" to="AfterSDD"  />
	<transition on="n" do="Keyword('no', 2)" to="AfterSDD" />
</state>
<state name="StandDQ" fallback="BustedXmlDecl">
	<transition on="y" do="Keyword('yes', 2)" to="AfterSDD" > <HotStart /></transition>
	<transition on="n" do="Keyword('no', 2)" to="AfterSDD"> <HotStart /></transition>
</state>

<state name="AfterSDD" fallback="BustedXmlDecl">
	<transition on="?" to="EndXMLD"> <EndSave /></transition>
	<transition on="$S" to="DoneSDD"> <EndSave /></transition>
</state>

<state name="DoneSDD" fallback="BustedXmlDecl">
	<transition on="$S" to="DoneSDD" />
	<transition on="?" to="EndXMLD" />
</state>

<state name="EndXMLD" fallback="BustedXmlDecl">
	<transition on=">" do="Pop()"> <GotXMLD /></transition>
</state>


</automaton>