package pyre-ast

  1. Overview
  2. Docs

This module provides a type that represents Python constant value.

type 'a t = private {
  1. none : 'a;
    (*

    Represents the value None.

    *)
  2. false_ : 'a;
    (*

    Represents the value False.

    *)
  3. true_ : 'a;
    (*

    Represents the value True.

    *)
  4. ellipsis : 'a;
    (*

    Represents the value ....

    *)
  5. integer : int -> 'a;
    (*

    Represents integer literals whose value can be represented by OCaml int type (e.g. 42).

    *)
  6. big_integer : string -> 'a;
    (*

    Represents integer literals whose value cannot be represented by OCaml int type. The integer will be stored as a string instead.

    *)
  7. float_ : float -> 'a;
    (*

    Represents Python float literals (e.g. 4.2).

    *)
  8. complex : float -> 'a;
    (*

    Represents Python complex literals (e.g. 4.2j). The float argument is the imaginary part of the complex number.

    The reason why we do not need to keep track of the real part is that in Python, complex numbers with non-zero real part are represented as compound expressions (e.g. 1+2j will be parsed as a binary expression that adds up constant 1 and 2j) as opposed to literals

    *)
  9. string_ : string -> 'a;
    (*

    Represents Python string literals (e.g. "derp").

    At OCaml level, the value of the string literal is a UTF-8 decoded byte array of the original string literal in Python. If the original literal cannot be UTF-8 decoded, the backslahreplace error handler is used, which replaces the un-decodable parts with backslashed escape sequence.

    Note that due to technical limitations, \N escape sequence translation is not supported: String literal "\N{FOO}" will be treated as an ascii string of length 7 as opposed to a Unicode string of length 1.

    *)
  10. byte_string : string -> 'a;
    (*

    Represents Python string literals (e.g. b"derp").

    Unlike non-ascii identifiers, non-ascii bytestring literals can be parsed properly by this library. That also means it has no trouble handling strings with embedded null bytes.

    *)
}
val make : none:'a -> false_:'a -> true_:'a -> ellipsis:'a -> integer:(int -> 'a) -> big_integer:(string -> 'a) -> float_:(float -> 'a) -> complex:(float -> 'a) -> string_:(string -> 'a) -> byte_string:(string -> 'a) -> unit -> 'a t

Constructor of t.

OCaml

Innovation. Community. Security.