From 91d6b1c7c02fd3a7aca6915a4670543740065571 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Thu, 12 Dec 2024 10:36:45 +0100 Subject: [PATCH] Cleanup --- doc/content/xml.md | 22 ++++++++++++++++------ tests/language/xml_test.liq | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/content/xml.md b/doc/content/xml.md index adac640fb1..deda87965e 100644 --- a/doc/content/xml.md +++ b/doc/content/xml.md @@ -34,12 +34,14 @@ let xml.parse (x : } } ) = s + +print("The value for blu is: #{x.bla.ble}") ``` Things to note: -- The basic mappings are: `tag name -> tag content` -- Tag content maps tag parameters to `xml_params` +- The basic mappings are: ` -> ` +- Tag content maps tag parameters to a `xml_params` method. - When multiple tags are present, their values are collected as tuple (`bar` tag in the example) - When a tag contains a single ground value (`string`, `bool`, `float` or `integer`), the mapping is from tag name to the corresponding value, with xml attributes attached as methods - Tag parameters can be converted to ground values and omitted. @@ -49,7 +51,15 @@ The parsing is driven by the type annotation and is intended to be permissive. F ```liquidsoaop s = 'foo' +# Here, `foo` is omitted. let xml.parse (x: { bla: unit }) = s + +# x contains: { bla = () } + +# Here, `foo` is made optional +let xml.parse (x: { bla: string? }) = s + +# x contains: { bla = "foo" } ``` ### Formal representation @@ -133,11 +143,11 @@ This representation is much less convenient to manipulate but allows an exact re Things to note: - XML nodes are represented by a pair of the form: `(, )` -- `` contains the following: +- `` is a record containing the following methods: - `xml_params`, represented as a list of pairs `(string * string)` - - `xml_children`, containing an array of the XML node's children. - - `xml_text`, present when the node is a text node. In this case, `xml_params` or `xm_children` are empty. -- By convention, text nodes are labelled `xml_text`. + - `xml_children`, containing a list of the XML node's children. Each entry in the list is a node in the formal XML representation. + - `xml_text`, present when the node is a text node. In this case, `xml_params` and `xm_children` are empty. +- By convention, text nodes are labelled `xml_text` and are of the form: `{ xml_text: "node content" }` ### Rendering XML values diff --git a/tests/language/xml_test.liq b/tests/language/xml_test.liq index 071bf3a658..e242e945f9 100644 --- a/tests/language/xml_test.liq +++ b/tests/language/xml_test.liq @@ -44,13 +44,13 @@ def f() = { xml_params=[("param", "1"), ("bla", "true")], bar="bla".{xml_params=[("option", "aab")]}, - foo="gni".{xml_params={opt=12.3}} + foo=true.{xml_params={opt=12.3}} } } ), ' bla - gni + true ' )