Skip to content

Read syntax

Ken Haase edited this page Feb 25, 2021 · 3 revisions

This document describes the default read syntax for KNO objects. Read macros describes ways to extend this syntax.

The textual form of KNO objects (and of KNO code) is essentially LISP/Scheme syntax with some extensions, including a limited extension framework [Read macros]. The objects represented in the standard Scheme syntax are:

  • integers: 42, -42, ``
  • flonums (floating point numbers): 3.1415, 3.5E10, 3.5E-10
  • rational numbers: 1/3, 11/5, `22/71
  • complex numbers: 5+3i, 5.0+3i, 1/2+2/3i
  • strings (made up of pairs): "foo", "foo bar", "foo \"bar\"", "foo\u0020bar", "foo\‐bar", "two\nlines", "tab\tseparated"
  • lists (made up of pairs): ("foo" bar 33 10/3 9/3)
  • improper lists: ("foo" . 33) or ("foo" bar . 33)
  • vectors: #("foo" bar 33 10/3 9/3)
  • constants: #t, #f, #eof, etc

There are also ways to refer to positive integers in useful radixes, e.g.

  • #o377 is 255
  • #x2a is 42

KNO provides simple specialized forms for some common data types:

  • UUIDs: #U8697708c-9cda-11e9-9a57-b8e85631ff28
  • Timestamps: #T2019-07-02T11:04:05-4:00 or #T2019-07-02T15:03:39.822364000Z.

In addition to UTF-8 strings, KNO supports byte strings, called packets. They use a #" syntax, for example #"abc" and support different encodings via a character between the # and ", e.g. hex (#X"2020" = #" ") or base64 (#b"Zm9v" = "foo").

OID syntax

One of the key features of KNO is the lightweight object pointers called OIDs. The read syntax for OIDs starts with the @ atsign character. This syntax has several variants as well as an simple extension frameork of their own. The formats are:

  • @<*hexdigits*>+ specifies a numeric OID based on the hexdigits, for example @200000999 specifies the OID with the numeric addres 8,589,937,049 in decimal.

  • @<hi>+<lo>+ specifies a numeric OID whose top 32 bits (or potentially more than 32 bits) are specified by hi and whose low 32 bits are specified by lo, again both in hex digits. For example, @2/999 refers to the above OID.

  • @/<*poolid*>/<lo>+ specifies an OID relative to the named pool poolid with a numeric address consisting of lo (again in hex) *added to the base of the pool tied to poolid. If the poolid *wikid were associated with a pool based at @2/0, the reference *@/wikid/999 would refer to the same OID as the two references *above.

  • @?<*id*> searches in the KNO background index for the %id slot id. So if the %id of an OID describing the English langauge were the symbol or string en, @?en would refer to that OID. (Providing that an entry for the OID was available in the background index*.

Compound syntax

Compounds are tagged KNO objects (typically vectors) and have the read syntax

#%(*tag* *specifiers...*)

The tag is used to locate a parser to generate an object from the specifiers. If no parser is available, a compound object is created from the tag with specifiers as positional elements.

Keymaps

KNO provides a read syntax for both schemaps and slotmaps (collectively referred to as keymaps). A schemap has the read syntax:

[*slotid1* *value1* *slotid2* *value2* ...]

while a slotmap has the same syntax prefixed by a hash/sharp sign (#):

#[*slotid1* *value1* *slotid2* *value2* ...]

Choices

Choices are collections of items enclosed in braces.

Clone this wiki locally