You are looking at historical revision 19700 of this page. It may differ significantly from its current revision.

honu

Usage

 (require-extension honu)

Author

Felix Winkelmann

Documentation

This is a parser for "Honu" syntax.

Honu syntax resembles Java, instead of Scheme. Like Scheme, however, Honu has no fixed syntax. Honu supports extensibility through macros and a base syntax of H-expressions, which are analogous to S-expressions.

Ignoring whitespace, an H-expression is either

Whitespace for H-expressions is as in Scheme: any character for which char-whitespace? returns true counts as a whitespace.

Numbers

The syntax for Honu numbers is the same as for Java. The S-expression encoding of a particular H-expression number is the obvious Scheme number.

Identifiers

The syntax for Honu identifiers is the union of Java identifiers plus semicolon (;), comma (,), and a set of operator identifiers. An operator identifier is any combination of the following characters:

 + - _ = ? : < > . ! % ^ & * / ~ |

The S-expression encoding of an H-expression identifier is the obvious Scheme symbol. Input is parsed to form maximally long identifiers. For example, the input int->int; is parsed as four H-expressions:

int, ->, int and ;.

Strings

The syntax for an H-expression string is exactly the same as for an S-expression string, and an H-expression string is represented by the obvious Scheme string.

Characters

The syntax for an H-expression character is the same as for an H-expression string that has a single content character, except that a single quote ('}) surrounds the character instead of double quotes ()). The S-expression representation of an H-expression character is the obvious Scheme character.

Parentheses, Brackets, and Braces

A parenthesized (), bracketed [], or braced {} H-expression sequence is represented by a Scheme list. The first element of the list is #%parens for a parenthesized sequence, #%brackets for a brackets sequence, or #%braces for a braced sequence. The remaining elements are the Scheme representation for the parenthesized, bracketed, or braced H-expressions in order.

Comments

An H-expression comment starts with either // or /* . In the former case, the comment runs until a linefeed or return. In the second case, the comment runs until */ , but /* .... */ comments can be nested. Comments are treated like whitespace.

#; starts an H-expression comment, as in Scheme. It is followed by an H-expression to be treated as whitespace. Note that #; is equivalent to #sx#;#hx.

Interface

read-honu
[procedure] (read-honu [PORT [SHOW-LINE-NUMBERS [WRAP]]])

Reads a single honu expression from PORT, which defaults to the value of (current-input-port) . If SHOW-LINE-NUMBERS is given and true, then parsing errors will report the offending line-number (as obtained by port-position. The optional argument WRAP may be given to wrap each read item into a user-definable structure, or to perform user-specific conversion. WRAP is called for each H-expression with the expression and the current line number as arguments replacing the H-expression with the result.

License

Copyright (c) 2006-2009, Felix L. Winkelmann.  All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the Software),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Version history

1.5
ported to CHICKEN 4
1.4
added support for static linking
1.3
optional wrapper function argument
1.2
Fixed imcomplete floating-point number parsing
1.1
Better error message for unexpected closing parens/brackets
1.0
Initial release