com.io7m.jsx 4.0.1-SNAPSHOT Documentation

Book Metadata

DATE | 2015-02-15T21:09:30+00:00
DESCRIPTION | jsx User Manual 4.0.1-SNAPSHOT
IDENTIFIER | bf4658b9-2181-44a9-98fe-01fa6f6ef67e
LANGUAGE | en
SOURCE | https://www.io7m.com/software/jsx
TITLE | com.io7m.jsx 4.0.1-SNAPSHOT Documentation

License

Copyright © 2024 Mark Raynsford <code@io7m.com> https://www.io7m.com

This book is placed into the public domain for free use by anyone for any purpose. It may be freely used, modified, and distributed.

In jurisdictions that do not recognise the public domain this book may be freely used, modified, and distributed without restriction.

This book comes with absolutely no warranty.

Table Of Contents

Cover

Colophon

Table Of Contents

1. Package Information

1.1. Orientation

1.2. Installation

1.2.1. Source Compilation

1.2.2. Maven

1.3. License

2. Expression Language

2.1. Notational Conventions

2.1.1. Unicode

2.1.2. EBNF

2.2. Language

1. Package Information

1.1. Orientation

1.2. Installation

1.2.1. Source Compilation

1.2.2. Maven

1.3. License

1.1. Orientation

The com.io7m.jsx package implements an S-expression parser.

1.2. Installation

1.2.1. Source Compilation

The project can be compiled and installed with Maven:

1.2.1.2. Compile

$ mvn -C clean install

1.2.2. Maven

Regular releases are made to the Central Repository, so it's possible to use the com.io7m.jsx package in your projects with the following Maven dependency:

1.2.2.2. Example

<dependency>
  <groupId>com.io7m.jsx</groupId>
  <artifactId>com.io7m.jsx-core</artifactId>
  <version>4.0.1-SNAPSHOT</version>
</dependency>

All io7m.com packages use Semantic Versioning [1], which implies that it is always safe to use version ranges with an exclusive upper bound equal to the next major version - the API of the package will not change in a backwards-incompatible manner before the next major version.

1.3. License

All files distributed with the com.io7m.jsx package are placed under the following license:

1.3.2. License

Copyright © 2015 Mark Raynsford <code@io7m.com> https://www.io7m.com

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Footnotes

1 | http://semver.org References to this footnote: 1

2. Expression Language

2.1. Notational Conventions

2.1.1. Unicode

2.1.2. EBNF

2.2. Language

2.1. Notational Conventions

2.1.1. Unicode

The specification makes reference to the Unicode character set which, at the time of writing, is at version 6.2.0. The specification often references specific Unicode characters, and does so using the standard notation U+NNNN, where N represents a hexadecimal digit. For example, U+03BB corresponds to the lowercase lambda symbol λ.

2.1.2. EBNF

The specification gives grammar definitions in ISO/IEC 14977:1996 Extended Backus-Naur form.

2.2. Language

The language understood by the com.io7m.jsx package can be defined by the following grammar:

2.2.2. Grammar (non-terminals)

expression =
    symbol
  | quoted_string
  | "(" , { expression } , ")" ;

expression_squares =
    symbol
  | quoted_string
  | "[" , { expression_squares } , "]"
  | "(" , { expression_squares } , ")" ;

The com.io7m.jsx lexer recognizes the sequences U+000D U+000A and U+000A as line terminators for the purposes of tracking line and column numbers for diagnostic messages. The lexer does not permit bare U+000D characters to appear outside of quoted strings.

Many systems that parse S-expressions allow for the use of square brackets to increase readability. For example:

2.2.5. Square brackets

(: map (→ (→ a b) (→ (list a) (list b))))

(: map (→ [→ a b] [→ (list a) (list b)]))

Note that the second version that uses square brackets is slightly easier to understand due to the square brackets more clearly indicating which of the nested lists are being terminated. The com.io7m.jsx lexer can optionally treat U+005B [ and U+005D ] as tokens, and the parser ensures that the use of the brackets is balanced with respect to ordinary parentheses as part of the grammar above. If square brackets are enabled, the language understood by the com.io7m.jsx package is defined by expression_squares. Otherwise, the language is defined by expression.

The terminals of the language are given by:

2.2.8. Grammar (terminals)

symbol_character =
  ? not (")" | "(" | U+0022 | WHITESPACE) ? ;

symbol_character_squares =
  ? not (")" | "(" | "[" | "]" | U+0022 | WHITESPACE) ? ;

symbol =
  symbol_character , { symbol_character } ;

quoted_character =
  ? not U+0022 ? ;

quoted_string =
  (quoted_character | escape) , { (quoted_character | escape) } ;

escape =
    escape_carriage
  | escape_newline
  | escape_tab
  | escape_quote
  | escape_unicode4
  | escape_unicode8 ;

escape_carriage =
  "\r" ;

escape_newline =
  "\n" ;

escape_quote =
  "\" , U+0022 ;

escape_tab =
  "\t" ;

escape_unicode4 =
  "\u" ,
  hex_digit , hex_digit , hex_digit , hex_digit ;

escape_unicode8 =
  "\u" ,
  hex_digit , hex_digit , hex_digit , hex_digit ,
  hex_digit , hex_digit , hex_digit , hex_digit ;

hex_digit =
  "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0" |
  "a" | "A" | "b" | "B" | "c" | "C" | "d" | "D" | "e" | "E" | "f" | "F" ;

Due to limitations in the EBNF format, the definitions for symbol_character and quoted_character cannot be expressed directly.

Informally, the symbol_character rule should be understood to specify any Unicode character that is not whitespace, is not U+0028 (, is not U+0029 ), and is not U+0022 ".

If square brackets are enabled, the symbol_character_squares rule should be understood to replace the symbol_character rule.

The quoted_character rule should be understood to specify any character that is not not U+0022 ".

Quoted strings may contain escape codes that are transformed to specific characters during lexing.

2.2.14. Escape Codes

Code | Resulting Character | Comment
\" | U+0022 | Double quote
\\ | U+005C | Backslash
\r | U+000D | Carriage return
\n | U+000A | Line feed
\t | U+0009 | Horizontal tab
\uNNNN | U+NNNN | Unicode character NNNN (where N is a hexadecimal digit)
\UNNNNNNNN | U+NNNNNNNN | Unicode character NNNNNNNN (where N is a hexadecimal digit)