From 5476d434410882383862d1d17a63d79502565bf4 Mon Sep 17 00:00:00 2001 From: Kostas Tsiligkiris Date: Wed, 17 Jan 2024 07:00:25 +0200 Subject: Move package xml before copyright Having the same copyright on all files made the documentation script to include it multiple times in the package information. --- core/encoding/xml/debug_print.odin | 6 ++++-- core/encoding/xml/helpers.odin | 6 ++++-- core/encoding/xml/tokenizer.odin | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'core/encoding/xml') diff --git a/core/encoding/xml/debug_print.odin b/core/encoding/xml/debug_print.odin index b97617a8a..2607bec23 100644 --- a/core/encoding/xml/debug_print.odin +++ b/core/encoding/xml/debug_print.odin @@ -1,3 +1,5 @@ +package xml + /* An XML 1.0 / 1.1 parser @@ -9,7 +11,7 @@ List of contributors: Jeroen van Rijn: Initial implementation. */ -package xml + import "core:io" import "core:fmt" @@ -81,4 +83,4 @@ print_element :: proc(writer: io.Writer, doc: ^Document, element_id: Element_ID, } return written, .None -} \ No newline at end of file +} diff --git a/core/encoding/xml/helpers.odin b/core/encoding/xml/helpers.odin index e0b5ecc32..42a5258b3 100644 --- a/core/encoding/xml/helpers.odin +++ b/core/encoding/xml/helpers.odin @@ -1,3 +1,5 @@ +package xml + /* An XML 1.0 / 1.1 parser @@ -6,7 +8,7 @@ This file contains helper functions. */ -package xml + // Find parent's nth child with a given ident. find_child_by_ident :: proc(doc: ^Document, parent_id: Element_ID, ident: string, nth := 0) -> (res: Element_ID, found: bool) { @@ -47,4 +49,4 @@ find_attribute_val_by_key :: proc(doc: ^Document, parent_id: Element_ID, key: st if attr.key == key { return attr.val, true } } return "", false -} \ No newline at end of file +} diff --git a/core/encoding/xml/tokenizer.odin b/core/encoding/xml/tokenizer.odin index cd055475c..a223a75d6 100644 --- a/core/encoding/xml/tokenizer.odin +++ b/core/encoding/xml/tokenizer.odin @@ -1,3 +1,5 @@ +package xml + /* An XML 1.0 / 1.1 parser @@ -9,7 +11,7 @@ List of contributors: Jeroen van Rijn: Initial implementation. */ -package xml + import "core:fmt" import "core:unicode" @@ -433,4 +435,4 @@ scan :: proc(t: ^Tokenizer) -> Token { lit = string(t.src[offset : t.offset]) } return Token{kind, lit, pos} -} \ No newline at end of file +} -- cgit v1.2.3 From 02c2aff41b92fa8b8a19c0b6599f02549178ca1a Mon Sep 17 00:00:00 2001 From: Kostas Tsiligkiris Date: Wed, 17 Jan 2024 07:04:00 +0200 Subject: Fix formatting of package documentation string --- core/encoding/xml/xml_reader.odin | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'core/encoding/xml') diff --git a/core/encoding/xml/xml_reader.odin b/core/encoding/xml/xml_reader.odin index f4f8a4b05..8538febb5 100644 --- a/core/encoding/xml/xml_reader.odin +++ b/core/encoding/xml/xml_reader.odin @@ -1,28 +1,28 @@ /* - An XML 1.0 / 1.1 parser + XML 1.0 / 1.1 parser - Copyright 2021-2022 Jeroen van Rijn . - Made available under Odin's BSD-3 license. + 2021-2022 Jeroen van Rijn . + available under Odin's BSD-3 license. - A from-scratch XML implementation, loosely modelled on the [spec](https://www.w3.org/TR/2006/REC-xml11-20060816). + from-scratch XML implementation, loosely modelled on the [spec](https://www.w3.org/TR/2006/REC-xml11-20060816). - Features: - - Supports enough of the XML 1.0/1.1 spec to handle the 99.9% of XML documents in common current usage. - - Simple to understand and use. Small. +Features: +- Supports enough of the XML 1.0/1.1 spec to handle the 99.9% of XML documents in common current usage. +- Simple to understand and use. Small. - Caveats: - - We do NOT support HTML in this package, as that may or may not be valid XML. - If it works, great. If it doesn't, that's not considered a bug. +Caveats: +- We do NOT support HTML in this package, as that may or may not be valid XML. + If it works, great. If it doesn't, that's not considered a bug. - - We do NOT support UTF-16. If you have a UTF-16 XML file, please convert it to UTF-8 first. Also, our condolences. - - <[!ELEMENT and <[!ATTLIST are not supported, and will be either ignored or return an error depending on the parser options. +- We do NOT support UTF-16. If you have a UTF-16 XML file, please convert it to UTF-8 first. Also, our condolences. +- <[!ELEMENT and <[!ATTLIST are not supported, and will be either ignored or return an error depending on the parser options. - MAYBE: - - XML writer? - - Serialize/deserialize Odin types? +MAYBE: +- XML writer? +- Serialize/deserialize Odin types? - List of contributors: - Jeroen van Rijn: Initial implementation. +List of contributors: +- Jeroen van Rijn: Initial implementation. */ package xml // An XML 1.0 / 1.1 parser @@ -700,4 +700,4 @@ new_element :: proc(doc: ^Document) -> (id: Element_ID) { cur := doc.element_count doc.element_count += 1 return cur -} \ No newline at end of file +} -- cgit v1.2.3 From a86cfa6e979f7b8d672561d3c177086f85ea2478 Mon Sep 17 00:00:00 2001 From: Kostas Tsiligkiris Date: Wed, 17 Jan 2024 21:38:33 +0200 Subject: Fix filename in example --- core/encoding/xml/example/xml_example.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/encoding/xml') diff --git a/core/encoding/xml/example/xml_example.odin b/core/encoding/xml/example/xml_example.odin index aebb8d0ea..9648143db 100644 --- a/core/encoding/xml/example/xml_example.odin +++ b/core/encoding/xml/example/xml_example.odin @@ -20,7 +20,7 @@ example :: proc() { xml.destroy(docs[round]) } - DOC :: #load("../../../../tests/core/assets/XML/unicode.xml") + DOC :: #load("../../../../tests/core/assets/XML/utf8.xml") input := DOC for round in 0.. Date: Wed, 17 Jan 2024 21:58:38 +0200 Subject: Fix comments in xml_reader.odin for better rendering in documentation --- core/encoding/xml/xml_reader.odin | 183 +++++++++++--------------------------- 1 file changed, 53 insertions(+), 130 deletions(-) (limited to 'core/encoding/xml') diff --git a/core/encoding/xml/xml_reader.odin b/core/encoding/xml/xml_reader.odin index 8538febb5..562d519d5 100644 --- a/core/encoding/xml/xml_reader.odin +++ b/core/encoding/xml/xml_reader.odin @@ -43,48 +43,32 @@ DEFAULT_OPTIONS :: Options{ } Option_Flag :: enum { - /* - If the caller says that input may be modified, we can perform in-situ parsing. - If this flag isn't provided, the XML parser first duplicates the input so that it can. - */ + // If the caller says that input may be modified, we can perform in-situ parsing. + // If this flag isn't provided, the XML parser first duplicates the input so that it can. Input_May_Be_Modified, - /* - Document MUST start with ` (doc: ^Document, err: Error) { data := data context.allocator = allocator opts := validate_options(options) or_return - /* - If `.Input_May_Be_Modified` is not specified, we duplicate the input so that we can modify it in-place. - */ + // If `.Input_May_Be_Modified` is not specified, we duplicate the input so that we can modify it in-place. if .Input_May_Be_Modified not_in opts.flags { data = bytes.clone(data) } @@ -252,10 +209,8 @@ parse_bytes :: proc(data: []u8, options := DEFAULT_OPTIONS, path := "", error_ha element, parent: Element_ID open: Token - /* - If a DOCTYPE is present, the root tag has to match. - If an expected DOCTYPE is given in options (i.e. it's non-empty), the DOCTYPE (if present) and root tag have to match. - */ + // If a DOCTYPE is present, the root tag has to match. + // If an expected DOCTYPE is given in options (i.e. it's non-empty), the DOCTYPE (if present) and root tag have to match. expected_doctype := options.expected_doctype loop: for { @@ -263,17 +218,13 @@ parse_bytes :: proc(data: []u8, options := DEFAULT_OPTIONS, path := "", error_ha // NOTE(Jeroen): This is faster as a switch. switch t.ch { case '<': - /* - Consume peeked `<` - */ + // Consume peeked `<` advance_rune(t) open = scan(t) // NOTE(Jeroen): We're not using a switch because this if-else chain ordered by likelihood is 2.5% faster at -o:size and -o:speed. if likely(open.kind, Token_Kind.Ident) == .Ident { - /* - e.g. 0 && expected_doctype != open.text { error(t, t.offset, "Root Tag doesn't match DOCTYPE. Expected: %v, got: %v\n", expected_doctype, open.text) @@ -298,23 +247,17 @@ parse_bytes :: proc(data: []u8, options := DEFAULT_OPTIONS, path := "", error_ha } } - /* - One of these should follow: - - `>`, which means we've just opened this tag and expect a later element to close it. - - `/>`, which means this is an 'empty' or self-closing tag. - */ + // One of these should follow: + // - `>`, which means we've just opened this tag and expect a later element to close it. + // - `/>`, which means this is an 'empty' or self-closing tag. end_token := scan(t) #partial switch end_token.kind { case .Gt: - /* - We're now the new parent. - */ + // We're now the new parent. parent = element case .Slash: - /* - Empty tag. Close it. - */ + // Empty tag. Close it. expect(t, .Gt) or_return parent = doc.elements[element].parent element = parent @@ -325,9 +268,7 @@ parse_bytes :: proc(data: []u8, options := DEFAULT_OPTIONS, path := "", error_ha } } else if open.kind == .Slash { - /* - Close tag. - */ + // Close tag. ident := expect(t, .Ident) or_return _ = expect(t, .Gt) or_return @@ -339,9 +280,7 @@ parse_bytes :: proc(data: []u8, options := DEFAULT_OPTIONS, path := "", error_ha element = parent } else if open.kind == .Exclaim { - /* - . - The grammar does not allow a comment to end in ---> - */ + // Comment: . + // The grammar does not allow a comment to end in ---> expect(t, .Dash) comment := scan_comment(t) or_return @@ -395,23 +332,17 @@ parse_bytes :: proc(data: []u8, options := DEFAULT_OPTIONS, path := "", error_ha } } else if open.kind == .Question { - /* - 0 { - /* - We've already seen a prologue. - */ + // We've already seen a prologue. return doc, .Too_Many_Prologs } else { - /* - Could be ` (err: Error) { doc.encoding = .LATIN_1 case: - /* - Unrecognized encoding, assume UTF-8. - */ + // Unrecognized encoding, assume UTF-8. error(t, offset, "[parse_prologue] Warning: Unrecognized encoding: %v\n", attr.val) } @@ -658,11 +583,11 @@ skip_element :: proc(t: ^Tokenizer) -> (err: Error) { parse_doctype :: proc(doc: ^Document) -> (err: Error) { /* - + - - ]> + + ]> */ assert(doc != nil) context.allocator = doc.allocator @@ -675,9 +600,7 @@ parse_doctype :: proc(doc: ^Document) -> (err: Error) { offset := t.offset skip_element(t) or_return - /* - -1 because the current offset is that of the closing tag, so the rest of the DOCTYPE tag ends just before it. - */ + // -1 because the current offset is that of the closing tag, so the rest of the DOCTYPE tag ends just before it. doc.doctype.rest = string(t.src[offset : t.offset - 1]) return .None } -- cgit v1.2.3