feat: Added standalone property and tweaked xmldecl parsing
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				test / test (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	test / test (push) Has been cancelled
				
			This commit is contained in:
		@@ -1,16 +1,16 @@
 | 
				
			|||||||
 | 
					import gleam/option.{type Option, None}
 | 
				
			||||||
import gleam/result
 | 
					import gleam/result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub type Declaration {
 | 
					pub type Declaration {
 | 
				
			||||||
  Declaration(versioninfo: String, encoding: String)
 | 
					  Declaration(versioninfo: String, encoding: String, standalone: Bool)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub type DocType {
 | 
					pub type DocType {
 | 
				
			||||||
  None
 | 
					 | 
				
			||||||
  DocType(name: String)
 | 
					  DocType(name: String)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub type Document {
 | 
					pub type Document {
 | 
				
			||||||
  Document(decl: Declaration, doctype: DocType)
 | 
					  Document(decl: Declaration, doctype: Option(DocType))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn main() {
 | 
					pub fn main() {
 | 
				
			||||||
@@ -23,8 +23,13 @@ fn parse_document(doc: String) -> Result(Document, Nil) {
 | 
				
			|||||||
  Ok(Document(decl, doctype))
 | 
					  Ok(Document(decl, doctype))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn parse_prolog(doc: String) -> Result(#(Declaration, DocType, String), Nil) {
 | 
					fn parse_prolog(
 | 
				
			||||||
  use #(decl, doc) <- result.try(parse_decl(doc))
 | 
					  doc: String,
 | 
				
			||||||
 | 
					) -> Result(#(Declaration, Option(DocType), String), Nil) {
 | 
				
			||||||
 | 
					  let #(decl, doc) = case parse_decl(doc) {
 | 
				
			||||||
 | 
					    Ok(#(decl, doc)) -> #(decl, doc)
 | 
				
			||||||
 | 
					    _ -> #(Declaration("1.0", "UTF-8", False), doc)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Ok(#(decl, None, doc))
 | 
					  Ok(#(decl, None, doc))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -37,9 +42,14 @@ fn parse_decl(doc: String) -> Result(#(Declaration, String), Nil) {
 | 
				
			|||||||
        Ok(e) -> e
 | 
					        Ok(e) -> e
 | 
				
			||||||
        Error(_) -> #("", doc)
 | 
					        Error(_) -> #("", doc)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      let #(standalone, doc) = case parse_standalone(doc) {
 | 
				
			||||||
 | 
					        Ok(e) -> e
 | 
				
			||||||
 | 
					        Error(_) -> #(False, doc)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      case trim_space(doc) {
 | 
					      case trim_space(doc) {
 | 
				
			||||||
        "?>" <> tail -> Ok(#(Declaration(versioninfo:, encoding:), tail))
 | 
					        "?>" <> tail ->
 | 
				
			||||||
 | 
					          Ok(#(Declaration(versioninfo:, encoding:, standalone:), tail))
 | 
				
			||||||
        _ -> Error(Nil)
 | 
					        _ -> Error(Nil)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -142,6 +152,17 @@ fn parse_encoding(doc: String) -> Result(#(String, String), Nil) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn parse_standalone(doc: String) -> Result(#(Bool, String), Nil) {
 | 
				
			||||||
 | 
					  use #(_, doc) <- result.try(parse_space(doc))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  case doc {
 | 
				
			||||||
 | 
					    "standalone=\"yes\"" <> tail | "standalone='yes'" <> tail ->
 | 
				
			||||||
 | 
					      Ok(#(True, tail))
 | 
				
			||||||
 | 
					    "standalone=\"no\"" <> tail | "standalone='no'" <> tail -> Ok(#(True, tail))
 | 
				
			||||||
 | 
					    _ -> Error(Nil)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn do_parse_digit(doc: String) -> Result(#(String, String), Nil) {
 | 
					fn do_parse_digit(doc: String) -> Result(#(String, String), Nil) {
 | 
				
			||||||
  case doc {
 | 
					  case doc {
 | 
				
			||||||
    "0" as digit <> tail
 | 
					    "0" as digit <> tail
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user