parent
680f5eeb15
commit
9fd0a71e4d
3 changed files with 65 additions and 2 deletions
|
|
@ -180,6 +180,7 @@ type
|
|||
errEqExpected, ## ``=`` expected
|
||||
errQuoteExpected, ## ``"`` or ``'`` expected
|
||||
errEndOfCommentExpected ## ``-->`` expected
|
||||
errAttributeValueExpected ## non-empty attribute value expected
|
||||
|
||||
ParserState = enum
|
||||
stateStart, stateNormal, stateAttr, stateEmptyElementTag, stateError
|
||||
|
|
@ -187,6 +188,7 @@ type
|
|||
XmlParseOption* = enum ## options for the XML parser
|
||||
reportWhitespace, ## report whitespace
|
||||
reportComments ## report comments
|
||||
allowUnquotedAttribs ## allow unquoted attribute values (for HTML)
|
||||
|
||||
XmlParser* = object of BaseLexer ## the parser object.
|
||||
a, b, c: string
|
||||
|
|
@ -207,7 +209,8 @@ const
|
|||
"'>' expected",
|
||||
"'=' expected",
|
||||
"'\"' or \"'\" expected",
|
||||
"'-->' expected"
|
||||
"'-->' expected",
|
||||
"attribute value expected"
|
||||
]
|
||||
|
||||
proc open*(my: var XmlParser, input: Stream, filename: string,
|
||||
|
|
@ -669,6 +672,21 @@ proc parseAttribute(my: var XmlParser) =
|
|||
pendingSpace = false
|
||||
add(my.b, buf[pos])
|
||||
inc(pos)
|
||||
elif allowUnquotedAttribs in my.options:
|
||||
const disallowedChars = {'"', '\'', '`', '=', '<', '>', ' ',
|
||||
'\0', '\t', '\L', '\F', '\f'}
|
||||
let startPos = pos
|
||||
while (let c = buf[pos]; c notin disallowedChars):
|
||||
if c == '&':
|
||||
my.bufpos = pos
|
||||
parseEntity(my, my.b)
|
||||
my.kind = xmlAttribute # parseEntity overwrites my.kind!
|
||||
pos = my.bufpos
|
||||
else:
|
||||
add(my.b, c)
|
||||
inc(pos)
|
||||
if pos == startPos:
|
||||
markError(my, errAttributeValueExpected)
|
||||
else:
|
||||
markError(my, errQuoteExpected)
|
||||
# error corrections: guess what was meant
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue