module WhiteSpace: sig
.. end
Convert a whitespace file into a brace file.
Convert a whitespace file into a brace file.
val wsfail : string -> 'a
Gracefully tell the programmer that they done goofed
Parameters: |
msg |
: |
string
The descriptive error message to convey to the programmer
|
|
val indenting_space : Parser.token list -> Parser.token list
Only allow spacing that is at the start of a line
Returns a list of tokens where the only white space is indentation, newlines,
and colons (which count as a newline as it must be followed by them)
val despace_brace : Parser.token list -> Parser.token list
Between LBRACE and RBRACE we ignore spaces and newlines; colons are errors in this context.
It's not necessary that this be done after the above, but it is recommended.
Returns A slightly slimmer program
Parameters: |
program |
: |
Parser.token list
A program in the form of a list of tokens
|
|
val trim_lines : Parser.token list -> Parser.token list
Remove empty indentation -- SPACE followed by COLON or NEWLINE
Returns A program without superfluous indentation
val squeeze_lines : Parser.token list -> Parser.token list
Remove consecutive newlines
Returns A program without consecutive newlines
val spacing : Parser.token list -> int * Parser.token list
Remove the initial space from a line but semantically note it
Returns an ordered pair of the number of spaces at the beginning
of the line and the tokens in the line
val tokens_to_lines : Parser.token list -> (int * Parser.token list * bool) list
Remove spaces, newlines, and colons but semantically note their presence.
Returns a list of triples, one for each line. Each triple's first item is
the number of spaces at the beginning of the line; the second item is the
tokens in the line; the third is whether the line ended in a colon.
Parameters: |
program |
: |
Parser.token list
A full program (transformed by the above pipeline)
|
|
val merge_lines : ('a * 'b list * bool) list -> ('a * 'b list * bool) list
Merge line continuatons given output from tokens_to_lines.
Line n+1 continues n if n does not end in a colon and n+1 is more
indented than n (or if line n is a continuation and they are both
equally indented).
Returns The lines of the program with whitespace collapsed
Parameters: |
program_lines |
: |
('a * 'b list * bool) list
The individual lines of the program
|
|
val needs_semi : Parser.token list -> bool
Check if a given line needs a semicolon at the end
val block_merge : ('a * Parser.token list * bool) list -> ('a * Parser.token list * bool) list
Build a block. Consecutive lines of the same indentation with only the last ending
in a colon are a `block'. Blocks are just `lines' merged together but joined with
a semi colon when necessary.
Returns A list of blocks
Parameters: |
lines |
: |
('a * Parser.token list * bool) list
The full set of lines
|
|
val terminate_blocks : ('a * Parser.token list * bool) list -> ('a * Parser.token list * bool) list
Make sure every line is terminated with a semi-colon when necessary
val arrange : 'a -> 'a list -> Parser.token list -> 'a list * Parser.token list
Pops the stack and adds rbraces when necessary
val space_to_brace : ('a * Parser.token list * bool) list -> Parser.token list
Take results of pipeline and finally adds braces. If blocks are merged
then either consecutive lines differ in scope or there are colons.
so now everything should be easy peasy (lemon squeezy).
val drop_eof : Parser.token list -> Parser.token list
Drop the EOF from a stream of tokens, failing if not possible
val append_eof : Parser.token list -> Parser.token list
Append an eof token to a program
val convert : Parser.token list -> Parser.token list
Run the entire pipeline
val lextoks : Parser.token list -> 'a -> Parser.token
A function to act like a lexfun