package atd
Install
Dune Dependency
Authors
-
MMartin Jambon <martin@mjambon.com>
-
RRudi Grinberg <rudi.grinberg@gmail.com>
-
MMartin Jambon <martin@r2c.dev>
-
MMartin Jambon <github@mjambon.com>
-
IIvan Jager <aij+git@mrph.org>
-
Ooleksiy <oleksiy.golovko@ahrefs.com>
-
DDavid Sheets <sheets@alum.mit.edu>
-
RRudi Grinberg <me@rgrinberg.com>
-
MMartin Jambon <martin@esper.com>
-
JJeff Meister <nanaki@gmail.com>
-
CCaio Wakamatsu <caio.wakamatsu@ahrefs.com>
-
CCarmelo Piccione <carmelo.piccione@gmail.com>
-
DDaniel Weil <danweil68@gmail.com>
-
EEgor Chemokhonenko <egor.chemohonenko@ahrefs.com>
-
Gabriel Scherer
-
RRaman Varabets <roman.vorobets@gmail.com>
-
Ttzm <frank@boldsolutions.de>
-
MMathieu Baudet <mathieubaudet@fb.com>
-
OOleksiy Golovko <alexei.golovko@gmail.com>
-
RRauan Mayemir <rauan@mayemir.io>
-
CCarmelo Piccione <cep1@solvuu.com>
-
JJohn Billings <john@monkeynut.org>
-
LLouis Roché <louis@louisroche.net>
-
BBrendan Long <self@brendanlong.com>
-
CChris Yocum <cyocum@gmail.com>
-
LLouis Roché (Ahrefs) <louis.roche@ahrefs.com>
-
LLouis Roché <louis.roche@ahrefs.com>
-
PPavel Antoshkin <pavel.antoshkin@ahrefs.com>
-
PPierre Boutillier <pierre.boutillier@laposte.net>
-
SShon Feder <shon.feder@key.me>
-
AAnurag Soni <anuragsoni.13@gmail.com>
-
AArjun Ravi Narayan <arjunravinarayan@gmail.com>
-
AAsya-kawai <kawai-toshiki@aintek.xyz>
-
CChristophe Troestler <christophe.Troestler@umons.ac.be>
-
Damien Doligez
-
DDaniel M <dan.mntg@gmail.com>
-
DDing Xiang Fei <dingxiangfei2009@protonmail.ch>
-
FFrançois Pottier <francois.pottier@inria.fr>
-
JJavier Chavarri <javier.chavarri@gmail.com>
-
KKate <kit.ty.kate@disroot.org>
-
LLouis <louis.roche@ahrefs.com>
-
LLouis Roché <louis@cryptosense.com>
-
RRaman Varabets <raman+git@ahrefs.com>
-
SStephane Legrand <slegrand45@gmail.com>
-
VVincent Bernardoff <vb@luminar.eu.org>
-
Hhaoyang <haoyang@esper.co>
-
Ppmundkur <prashanth.mundkur@gmail.com>
-
Yygrek <ygrek@autistici.org>
Maintainers
Sources
sha256=84d15eefa1b0c23823484eaadc984b58063de74d42004c5a44795da94597c4cb
sha512=ba03e00dc34666a06f0fe798d5c145a0ebe619c823f88c50a0e7963e12d13f7041baf3a03544be882f473daf3b0bf6238ef42fb5e83ba504dda2b7e41fb8bc36
doc/atd/Atd/Annot/index.html
Module Atd.Annot
Source
Utilities for interpreting annotations of type Ast.annot
Sample annotation in ATD syntax with legend:
section a section b ----------- ------ <a a1="x1"> <b b1> | | | | | | | +- field without a value | | | | | +- field value | | | +- field name | +- section name
The following rules must be followed for a proper use of this module:
- There may not be two sections with the same name. The
merge
function can be used to merge sections. - Section order doesn't matter as long as section names are unique.
- Field names within a section should be unique. If not, only the first occurrence of each field is meaningful.
- Field values may be arbitrary strings.
has_field section_names field_name annotations
returns true if at least one section exists with a name in section_names
and one of its fields named field_name
.
Each section should be unique.
get_flag section_names field_name
looks sequentially into the sections specified by section_names
for a field named field_name
. If no such field can be found in any section, the result is false
. Otherwise, the search stops with the first field matching one of the section names and the field name. If the field has no associated value, the result is true
. If the field value is "true"
then true
is returned. Likewise, if the field value is "false"
then false
is returned. If the field value is anything else, a Failure
exception is raised.
Each section should be unique.
Given the following annotations in the ATD syntax noted a
:
<ocaml openin="false"> <ocaml_312 openin>
We obtain the following results:
# get_flag \["ocaml_312"; "ocaml"\] "openin" a;; \- : true # get_flag \["ocaml_311"; "ocaml"\] "openin" a;; \- : false # get_flag \["ocaml_312"\] "openin" a;; \- : true # get_flag \["ocaml_311"\] "openin" a;; \- : false # get_flag \["ocaml"\] "openin" a;; \- : false
val get_field :
parse:(string -> 'a option) ->
default:'a ->
sections:string list ->
field:string ->
t ->
'a
get_field parse default section_names field_name annotations
looks sequentially into the sections specified by section_names
for a field named field_name
. If no such field exists, the default
value is returned. If the field is present, the associated value is parsed using the given function parse
which should return None
in order to indicate an invalid value. If the field is present without an associated value or if parse
returns None
, a Failure
exception is raised.
Each section should be unique.
val get_fields :
parse:(string -> 'a option) ->
sections:string list ->
field:string ->
t ->
'a list
get_fields parse section_names field_name annotations
looks sequentially into the sections specified by section_names
for fields named field_name
. Each found value is parsed using the given function parse
which should return None
in order to indicate an invalid value. In the end the list of parsed values is returned. If the field is present without an associated value or if parse
returns None
, a Failure
exception is raised.
Each section should be unique.
val get_opt_field :
parse:(string -> 'a option) ->
sections:string list ->
field:string ->
t ->
'a option
This is the same as get_field
except that no default value for the field exists.
Returns the location of the annotation. Useful for error reporting.
Returns the location of the annotation. Useful for error reporting.
set_field loc section_name field_name value annotations
sets a field, reusing existing section section_name
if it exists, preserving the position of field field_name
and overwriting its value if it exists.
Merge sections of the same name together, and keeps only the first occurrence of each field.
<a a1="x1"> <b> <a a2="x3" a1="x2">
becomes
<a a1="x1" a2="x3"> <b>
Create a unique numeric ID
An annotation schema for a section "foo"
defines all the locations where annotations of the form <foo ...>
can occur and which fields are allowed. The goal is to detect misspellings in field names or the incorrect placement of an annotation.
Annotations whose section is undeclared in the schema are ignored. The following is an example specifying the legal placement of annotations of the form <json name="...">
:
{ section = "json"; fields = [ Variant, "name"; Field, "name"; ] }