Модуль Parsetree
module Parsetree: sig .. end
Дерево абстрактной синтаксической структуры, полученное в результате парсинга
Предупреждение: этот модуль нестабилен и является частью compiler-libs.
type constant =
|
| Pconst_integer of
| (* |
Целочисленные константы, такие как Суффиксы |
*) |
|
| Pconst_char of
| (* |
Символы, такие как |
*) |
|
| Pconst_string of
| (* |
Строковые константы, такие как Диапазон расположения охватывает содержимое строки без разделителей. |
*) |
|
| Pconst_float of
| (* |
Константы с плавающей точкой, такие как Суффиксы |
*) |
type location_stack = Location.t list
Точки расширения
type attribute = {
attr_name :
| |
attr_payload :
| |
attr_loc :
|
} Атрибуты, такие как [@id ARG] и [@@id ARG].
Контейнеры метаданных, передаваемые в рамках AST. Компилятор игнорирует неизвестные атрибуты.
type extension = string Asttypes.loc * payload
Точки расширения, такие как [%id ARG] and [%%id ARG].
Заполнитель подязыка — отклоняется типовой проверкой.
type attributes = attribute list
type payload =
|
| PStr of
| |||
|
| PSig of
| (* |
|
*) |
|
| PTyp of
| (* |
|
*) |
|
| PPat of
| (* |
|
*) |
Ядро языка
Выражения типов
type core_type = {
ptyp_desc :
| ||||
ptyp_loc :
| ||||
ptyp_loc_stack :
| ||||
ptyp_attributes :
| (* |
|
*) |
} type core_type_desc =
|
| Ptyp_any
| (* |
|
*) |
|
| Ptyp_var of
| (* |
Переменная типа, например |
*) |
|
| Ptyp_arrow of
| (* |
*) | |
|
| Ptyp_tuple of
| (* |
Инвариант: |
*) |
|
| Ptyp_constr of
| (* |
|
*) |
|
| Ptyp_object of
| (* |
*) | |
|
| Ptyp_class of
| (* |
|
*) |
|
| Ptyp_alias of
| (* |
|
*) |
|
| Ptyp_variant of
| (* |
*) | |
|
| Ptyp_poly of
| (* |
Может появляться только в следующих контекстах:
|
*) |
|
| Ptyp_package of
| (* |
|
*) |
|
| Ptyp_open of
| (* |
|
*) |
|
| Ptyp_extension of
| (* |
|
*) |
type package_type = Longident.t Asttypes.loc * (Longident.t Asttypes.loc * core_type) list
В качестве типизированных значений Parsetree.package_type:
-
(S, [])представляет(module S), -
(S, [(t1, T1) ; ... ; (tn, Tn)])представляет(module S with type t1 = T1 and ... and tn = Tn).
type row_field = {
prf_desc :
| |
prf_loc :
| |
prf_attributes :
|
} type row_field_desc =
|
| Rtag of
| (* |
|
*) |
|
| Rinherit of
| (* |
|
*) |
type object_field = {
pof_desc :
| |
pof_loc :
| |
pof_attributes :
|
} type object_field_desc =
|
| Otag of
|
|
| Oinherit of
|
Шаблоны
type pattern = {
ppat_desc :
| ||||
ppat_loc :
| ||||
ppat_loc_stack :
| ||||
ppat_attributes :
| (* |
|
*) |
} type pattern_desc =
|
| Ppat_any
| (* |
Шаблон |
*) |
|
| Ppat_var of
| (* |
Переменной шаблон, например, |
*) |
|
| Ppat_alias of
| (* |
Псевдоним шаблона, например, |
*) |
|
| Ppat_constant of
| (* |
Шаблоны, такие как |
*) |
|
| Ppat_interval of
| (* |
Шаблоны, такие как Другие формы интервалов распознаются анализатором, но отклоняются проверяющим типов. |
*) |
|
| Ppat_tuple of
| (* |
Шаблоны Инвариант: |
*) |
|
| Ppat_construct of
| (* |
|
*) |
|
| Ppat_variant of
| (* |
|
*) |
|
| Ppat_record of
| (* |
*) | |
|
| Ppat_array of
| (* |
Шаблон |
*) |
|
| Ppat_or of
| (* |
Шаблон |
*) |
|
| Ppat_constraint of
| (* |
Шаблон |
*) |
|
| Ppat_type of
| (* |
Шаблон |
*) |
|
| Ppat_lazy of
| (* |
Шаблон |
*) |
|
| Ppat_unpack of
| (* |
Примечание: |
*) |
|
| Ppat_exception of
| (* |
Шаблон |
*) |
|
| Ppat_extension of
| (* |
Шаблон |
*) |
|
| Ppat_open of
| (* |
Шаблон |
*) |
Выражения значений
type expression = {
pexp_desc :
| ||||
pexp_loc :
| ||||
pexp_loc_stack :
| ||||
pexp_attributes :
| (* |
|
*) |
} type expression_desc =
|
| Pexp_ident of
| (* |
Идентификаторы, такие как |
*) |
|
| Pexp_constant of
| (* |
Константные выражения, такие как |
*) |
|
| Pexp_let of
| (* |
|
*) |
|
| Pexp_function of
| (* |
Функция должна иметь параметры. |
*) |
|
| Pexp_apply of
| (* |
*) | |
|
| Pexp_match of
| (* |
|
*) |
|
| Pexp_try of
| (* |
|
*) |
|
| Pexp_tuple of
| (* |
Выражения Инвариант: |
*) |
|
| Pexp_construct of
| (* |
|
*) |
|
| Pexp_variant of
| (* |
|
*) |
|
| Pexp_record of
| (* |
Инвариант: |
*) |
|
| Pexp_field of
| (* |
|
*) |
|
| Pexp_setfield of
| (* |
|
*) |
|
| Pexp_array of
| (* |
|
*) |
|
| Pexp_ifthenelse of
| (* |
|
*) |
|
| Pexp_sequence of
| (* |
|
*) |
|
| Pexp_while of
| (* |
|
*) |
|
| Pexp_for of
| (* |
*) | |
|
| Pexp_constraint of
| (* |
|
*) |
|
| Pexp_coerce of
| (* |
|
*) |
|
| Pexp_send of
| (* |
|
*) |
|
| Pexp_new of
| (* |
|
*) |
|
| Pexp_setinstvar of
| (* |
|
*) |
|
| Pexp_override of
| (* |
|
*) |
|
| Pexp_letmodule of
| (* |
|
*) |
|
| Pexp_letexception of
| (* |
|
*) |
|
| Pexp_assert of
| (* |
Примечание: |
*) |
|
| Pexp_lazy of
| (* |
|
*) |
|
| Pexp_poly of
| (* |
Используется для тел методов. Может использоваться только как выражение под |
*) |
|
| Pexp_object of
| (* |
|
*) |
|
| Pexp_newtype of
| (* |
|
*) |
|
| Pexp_pack of
| (* |
|
*) |
|
| Pexp_open of
| (* |
-
|
*) |
|
| Pexp_letop of
| (* |
-
|
*) |
|
| Pexp_extension of
| (* |
|
*) |
|
| Pexp_unreachable
| (* |
|
*) |
type case = {
pc_lhs :
| |
pc_guard :
| |
pc_rhs :
|
} Значения типа Parsetree.case представляют (P -> E) или (P when E0 -> E)
type letop = {
let_ :
| |
ands :
| |
body :
|
} type binding_op = {
pbop_op :
| |
pbop_pat :
| |
pbop_exp :
| |
pbop_loc :
|
} type function_param_desc =
|
| Pparam_val of
| (* |
Примечание: Если |
*) |
|
| Pparam_newtype of
| (* |
Несколько параметров [ { pparam_kind = Pparam_newtype a; pparam_loc = loc1 };
{ pparam_kind = Pparam_newtype b; pparam_loc = loc2 };
{ pparam_kind = Pparam_newtype c; pparam_loc = loc3 };
]
Здесь первый loc |
*) |
type function_param = {
pparam_loc :
| |
pparam_desc :
|
} type function_body =
|
| Pfunction_body of
| |||
|
| Pfunction_cases of
| (* |
В |
*) |
См. комментарий к Pexp_function.
type type_constraint =
|
| Pconstraint of
| |||
|
| Pcoerce of
| (* |
См. комментарий к |
*) |
Описание значений
type value_description = {
pval_name :
| ||||
pval_type :
| ||||
pval_prim :
| ||||
pval_attributes :
| (* |
|
*) | |
pval_loc :
|
} Значения типа Parsetree.value_description представляют:
Объявления типов
type type_declaration = {
ptype_name :
| ||||
ptype_params :
| (* |
|
*) | |
ptype_cstrs :
| (* |
|
*) | |
ptype_kind :
| ||||
ptype_private :
| (* |
для |
*) | |
ptype_manifest :
| (* |
представляет |
*) | |
ptype_attributes :
| (* |
|
*) | |
ptype_loc :
|
} Вот объявления типов и их представление для различных значений ptype_kind и ptype_manifest:
-
type tкогдаtype_kindявляетсяPtype_abstract, иmanifestравноNone, -
type t = T0когдаtype_kindявляетсяPtype_abstract, иmanifestравноSome T0, -
type t = C of T | ...когдаtype_kindявляетсяPtype_variant, иmanifestравноNone, -
type t = T0 = C of T | ...когдаtype_kindявляетсяPtype_variant, иmanifestравноSome T0, -
type t = {l: T; ...}когдаtype_kindявляетсяPtype_record, иmanifestравноNone, -
type t = T0 = {l : T; ...}когдаtype_kindявляетсяPtype_record, иmanifestравноSome T0, -
type t = ..когдаtype_kindявляетсяPtype_open, иmanifestравноNone.
type type_kind =
|
| Ptype_abstract
| |||
|
| Ptype_variant of
| |||
|
| Ptype_record of
| (* |
Инвариант: непустой список |
*) |
|
| Ptype_open
|
type label_declaration = {
pld_name :
| ||||
pld_mutable :
| ||||
pld_type :
| ||||
pld_loc :
| ||||
pld_attributes :
| (* |
|
*) |
} - { ...; l: T; ... } когда pld_mutable имеет значение Immutable,
-
{ ...; mutable l: T; ... }когдаpld_mutableимеет значениеMutable.
Примечание: T может быть Ptyp_poly.
type constructor_declaration = {
pcd_name :
| ||||
pcd_vars :
| ||||
pcd_args :
| ||||
pcd_res :
| ||||
pcd_loc :
| ||||
pcd_attributes :
| (* |
|
*) |
} type constructor_arguments =
|
| Pcstr_tuple of
| |||
|
| Pcstr_record of
| (* |
Значения типа
|
*) |
type type_extension = {
ptyext_path :
| ||||
ptyext_params :
| ||||
ptyext_constructors :
| ||||
ptyext_private :
| ||||
ptyext_loc :
| ||||
ptyext_attributes :
| (* |
... |
*) |
} Определение новых конструкторов расширений для расширенного типа суммы t (type t += ...).
type extension_constructor = {
pext_name :
| ||||
pext_kind :
| ||||
pext_loc :
| ||||
pext_attributes :
| (* |
|
*) |
} type type_exception = {
ptyexn_constructor :
| ||||
ptyexn_loc :
| ||||
ptyexn_attributes :
| (* |
|
*) |
} Определение нового исключения (exception E).
type extension_constructor_kind =
|
| Pext_decl of
| (* |
|
*) |
|
| Pext_rebind of
| (* |
|
*) |
Класс язык
Типы выражений для языка классов
type class_type = {
pcty_desc :
| ||||
pcty_loc :
| ||||
pcty_attributes :
| (* |
|
*) |
} type class_type_desc =
|
| Pcty_constr of
| (* |
-
|
*) |
|
| Pcty_signature of
| (* |
|
*) |
|
| Pcty_arrow of
| (* |
|
*) |
|
| Pcty_extension of
| (* |
|
*) |
|
| Pcty_open of
| (* |
|
*) |
type class_signature = {
pcsig_self :
| |
pcsig_fields :
|
} Значения типа class_signature представляют:
object('selfpat) ... end-
object ... endкогдаpcsig_selfравенPtyp_any
type class_type_field = {
pctf_desc :
| ||||
pctf_loc :
| ||||
pctf_attributes :
| (* |
|
*) |
} type class_type_field_desc =
|
| Pctf_inherit of
| (* |
|
*) |
|
| Pctf_val of
| (* |
|
*) |
|
| Pctf_method of
| (* |
Примечание: |
*) |
|
| Pctf_constraint of
| (* |
|
*) |
|
| Pctf_attribute of
| (* |
|
*) |
|
| Pctf_extension of
| (* |
|
*) |
type 'a class_infos = {
pci_virt :
| ||||
pci_params :
| ||||
pci_name :
| ||||
pci_expr :
| ||||
pci_loc :
| ||||
pci_attributes :
| (* |
|
*) |
} Значения типа class_expr class_infos представляют:
class c = ...class ['a1,...,'an] c = ...class virtual c = ...
Они также используются для объявления "типа класса".
type class_description = class_type class_infos
type class_type_declaration = class_type class_infos
Выражения значений для языка классов
type class_expr = {
pcl_desc :
| ||||
pcl_loc :
| ||||
pcl_attributes :
| (* |
|
*) |
} type class_expr_desc =
|
| Pcl_constr of
| (* |
|
*) |
|
| Pcl_structure of
| (* |
|
*) |
|
| Pcl_fun of
| (* |
|
*) |
|
| Pcl_apply of
| (* |
Инвариант: |
*) |
|
| Pcl_let of
| (* |
|
*) |
|
| Pcl_constraint of
| (* |
|
*) |
|
| Pcl_extension of
| (* |
|
*) |
|
| Pcl_open of
| (* |
|
*) |
type class_structure = {
pcstr_self :
| |
pcstr_fields :
|
} Значения типа Parsetree.class_structure представляют:
object(selfpat) ... end-
object ... endкогдаpcstr_selfравенPpat_any
type class_field = {
pcf_desc :
| ||||
pcf_loc :
| ||||
pcf_attributes :
| (* |
|
*) |
} type class_field_desc =
|
| Pcf_inherit of
| (* |
*) | |
|
| Pcf_val of
| (* |
|
*) |
|
| Pcf_method of
| (* |
*) | |
|
| Pcf_constraint of
| (* |
|
*) |
|
| Pcf_initializer of
| (* |
|
*) |
|
| Pcf_attribute of
| (* |
|
*) |
|
| Pcf_extension of
| (* |
|
*) |
type class_field_kind =
|
| Cfk_virtual of
|
|
| Cfk_concrete of
|
type class_declaration = class_expr class_infos
Язык модуля
Типы выражений для языка модуля
type module_type = {
pmty_desc :
| ||||
pmty_loc :
| ||||
pmty_attributes :
| (* |
|
*) |
} type module_type_desc =
|
| Pmty_ident of
| (* |
|
*) |
|
| Pmty_signature of
| (* |
|
*) |
|
| Pmty_functor of
| (* |
|
*) |
|
| Pmty_with of
| (* |
|
*) |
|
| Pmty_typeof of
| (* |
|
*) |
|
| Pmty_extension of
| (* |
|
*) |
|
| Pmty_alias of
| (* |
|
*) |
type functor_parameter =
|
| Unit
| (* |
|
*) |
|
| Named of
| (* |
|
*) |
type signature = signature_item list
type signature_item = {
psig_desc :
| |
psig_loc :
|
} type signature_item_desc =
|
| Psig_value of
| (* |
-
|
*) |
|
| Psig_type of
| (* |
|
*) |
|
| Psig_typesubst of
| (* |
|
*) |
|
| Psig_typext of
| (* |
|
*) |
|
| Psig_exception of
| (* |
|
*) |
|
| Psig_module of
| (* |
|
*) |
|
| Psig_modsubst of
| (* |
|
*) |
|
| Psig_recmodule of
| (* |
|
*) |
|
| Psig_modtype of
| (* |
|
*) |
|
| Psig_modtypesubst of
| (* |
|
*) |
|
| Psig_open of
| (* |
|
*) |
|
| Psig_include of
| (* |
|
*) |
|
| Psig_class of
| (* |
|
*) |
|
| Psig_class_type of
| (* |
|
*) |
|
| Psig_attribute of
| (* |
|
*) |
|
| Psig_extension of
| (* |
|
*) |
type module_declaration = {
pmd_name :
| ||||
pmd_type :
| ||||
pmd_attributes :
| (* |
|
*) | |
pmd_loc :
|
} Значения типа module_declaration представляют S : MT
type module_substitution = {
pms_name :
| ||||
pms_manifest :
| ||||
pms_attributes :
| (* |
|
*) | |
pms_loc :
|
} Значения типа module_substitution представляют S := M
type module_type_declaration = {
pmtd_name :
| ||||
pmtd_type :
| ||||
pmtd_attributes :
| (* |
|
*) | |
pmtd_loc :
|
} Значения типа module_type_declaration представляют:
-
S = MT, -
Sдля объявления абстрактного модульного типа, когдаpmtd_typeравноNone.
type 'a open_infos = {
popen_expr :
| |
popen_override :
| |
popen_loc :
| |
popen_attributes :
|
} Значения типа 'a open_infos представляют:
-
open! Xкогдаpopen_overrideимеет значениеOverride(подавляет предупреждение о затенении идентификатора) -
open Xкогдаpopen_overrideимеет значениеFresh
type open_description = Longident.t Asttypes.loc open_infos
Значения типа open_description представляют:
open M.Nopen M(N).O
type open_declaration = module_expr open_infos
Значения типа open_declaration представляют:
open M.Nopen M(N).Oopen struct ... end
type 'a include_infos = {
pincl_mod :
| |
pincl_loc :
| |
pincl_attributes :
|
} type include_description = module_type include_infos
Значения типа include_description представляют include MT
type include_declaration = module_expr include_infos
Значения типа include_declaration представляют include ME
type with_constraint =
|
| Pwith_type of
| (* |
Примечание: последний компонент longident должен соответствовать имени type_declaration. |
*) |
|
| Pwith_module of
| (* |
|
*) |
|
| Pwith_modtype of
| (* |
|
*) |
|
| Pwith_modtypesubst of
| (* |
|
*) |
|
| Pwith_typesubst of
| (* |
|
*) |
|
| Pwith_modsubst of
| (* |
|
*) |
Выражения значений для языка модулей
type module_expr = {
pmod_desc :
| ||||
pmod_loc :
| ||||
pmod_attributes :
| (* |
|
*) |
} type module_expr_desc =
|
| Pmod_ident of
| (* |
|
*) |
|
| Pmod_structure of
| (* |
|
*) |
|
| Pmod_functor of
| (* |
|
*) |
|
| Pmod_apply of
| (* |
|
*) |
|
| Pmod_apply_unit of
| (* |
|
*) |
|
| Pmod_constraint of
| (* |
|
*) |
|
| Pmod_unpack of
| (* |
|
*) |
|
| Pmod_extension of
| (* |
|
*) |
type structure = structure_item list
type structure_item = {
pstr_desc :
| |
pstr_loc :
|
} type structure_item_desc =
|
| Pstr_eval of
| (* |
|
*) |
|
| Pstr_value of
| (* |
|
*) |
|
| Pstr_primitive of
| (* |
-
|
*) |
|
| Pstr_type of
| (* |
|
*) |
|
| Pstr_typext of
| (* |
|
*) |
|
| Pstr_exception of
| (* |
-
|
*) |
|
| Pstr_module of
| (* |
|
*) |
|
| Pstr_recmodule of
| (* |
|
*) |
|
| Pstr_modtype of
| (* |
|
*) |
|
| Pstr_open of
| (* |
|
*) |
|
| Pstr_class of
| (* |
|
*) |
|
| Pstr_class_type of
| (* |
|
*) |
|
| Pstr_include of
| (* |
|
*) |
|
| Pstr_attribute of
| (* |
|
*) |
|
| Pstr_extension of
| (* |
|
*) |
type value_constraint =
|
| Pvc_constraint of
| |||||||
|
| Pvc_coercion of
| (* |
-
|
*) |
type value_binding = {
pvb_pat :
| |
pvb_expr :
| |
pvb_constraint :
| |
pvb_attributes :
| |
pvb_loc :
|
} let pat : type_constraint = exp
type module_binding = {
pmb_name :
| |
pmb_expr :
| |
pmb_attributes :
| |
pmb_loc :
|
} Значения типа module_binding представляют module X = ME
Уровень верхнего уровня
Фразы верхнего уровня
type toplevel_phrase =
|
| Ptop_def of
| |||
|
| Ptop_dir of
| (* |
|
*) |
type toplevel_directive = {
pdir_name :
| |
pdir_arg :
| |
pdir_loc :
|
} type directive_argument = {
pdira_desc :
| |
pdira_loc :
|
} type directive_argument_desc =
|
| Pdir_string of
|
|
| Pdir_int of
|
|
| Pdir_ident of
|
|
| Pdir_bool of
|
© 1995-2024 INRIA.
https://ocaml.org/manual/5.2/api/compilerlibref/Parsetree.html