cudl

A data language as simple as JSON but as readable as YAML or TOML.
git clone https://shtanton.xyz/git/cudl.git
Log | Files | Refs | README

spec.txt (3238B)


      1 # CUDL - Clear and Unmistakable Data Language
      2 
      3 * Every file contains 1 value, which may have other values nested inside it.
      4 * A schema can be provided when a file is parsed which gives it's value a type.
      5 * The schema can contain the types map, array, string, int, float, bool, nullable and "any" which will infer the type while parsing.
      6 * Each value must have certain characters around it depending on its type. It must have a preceeding character or starting character if it's type is not given in the schema.
      7 * Whitespace at the start of the file and after a value is ignored, however "succeeded by" always refers to the character immediately following the value, with no whitespace in between.
      8 * Unless stated otherwise, the preceeding and succeeding character is part of the syntax of the value (is consumed by the parser when the value is consumed).
      9 
     10 An inline-end character is one of the following:
     11 * linefeed
     12 * carriage return
     13 * ]
     14 * }
     15 * EOF
     16 
     17 ## Map
     18 
     19 A sequence of key:value pairs. No delimeter is needed as every value will have a ending marker.
     20 The first key may be preceeded by whitespace and whitespace can occur before or after the : between the key and value.
     21 If a key starts with a quote then it obeys the same rules as a quoted string.
     22 Otherwise a key must match [A-Za-z0-9_-]+
     23 
     24 A map can be preceeded by a { and succeeded by a }
     25 A map can be preceeded by nothing and succeeded by a semicolon or EOF.
     26 A map can be preceeded by nothing and succeeded by a ], which is not consumed.
     27 
     28 ## Array
     29 
     30 A sequence of values, no delimeter.
     31 
     32 An array is preceeded by a [ (optionally followed by whitespace) and succeeded by a ]
     33 
     34 ## String
     35 
     36 A string can be preceeded by a " and succeeded by a "
     37 A string can be preceeded by nothing and succeeded by a comma
     38 A string can be preceeded by nothing and succeeded by an inline-end character, which is not consumed.
     39 An unquoted string must match [A-Za-z0-9_ ]+
     40 The following escape sequences are available for quoted strings and keys:
     41 ```
     42 \b - backspace
     43 \t - tab
     44 \n - linefeed
     45 \r - carriage return
     46 \" - quote
     47 \\ - backslash
     48 \uXXXX - unicode XXXX
     49 \UXXXXXXXX - unicode XXXXXXXX
     50 ```
     51 
     52 ### Multiline string
     53 
     54 A string can also be a multiline string. If a value starts with a pipe, it should be followed by a newline. Then there should be a sequence of 0 or more whitespace characters, which defines the indent sequence, followed by a sequence of non-whitespace characters (the terminating sequence) then a newline. Then every line much start with the indent sequence (which is not part of the string value) and the multiline string runs until it encounters the indent sequence followed by the terminating sequence on its own line. The final newline is not included in the value of the string.
     55 
     56 ### Integer/Float
     57 
     58 A schema can declare a value to be an integer or float.
     59 
     60 An integer matches -?[0-9]+(e[0-9]+)?
     61 A float matches -?[0-9]+(\.[0-9]+)?(e[0-9]+)?
     62 
     63 ## Number
     64 
     65 A number starts with a digit or - and is succeeded by:
     66 * A comma, which is consumed
     67 * An inline-end character or whitespace, which are not consumed
     68 
     69 Numbers can be integers or floats depending on the implementation.
     70 
     71 ## Boolean
     72 
     73 A boolean is either %true or %false. It is not succeeded by anything.
     74 
     75 ## Null
     76 
     77 A null is written as %null