Sym
Module
signature SYM
structure Sym
:> SYM
This module provides the abstract type of Forlan symbols. (This abstract type is actually defined by the lexical analysis module, Lex
, but most Forlan users will never have to directly use Lex
.)
type basic = Lex.basic
val charToBasic : char -> basic
val basicToChar : basic -> char
type sym = Lex.sym
datatype top
= Basic of basic
| Compound of sym option list
val fromTop : top -> sym
val toTop : sym -> top
val inputFromLabToks : (int * Lex.tok) list -> sym * (int * Lex.tok) list
val fromString : string -> sym
val input : string -> sym
val toPP : sym -> PP.pp
val toString : sym -> string
val output : string * sym -> unit
val compare : sym Sort.total_ordering
val equal : sym * sym -> bool
val size : sym -> int
val jforlanValidate : string -> unit
val jforlanPretty : string -> unit
type basic = Lex.basic
charToBasic c
c
is a digit, lowercase letter or uppercase letter, then charToBasic
returns c
. Otherwise, issues an error message.
basicToChar c
c
.
type sym = Lex.sym
,
) and angle brackets (<
and >
) such that:
c
, [c]
is a symbol;
n
, and all x1
... xn
that are symbols or [,]
,
[<] @ x1 @ ... @ xn @ [>]is a symbol.
The concrete syntax for a symbol [c1, ..., cn]
is c1 ... cn
. E.g., [<, i, d, >]
is written as <id>
.
The type could be implemented using lists, but is actually implemented in a way that makes the construction and destruction of symbols more efficient. See fromTop
and toTop
.
datatype top
= Basic of basic
| Compound of sym option list
fromTop top
top
. If top
is BasicSymTop b
, then fromTop
returns [b]
. Otherwise, top
looks like CompoundSymTop xs
, in which case the symbol returned by fromTop
consists of the result of appending an initial [<]
, followed by the lists corresponding to xs
, followed by a closing [>]
. Each occurrence of NONE
in xs
is turned into [,]
. And each occurrence of the form SOME a
is turned into a
.
toTop a
sym_top
describing the top-level structure of a
. If the only element of a
is a digit or letter, then toTop
returns BasicSymTop b
, where b
is that digit or letter. Otherwise a
is the result of appending the elements of a list of lists xs
, where the first and last elements of xs
are [<]
and [>]
, respectively, and each of the remaining elements are either [,]
or are single symbols. In this case, toTop
returns CompoundSymTop ys
, where ys
is the value of type sym option list
corresponding to all but the first and last elements ([<]
and [>]
) of xs
, in the following way. [,]
is turned into NONE
. And a symbol x
is turned into SOME x
.
inputFromLabToks lts
lts
, returning the pair of that symbol with the rest of lts
. Issues an error message if lts
doesn't begin with a symbol.
fromString s
s
.
input fil
fil
.
toPP a
a
.
toString a
a
to a string.
output(fil, a)
a
to the file fil
.
compare(a, b)
a
and b
, first according to length, and then lexicographically, using the ordering in which the comma (,
) comes first, followed by the digits (in ascending order), followed by the lowercase letters (in ascending order), followed by the uppercase letters (in ascending order), followed the open angle bracket (<
), followed by the close angle bracket (>
).
equal(a, b)
a
and b
are equal.
sizeSym a
a
.
jforlanValidate
jforlanPretty
Forlan Version 4.12
Copyright © 2019 Alley Stoughton