fix: XML parsing bugs (#2601)
* fix: make XML parser handle trailing whitespace in opening tags * fix: make XML parser handle comments correctly --------- Co-authored-by: György Kurucz <me@kuruczgy.com>
This commit is contained in:
parent
44bc68bdc6
commit
83c7c29075
3 changed files with 14 additions and 2 deletions
|
|
@ -119,7 +119,7 @@ def XMLdecl : Parsec Unit := do
|
|||
def Comment : Parsec String :=
|
||||
let notDash := Char.toString <$> satisfy (λ c => c ≠ '-')
|
||||
skipString "<!--" *>
|
||||
Array.foldl String.append "" <$> many (notDash <|> (do
|
||||
Array.foldl String.append "" <$> many (attempt <| notDash <|> (do
|
||||
let d ← pchar '-'
|
||||
let c ← notDash
|
||||
pure $ d.toString ++ c))
|
||||
|
|
@ -408,7 +408,7 @@ def Attribute : Parsec (String × String) := do
|
|||
protected def elementPrefix : Parsec (Array Content → Element) := do
|
||||
skipChar '<'
|
||||
let name ← Name
|
||||
let attributes ← many (S *> Attribute)
|
||||
let attributes ← many (attempt <| S *> Attribute)
|
||||
optional S *> pure ()
|
||||
return Element.Element name (RBMap.fromList attributes.toList compare)
|
||||
|
||||
|
|
|
|||
10
tests/lean/xmlParsing.lean
Normal file
10
tests/lean/xmlParsing.lean
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import Lean.Data.Xml
|
||||
open Lean.Xml
|
||||
|
||||
/-! Test XML parsing. -/
|
||||
|
||||
/-! Test whether trailing whitespace in opening tags is handled correctly. -/
|
||||
#eval parse "<a ><b a=\"v\" ></b></a>"
|
||||
|
||||
/-! Test whether comments are parsed correctly. -/
|
||||
#eval parse "<a><!-- comment --></a>"
|
||||
2
tests/lean/xmlParsing.lean.expected.out
Normal file
2
tests/lean/xmlParsing.lean.expected.out
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ok: <a><b a="v"></b></a>
|
||||
ok: <a><!-- comment --></a>
|
||||
Loading…
Add table
Reference in a new issue