package pacomb

  1. Overview
  2. Docs
Parsing library based on combinators and ppx extension to write languages

Install

Dune Dependency

Authors

Maintainers

Sources

1.3.tar.gz
md5=e48dc9fae5b96632bd1de929a49af71c
sha512=e4bf5dcfb0d4c5225a81fffe8e74cd9c147221eb9c8278b05d22391da0e06c6997e5b9a83a6431d72829f07f402da2449778cfe0bd56e7e2d3c8e08bbc1a73d5

doc/pacomb/Pacomb/Input/index.html

Module Pacomb.InputSource

A module providing efficient input buffers with preprocessing.

Type

Sourcetype stream_infos =
  1. | File of {
    1. name : string;
    2. length : int;
    3. date : float;
    }
  2. | String of string
  3. | Stream

Information for a file for reopening

Sourcetype buffer

The abstract type for an input buffer.

Sourcetype infos

Type of fixed data attached to the buffer (like file name)

Sourceval infos : buffer -> infos

return the infos associated to a buffer

Sourceval phantom_infos : infos

dummy infos

Sourceval stream_infos : infos -> stream_infos

returns the stream_infos stored in infos

Sourceval filename : infos -> string

returns the filename if it exists, the empty string otherwise

utf8 infos return the unicode context in use for this file

Sourcetype idx

The abstract type position relative to the current buffer

Sourceval init_idx : idx

position at the beginning of a buffer

Sourcetype byte_pos

The abstract position relative to the beginning of buffer

Sourceval int_of_byte_pos : byte_pos -> int

convert byte_pos to natural number

Sourceval init_byte_pos : byte_pos

zero

Sourceval phantom_byte_pos : byte_pos

dummy value, to initiaize references for instance

Sourcetype spos = infos * byte_pos

Short (and quick) type for positions

Sourceval phantom_spos : spos

dummy value, to initiaize references for instance

Reading from a buffer

Sourceval read : buffer -> idx -> char * buffer * idx

read buf idx returns the character at position idx in the buffer buf, together with the new buffer and position. Read infinitely many '\255' at end of buffer

Sourceval sub : buffer -> idx -> int -> string

sub b i len returns len characters from position idx. If the end of buffer is reached, the string is filed with eof '\255'

Sourceval get : buffer -> idx -> char

get buf idx returns the character at position idx in the buffer buf.

Creating a buffer

Sourcetype context = Utf8.context
Sourceval from_file : ?utf8:context -> string -> buffer

from_file fn returns a buffer constructed using the file fn.

If utf8 is Utf8.UTF8 or Utf8.CJK_UTF8 (Utf8.ASCII is the default), positions are reported according to utf8. read is still reading bytes.

Getting line number and column number requires rescanning the file and if the file is not a regular file, it is kept in memory. Setting rescan to false avoid this, but only byte position and file name will be available.

Sourceval from_channel : ?utf8:context -> ?filename:string -> in_channel -> buffer

from_channel ~filename ch returns a buffer constructed using the channel ch. The optional filename is only used as a reference to the channel in error messages.

uft8 and rescan as in from_file.

Sourceval from_fd : ?utf8:context -> ?filename:string -> Unix.file_descr -> buffer

Same as above for file descriptor

Sourceval from_string : ?utf8:context -> string -> buffer

from_string ~filename str returns a buffer constructed using the string str. The optional filename is only used as a reference to the channel in error messages.

Buffer manipulation functions

Sourceval is_empty : buffer -> int -> bool

is_empty buf test whether the buffer buf is empty.

Sourceexception NoLineNorColumnNumber
Sourceval byte_pos : buffer -> idx -> byte_pos

position in bytes, regardless to utf8

Sourceval spos : buffer -> idx -> spos

get spos from buffer and idx, to get line_num and col_num if needed later.

Sourceval buffer_uid : buffer -> int

buffer_uid buf returns a unique identifier. Input.read does not change the uid. The uid is created when creating the initial buffer.

Sourceval buffer_equal : buffer -> buffer -> bool

buffer_eq b1 b2 tests the equality of b1 and b2.

Sourceval buffer_compare : buffer -> buffer -> int

buffer_compare b1 b2 compares b1 and b2.

Sourceval buffer_before : buffer -> int -> buffer -> int -> bool

buffer_before b1 i1 b2 i2 returns true if the position b1, i1 is before b2, i2. Gives meaningless result if b1 and b2 do not refer to the same file, i.e. do not have the same uid.

Sourcemodule Tbl : sig ... end

Table to associate value to positions in input buffers. The complexity of access in the table is O(ln(N)) where N is the number of tables.

OCaml

Innovation. Community. Security.