package forester
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=1781b3d67f7ff4edaeb5cfdedba46b9e
sha512=879a583fd3ddf1cf44039fbe9a1d7280e9cc9cc0340506561dc8c6bb6b792db7c512a682d4d09d6c6b0b3b14940665573c9d94580c9ce0a87ee05822fbe4c229
doc/forester.core/Core/Range/index.html
Module Core.RangeSource
include module type of struct include Asai.Range end
Types
type string_source = Asai.Range.string_source = {title : string option;(*The title of a string source. A diagnostic handler can use the title of a string source in lieu of a file path.
*)content : string;(*The content of a string source
*)
}The string source of a position or a range.
type source = [ | `File of string(*A file source specified by its file path.
*)| `String of string_source(*A string (in-memory) source.
*)
]The source of a position or a range. The `String source can be used for representing inputs in REPL.
type position = Asai.Range.position = {source : source;(*The source (e.g., the file) that contains the position.
*)offset : int;(*The 0-indexed byte offset of the position relative to the beginning of the source.
*)start_of_line : int;(*The 0-indexed byte offset pointing to the start of the line that contains the position.
*)line_num : int;(*The 1-indexed line number of the line that contains the position.
*)
}The type of positions; this is isomorphic to Lexing.position, but with arguably better field names.
The abstract type of ranges.
An auxiliary type to package data with an optional range.
Ranges
make (beginning, ending) builds the range [beginning, ending) (not including the byte at the ending position) from a pair of positions beginning and ending. A range is empty if its beginning and ending positions are the same.
eof pos builds a special range referring to the end of the source. The input pos must be pointing at the end position; for example, if the position referring to a string source, pos.offset should be the length of the string.
view range returns a view of the range.
split range returning the pair of the beginning and ending positions of range. It is the left-inverse of make.
begin_line_num range returns the 1-indexed line number of the beginning position.
end_line_num range returns the 1-indexed line number of the ending position.
begin_offset range returns the 0-indexed offset of the (inclusive) beginning position.
end_offset range returns the 0-indexed offset of the (exclusive) ending position.
Other Helper Functions
title src gets the title of a string source or the path of a file source, or None if it does not exist.
Support of Lexing
of_lex_position pos converts an OCaml lexer position pos of type Lexing.position into a position. The input pos must be byte-indexed. (Therefore, the OCaml tool ocamllex is compatible, but the OCaml library sedlex is not because it uses Unicode code points.)
of_lex_range (begining, ending) takes a pair of OCaml lexer positions and creates a range. It is make (of_lex_position begining, of_lex_position ending).
of_lexbuf lexbuf constructs a range from the current lexeme that lexbuf points to. It is of_lex_range (Lexing.lexeme_start_p lexbuf, Lexing.lexeme_end_p lexbuf).
locate_lex ps v is a helper function to create a value annotated with a range. It is locate (Some (of_lex_range ps)) v and is designed to work with the OCaml parser generator Menhir. You can add the following code to your Menhir grammar to generate annotated data:
%inline
locate(X):
| e = X
{ Asai.Range.locate_lex $loc e }Debugging
Ugly printer for debugging