package forester
Install
Dune Dependency
Authors
Maintainers
Sources
md5=3512b493a31b0d1073ba4e48e8058493
sha512=b6e5ad2f86132d1874cb943546375e2f1b987a0c65628d71f17827f1ff7435df476c86fb135b34b3ff302f99ea54a21b90730257e12aa41cce170fae57c422b0
doc/forester.core/Core/Range/index.html
Module Core.Range
Source
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