Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Full Grammar

There are two kind of files in a dolfin package. The package.dlf placed at the root of a package folder, it serves as a manifest of the whole package. We give an exemple of such a file here and let the grammar being deduced.


package <http://my.special.iri/of-ontology>:
  dolfin_version: 1
  version: 1.2.3
  author: not only me
  author: but also you
  description: This package is an example

There are regular dolfin files. The folder in which they are, are used to compose the iri of each ontology and then the iri of each element.

ontology ::= 
    iri_name_annotation?
    header_item*
    declaration*
    EOF

iri_name_annotation ::=
    "@iri_name" String NEWLINE

(* Prefixes and file-level directives may appear in any order at the top of
   the file, before the first declaration. *)
header_item ::=
    prefix_statement
  | locale_directive
  | timezone_directive

locale_directive ::=
    "@locale" date_field_order NEWLINE

timezone_directive ::=
    "@timezone" timezone_spec NEWLINE

date_field_order ::= field date_sep field date_sep field   (* e.g. d/m/y *)
field             ::= "y" | "m" | "d"
date_sep          ::= "/" | "-" | "."
timezone_spec     ::= iana_name        (* e.g. Europe/Brussels *)
                    | utc_offset       (* e.g. +02:00, -05:00 *)
                    | tz_abbrev        (* e.g. UTC, Z, CET *)

prefix_statement ::=
    "prefix" prefix_target

prefix_target ::=
    qualified_name_or_iri ":" NEWLINE
    INDENT
      prefix_target+
    DEDENT
  | qualified_name_or_iri "as" Name NEWLINE
  | qualified_name_or_iri NEWLINE

declaration ::=
    concept
  | property
  | rule

concept ::=
    "concept" Name ":" NEWLINE
    INDENT
      concept_member+
    DEDENT

concept_member ::=
    sub_concept
  | has_property
  | "one" "of" ":" NEWLINE
    INDENT
      enum_value+
    DEDENT

sub_concept ::= "sub" type_ref ("," typeref)*

has_property ::= "has" Name ":" cardinality? type_ref NEWLINE

property ::=
    "property" Name ":" cardinality? type_ref "->" cardinality? type_ref NEWLINE

rule ::=
    "rule" Name ":" NEWLINE
    INDENT
      match_block
      then_block
    DEDENT

match_block ::=
    "match" ":" NEWLINE
    INDENT
      match_pattern+
    DEDENT

then_block ::=
    "then" ":" NEWLINE
    INDENT
      then_item+
    DEDENT

match_pattern ::=
    subject qualified_name object NEWLINE
  | subject qualified_name contraint_block NEWLINE
  | subject "a" tyep_ref NEWLINE
  | "among" ":" NEWLINE
    INDENT
      match_pattern+
    DEDENT quantifier ":" NEWLINE
    INDENT
      match_pattern+
    DEDENT
  | quantifier ":" NEWLINE
    INDENT
      match_pattern+
    DEDENT

quantifier ::=
    "all"
  | "none"
  | "at least" Integer
  | "at most" Integer
  | "exactly" Integer
  | "between" Integer "," Integer

then_item ::=
    assertion NEWLINE
  | nested_rule

assertion ::=
    subject qualified_name object
  | subject qualified_name no_comp_contraint_block
  | subject "a" type_ref

nested_rule ::= match_block then_block

subject ::=
    variable
  | qualified_name
  | contraint_block

object ::=
    variable
  | literal
  | qualified_name

constraint_block ::= "[" constraint ("," constraint)+ "]"

no_comp_constraint_block ::= "[" no_comp_constraint ("," no_comp_constraint)+ "]"

no_comp_constraint ::=
    "a" type_ref
  | qualified_name object
  | qualified_name contraint_block

constraint ::= 
    no_comp_constraint
  | comparison_op literal
  
comparion_op ::=
    "="
  | "!="
  | "<"
  | "<="
  | ">"
  | ">="

type_ref ::= 
    "string"
  | "int"
  | "float"
  | "boolean"
  | "date"
  | "time"
  | "date_time"
  | "duration"
  | qualified_name

qualified_name ::=
  

(* ----------------------------------------------------------------------- *)
(* Literals                                                                 *)
(* ----------------------------------------------------------------------- *)

literal ::=
    String
  | Integer
  | Float
  | Boolean
  | IRI
  | temporal_literal
  | quantity_literal

(* Temporal smart literals. The keyword names the XSD type; the parenthesised
   content is human-friendly notation, parsed by the dolfin-datetime library.
   The content must NOT contain a ")". *)
temporal_literal ::=
    "date"      "(" date_content     ")"
  | "time"      "(" time_content     ")"
  | "date_time" "(" datetime_content ")"
  | "duration"  "(" duration_content ")"

date_content ::= natural_date | numeric_date ("as" date_field_order)?

natural_date ::= month_name day_ordinal year
               | day_ordinal month_name year
month_name   ::= "January" | "Jan" | "February" | "Feb" | ... | "December" | "Dec"  (* case-insensitive *)
day_ordinal  ::= Integer ("st" | "nd" | "rd" | "th")?   (* suffix is cosmetic *)
year         ::= Integer
numeric_date ::= Integer date_sep Integer date_sep Integer
(* The separator in the value and in the "as" mask must match. Without a mask
   the file-level @locale supplies the field order; with neither, an ambiguous
   numeric date is an error. *)

time_content ::= hour ":" minute (":" second)? am_pm? timezone_spec?
hour   ::= Integer          (* 0-23, or 1-12 with AM/PM *)
minute ::= Integer          (* 00-59 *)
second ::= Integer          (* 00-59 *)
am_pm  ::= "AM" | "PM"      (* case-insensitive; switches to 12-hour clock *)

datetime_content ::= date_content ("," )? time_content   (* comma or space separated *)

duration_content ::= duration_term+
duration_term    ::= Integer duration_unit
duration_unit    ::= "y" | "mo" | "w" | "d" | "h" | "min" | "s"

(* Physical-quantity smart literal. The parenthesised content is a value and a
   unit expression, parsed by the dolfin-units library. The content must NOT
   contain a ")". See the Units & Quantities reference. *)
quantity_literal ::= "quantity" "(" quantity_content ")"
quantity_content ::= simple_quantity (arith_op simple_quantity)* ("as" convert_target)?
simple_quantity  ::= Number unit_expr | Number       (* bare number = dimensionless *)
arith_op         ::= "+" | "-" | "*" | "/"
convert_target   ::= unit_expr | "SI"
unit_expr        ::= unit_term (("." | "/") unit_term)*
unit_term        ::= unit_name ("^" power)?
power            ::= Integer | "(" Integer ")"        (* e.g. s^(-1) *)
unit_name        ::= (* a unit token, optionally SI-prefixed, e.g. m, kg, km, N, km/h components *)

cardinality ::=
    "one"
  | "any"
  | "some"
  | "optional"
  | Integer
  | "at least" Integer
  | "at most" Integer
  | Integer ".." Integer
  | Integer ".." "*"

(* "at least"/"at most" (and the "at_least"/"at_most" underscore aliases) are
   shared with the rule quantifiers above. *)