Flowdock

Using the Pull Parser

This API is experimental, and subject to change.

parser = PullParser.new( "<a>text<b att='val'/>txet</a>" )
while parser.has_next?
  res = parser.next
  puts res[1]['att'] if res.start_tag? and res[0] == 'b'
end

See the PullEvent class for information on the content of the results. The data is identical to the arguments passed for the various events to the StreamListener API.

Notice that:

parser = PullParser.new( "<a>BAD DOCUMENT" )
while parser.has_next?
  res = parser.next
  raise res[1] if res.error?
end

Nat Price gave me some good ideas for the API.

Constants

MISSING_ATTRIBUTE_QUOTES = /^<#{NAME_STR}\s+#{NAME_STR}\s*=\s*[^"']/um

DEFAULT_ENTITIES = { 'gt' => [/>/, '>', '>', />/], 'lt' => [/</, '<', '<', / [/"/, '"', '"', /"/], "apos" => [/'/, "'", "'", /'/] }

EREFERENCE = /&(?!#{NAME};)/

ENTITYDECL = /\s*(?:#{GEDECL})|(?:#{PEDECL})/um

GEDECL = ""

PEDECL = ""

ENTITYDEF = "(?:#{ENTITYVALUE}|(?:#{EXTERNALID}(#{NDATADECL})?))"

PEDEF = "(?:#{ENTITYVALUE}|#{EXTERNALID})"

ENTITYVALUE = %Q{((?:"(?:[^%&"]|#{PEREFERENCE}|#{REFERENCE})*")|(?:'([^%&']|#{PEREFERENCE}|#{REFERENCE})*'))}

PEREFERENCE = "%#{NAME};"

NDATADECL = "\\s+NDATA\\s+#{NAME}"

EXTERNALID = "(?:(?:(SYSTEM)\\s+#{SYSTEMLITERAL})|(?:(PUBLIC)\\s+#{PUBIDLITERAL}\\s+#{SYSTEMLITERAL}))"

PUBIDLITERAL = %Q{("[#{PUBIDCHAR}']*"|'[#{PUBIDCHAR}]*')}

SYSTEMLITERAL = %Q{((?:"[^"]*")|(?:'[^']*'))}

PUBIDCHAR = "\x20\x0D\x0Aa-zA-Z0-9\\-()+,./:=?;!*@$_%#"

TEXT_PATTERN = /\A([^<]*)/um

SYSTEM = /^\s*/um

PUBLIC = /^\s*/um

NOTATIONDECL_START = /^\s*

ATTLISTDECL_PATTERN = /^\s*/um

ATTLISTDECL_START = /^\s*

ATTDEF_RE = /#{ATTDEF}/

ATTDEF = "\\s+#{NAME}\\s+#{ATTTYPE}\\s+#{DEFAULTDECL}"

DEFAULTDECL = "(#REQUIRED|#IMPLIED|(?:(#FIXED\\s+)?#{ATTVALUE}))"

ATTVALUE = "(?:\"((?:[^<&\"]|#{REFERENCE})*)\")|(?:'((?:[^<&']|#{REFERENCE})*)')"

ATTTYPE = "(CDATA|ID|IDREF|IDREFS|ENTITY|ENTITIES|NMTOKEN|NMTOKENS|#{ENUMERATEDTYPE})"

ENUMERATEDTYPE = "(?:(?:#{NOTATIONTYPE})|(?:#{ENUMERATION}))"

NOTATIONTYPE = "NOTATION\\s+\\(\\s*#{NAME}(?:\\s*\\|\\s*#{NAME})*\\s*\\)"

ENUMERATION = "\\(\\s*#{NMTOKEN}(?:\\s*\\|\\s*#{NMTOKEN})*\\s*\\)"

SYSTEMENTITY = /^\s*(%.*?;)\s*$/um

ELEMENTDECL_PATTERN = /^\s*(/um

ELEMENTDECL_START = /^\s*

IDENTITY = /^([!\*\w\-]+)(\s+#{NCNAME_STR})?(\s+["'](.*?)['"])?(\s+['"](.*?)["'])?/u

ENTITY_START = /^\s*

STANDALONE = /\bstandalone\s*=\s*["'](.*?)['"]/um

ENCODING = /\bencoding\s*=\s*["'](.*?)['"]/um

VERSION = /\bversion\s*=\s*["'](.*?)['"]/um

CLOSE_MATCH = /^\s*<\/(#{NAME_STR})\s*>/um

TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{UNAME_STR}\s*=\s*(["']).*?\5)*)\s*(\/)?>/um

INSTRUCTION_PATTERN = /<\?(.*?)(\s+.*?)?\?>/um

INSTRUCTION_START = /\A<\?/u

XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um

XMLDECL_START = /\A<\?xml\s/u;

CDATA_PATTERN = //um

CDATA_END = /^\s*\]\s*>/um

CDATA_START = /\A

COMMENT_PATTERN = //um

COMMENT_START = /\A