Skip to content

w3c-turtle-grammar.fbl

Example document w3c-turtle-grammar.fbl

Views generated from the file

This view is drawn by this site from w3c-turtle-grammar.fbl itself. It shows the data in the document, not the notation the diagram draws.

Bindings of w3c-turtle-grammar.fbl. Flowchart of the bindings in w3c-turtle-grammar.fbl: 2 binding(s) (turtle, triples) as boxes with the files they claim and their body's format family, and 13 element rule(s) and 0 relation rule(s) as rounded boxes with the type each produces.
Generated from w3c-turtle-grammar.fbl at 46e5f91
Diagram as text (Mermaid)
flowchart LR
  accTitle: Bindings of w3c-turtle-grammar.fbl
  accDescr: Flowchart of the bindings in w3c-turtle-grammar.fbl: 2 binding(s) (turtle, triples) as boxes with the files they claim and their body's format family, and 13 element rule(s) and 0 relation rule(s) as rounded boxes with the type each produces.
  b_turtle["RDF in Turtle, read by its grammar<br/>turtle<br/>.ttl, grammar family"]
  e_turtle_prefix("prefix<br/>Prefix")
  b_turtle -->|element| e_turtle_prefix
  e_turtle_resource("resource<br/>Resource")
  b_turtle -->|element| e_turtle_resource
  b_triples["RDF triples in Turtle or N-Triples, read by the grammar<br/>triples<br/>.ttl .nt, grammar family"]
  e_triples_base("base<br/>Base")
  b_triples -->|element| e_triples_base
  e_triples_sparql_base("sparql-base<br/>Base")
  b_triples -->|element| e_triples_sparql_base
  e_triples_prefix("prefix<br/>Prefix")
  b_triples -->|element| e_triples_prefix
  e_triples_sparql_prefix("sparql-prefix<br/>Prefix")
  b_triples -->|element| e_triples_sparql_prefix
  e_triples_literal("literal<br/>Triple")
  b_triples -->|element| e_triples_literal
  e_triples_term("term<br/>Triple")
  b_triples -->|element| e_triples_term
  e_triples_nested_literal("nested-literal<br/>Triple")
  b_triples -->|element| e_triples_nested_literal
  e_triples_nested_term("nested-term<br/>Triple")
  b_triples -->|element| e_triples_nested_term
  e_triples_first_literal("first-literal<br/>Triple")
  b_triples -->|element| e_triples_first_literal
  e_triples_first_term("first-term<br/>Triple")
  b_triples -->|element| e_triples_first_term
  e_triples_rest("rest<br/>Triple")
  b_triples -->|element| e_triples_rest

The file

Download w3c-turtle-grammar.fbl (26,884 bytes, unchanged from the source).

{
  "$schema": "https://etalii.net/adp/fbl/schema/0.1/fbl.schema.json#/$defs/Document",
  "fbl": "0.16",
  "doc": "FBL 0.9's grammar family (section 4.9): Turtle read by the grammar w3c-turtle.lark beside this document instead of by a persistence plugin, for the prefixes and the labelled resources of a W3C RDF graph (definitions/diagrams/w3c-rdf.dis). A statement whose subject is a resource, an IRI or a prefixed name, is a Resource, its id the subject as written and its label the first rdfs:label written in it; a prefix directive is a Prefix. Every other statement, and every other triple, is kept and binds nothing. A statement that does not parse is skipped to its '.' and reported at its line, and the rest is read (recover). w3c-turtle.fbl, the plugin binding the four W3C tool types run, stays as it is; spec 035 binds the W3C RDF type's Turtle with this family in its tool description. FBL 0.15's binding `triples` reads what w3c-turtle.fbl's plugin reads, with no plugin (spec 067, T037): a stored Triple per triple, each reaching up to its subject, its terms read through the file's directives, a blank node by its number and a literal unescaped, in the order a construct closes; a Prefix per directive and the Base. Four tool types read it, whose descriptions bind it in ATD (definitions/diagrams/w3c-*.turtle.atd), and a test holds them equal. It writes as FBL 0.16 states: a value in place, a term under the file's prefixes, a new triple as a `;` continuation of its subject's last statement, or a statement of its own at the end of the body when the file has none, and a removed triple with its separator, the whole statement when it is the last.",
  "bindings": {
    "turtle": {
      "title": "RDF in Turtle, read by its grammar",
      "claims": {
        "extensions": [
          ".ttl"
        ],
        "origins": [
          "w3c/rdf"
        ]
      },
      "body": {
        "kind": "file",
        "family": "grammar",
        "grammar": {
          "file": "w3c-turtle.lark"
        },
        "start": "turtle_doc",
        "recover": {
          "unit": "statement",
          "sync": [
            "."
          ]
        }
      },
      "reader": "declared",
      "text": {
        "newline": "crlf",
        "indent": 4,
        "finalNewline": true
      },
      "elements": [
        {
          "name": "prefix",
          "type": "Prefix",
          "doc": "`@prefix ex: <http://example.org/> .`: the name without its colon, the IRI without its angle brackets. Prefixes are read, and written only by a set.",
          "at": "/statement/prefix_id",
          "id": {
            "from": {
              "node": "PNAME_NS"
            }
          },
          "attributes": {
            "name": {
              "node": "PNAME_NS",
              "match": "(?<value>[^:]*):"
            },
            "iri": {
              "node": "IRIREF",
              "match": "<(?<value>[^>]*)>"
            }
          }
        },
        {
          "name": "resource",
          "type": "Resource",
          "at": "/triples_statement",
          "when": "entry.children[0].children[0].children[0].type == 'iri'",
          "id": {
            "from": {
              "node": "triples/subject"
            }
          },
          "attributes": {
            "label": {
              "node": "triples/predicate_object_list/predicate_object[verb='rdfs:label']/object_list/object/rdf_literal/string",
              "match": "\"(?<value>(?:[^\"\\\\]|\\\\.)*)\""
            }
          },
          "insert": {
            "place": "after-last",
            "emit": "{id} rdfs:label \"{label}\" ."
          },
          "remove": {}
        }
      ],
      "template": {
        "text": "@prefix ex: <http://example.org/> .\r\n@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\r\n\r\nex:{key} rdfs:label \"{base}\" .\r\n"
      }
    },
    "triples": {
      "title": "RDF triples in Turtle or N-Triples, read by the grammar",
      "claims": {
        "extensions": [
          ".ttl",
          ".nt"
        ],
        "origins": [
          "w3c/rdf",
          "w3c/owl",
          "w3c/skos",
          "w3c/shacl"
        ]
      },
      "body": {
        "kind": "file",
        "family": "grammar",
        "grammar": {
          "file": "w3c-turtle.lark"
        },
        "start": "turtle_doc",
        "order": "closed",
        "prefixes": {
          "declarations": [
            {
              "at": "/statement/prefix_id",
              "name": {
                "node": "PNAME_NS",
                "match": "(?<value>[^:]*):"
              },
              "iri": {
                "node": "IRIREF"
              }
            },
            {
              "at": "/statement/sparql_prefix",
              "name": {
                "node": "PNAME_NS",
                "match": "(?<value>[^:]*):"
              },
              "iri": {
                "node": "IRIREF"
              }
            }
          ],
          "bases": [
            {
              "at": "/statement/base",
              "iri": {
                "node": "IRIREF"
              }
            },
            {
              "at": "/statement/sparql_base",
              "iri": {
                "node": "IRIREF"
              }
            }
          ],
          "absolute": "<(?<value>[^>]*)>",
          "prefixed": "(?<prefix>[^:<]*):(?<local>.*)",
          "local": "(?:[\\pL\\pN_-][\\pL\\pN_.-]*)?[\\pL\\pN_-]",
          "terminals": [
            "PNAME_LN",
            "PNAME_NS"
          ]
        },
        "ordinals": {
          "blank": {
            "at": [
              "/**/blank_node/*",
              "/**/blank_node_property_list",
              "/**/collection/object"
            ],
            "same": "BLANK_NODE_LABEL"
          }
        }
      },
      "reader": "declared",
      "text": {
        "newline": "crlf",
        "indent": 4,
        "finalNewline": true
      },
      "elements": [
        {
          "name": "base",
          "type": "Base",
          "at": "/statement/base",
          "attributes": {
            "iri": {
              "node": "IRIREF",
              "expand": true
            }
          },
          "readOnly": "The base is written in the file; change it there."
        },
        {
          "name": "sparql-base",
          "type": "Base",
          "at": "/statement/sparql_base",
          "attributes": {
            "iri": {
              "node": "IRIREF",
              "expand": true
            }
          },
          "readOnly": "The base is written in the file; change it there."
        },
        {
          "name": "prefix",
          "type": "Prefix",
          "at": "/statement/prefix_id",
          "attributes": {
            "name": {
              "node": "PNAME_NS",
              "match": "(?<value>[^:]*):"
            },
            "iri": {
              "node": "IRIREF",
              "match": "<(?<value>[^>]*)>"
            },
            "form": {
              "value": "'turtle'"
            },
            "line": {
              "value": "line"
            }
          },
          "insert": {
            "place": "after-last",
            "container": "/",
            "emit": "@prefix {name}: <{iri}> ."
          },
          "doc": "A directive: its name without its colon, its IRI; written after the last declaration."
        },
        {
          "name": "sparql-prefix",
          "type": "Prefix",
          "at": "/statement/sparql_prefix",
          "attributes": {
            "name": {
              "node": "PNAME_NS",
              "match": "(?<value>[^:]*):"
            },
            "iri": {
              "node": "IRIREF",
              "match": "<(?<value>[^>]*)>"
            },
            "form": {
              "value": "'sparql'"
            },
            "line": {
              "value": "line"
            }
          }
        },
        {
          "name": "literal",
          "type": "Triple",
          "at": "/**/triples/predicate_object_list/predicate_object/object_list/object",
          "when": "entry.children[0].type in ['rdf_literal', 'numeric_literal', 'boolean_literal']",
          "attributes": {
            "s": {
              "node": "../../../../subject/iri",
              "expand": true,
              "map": {
                "empty_collection": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
              },
              "or": [
                {
                  "node": "../../../../subject/blank_node/*",
                  "ordinal": "blank"
                },
                {
                  "node": "../../../../subject/collection/object",
                  "ordinal": "blank"
                },
                {
                  "node": "../../../../subject_list/blank_node_property_list",
                  "ordinal": "blank"
                },
                {
                  "node": "../../../../subject/empty_collection",
                  "name": true
                }
              ]
            },
            "sKind": {
              "node": "../../../../*/*",
              "name": true,
              "map": {
                "iri": "iri",
                "blank_node": "blank",
                "collection": "blank",
                "blank_node_property_list": "blank",
                "empty_collection": "iri"
              }
            },
            "sLabel": {
              "node": "../../../../subject/blank_node/BLANK_NODE_LABEL",
              "match": "_:(?<value>.*)"
            },
            "sWritten": {
              "node": "../../../../subject/iri"
            },
            "p": {
              "node": "../../verb",
              "expand": {
                "keywords": {
                  "a": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
                }
              }
            },
            "o": {
              "node": "rdf_literal/string",
              "match": "(?:\"\"\"|'''|\"|')(?<value>(?s:.*?))(?:\"\"\"|'''|\"|')",
              "escape": {
                "with": "\\",
                "quote": "\"",
                "sequences": {
                  "t": "\t",
                  "b": "\b",
                  "n": "\n",
                  "r": "\r",
                  "f": "\f",
                  "'": "'"
                },
                "unicode": {
                  "u": 4,
                  "U": 8
                },
                "writes": [
                  "\n",
                  "\r",
                  "\t"
                ],
                "requote": "\""
              },
              "or": [
                {
                  "node": "numeric_literal"
                },
                {
                  "node": "boolean_literal"
                }
              ]
            },
            "oKind": {
              "value": "'literal'"
            },
            "language": {
              "node": "rdf_literal/LANGTAG",
              "match": "@(?<value>.*)"
            },
            "datatype": {
              "node": "rdf_literal/iri",
              "expand": true,
              "map": {
                "INTEGER": "http://www.w3.org/2001/XMLSchema#integer",
                "DECIMAL": "http://www.w3.org/2001/XMLSchema#decimal",
                "DOUBLE": "http://www.w3.org/2001/XMLSchema#double",
                "boolean_literal": "http://www.w3.org/2001/XMLSchema#boolean"
              },
              "or": [
                {
                  "node": "numeric_literal/*",
                  "name": true
                },
                {
                  "node": "boolean_literal",
                  "name": true
                }
              ]
            },
            "line": {
              "value": "line"
            }
          },
          "insert": {
            "when": "attributes.oKind == 'literal'",
            "place": "end-of-document",
            "emit": "\n{s} {p} {o}[@{language}][^^{datatype}] .",
            "continues": {
              "at": "/triples_statement",
              "same": {
                "s": {
                  "node": "triples/subject/iri",
                  "expand": true
                }
              },
              "separator": ";",
              "emit": "{p} {o}[@{language}][^^{datatype}] ."
            }
          },
          "remove": {
            "parts": [
              {
                "item": ".",
                "separator": ","
              },
              {
                "item": "../..",
                "separator": ";"
              }
            ],
            "whole": "../../../../.."
          },
          "doc": "A literal object in a statement: `s` reaches up to the statement's subject (FBL 0.15, section 4.9)."
        },
        {
          "name": "term",
          "type": "Triple",
          "at": "/**/triples/predicate_object_list/predicate_object/object_list/object",
          "when": "!(entry.children[0].type in ['rdf_literal', 'numeric_literal', 'boolean_literal'])",
          "attributes": {
            "s": {
              "node": "../../../../subject/iri",
              "expand": true,
              "map": {
                "empty_collection": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
              },
              "or": [
                {
                  "node": "../../../../subject/blank_node/*",
                  "ordinal": "blank"
                },
                {
                  "node": "../../../../subject/collection/object",
                  "ordinal": "blank"
                },
                {
                  "node": "../../../../subject_list/blank_node_property_list",
                  "ordinal": "blank"
                },
                {
                  "node": "../../../../subject/empty_collection",
                  "name": true
                }
              ]
            },
            "sKind": {
              "node": "../../../../*/*",
              "name": true,
              "map": {
                "iri": "iri",
                "blank_node": "blank",
                "collection": "blank",
                "blank_node_property_list": "blank",
                "empty_collection": "iri"
              }
            },
            "sLabel": {
              "node": "../../../../subject/blank_node/BLANK_NODE_LABEL",
              "match": "_:(?<value>.*)"
            },
            "sWritten": {
              "node": "../../../../subject/iri"
            },
            "p": {
              "node": "../../verb",
              "expand": {
                "keywords": {
                  "a": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
                }
              }
            },
            "o": {
              "node": "iri",
              "expand": true,
              "map": {
                "empty_collection": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
              },
              "or": [
                {
                  "node": "blank_node/*",
                  "ordinal": "blank"
                },
                {
                  "node": "collection/object",
                  "ordinal": "blank"
                },
                {
                  "node": "blank_node_property_list",
                  "ordinal": "blank"
                },
                {
                  "node": "empty_collection",
                  "name": true
                }
              ]
            },
            "oKind": {
              "node": "*",
              "name": true,
              "map": {
                "iri": "iri",
                "blank_node": "blank",
                "collection": "blank",
                "blank_node_property_list": "blank",
                "empty_collection": "iri"
              }
            },
            "oLabel": {
              "node": "blank_node/BLANK_NODE_LABEL",
              "match": "_:(?<value>.*)"
            },
            "line": {
              "value": "line"
            }
          },
          "insert": {
            "place": "end-of-document",
            "emit": "\n{s} {p} {o} .",
            "continues": {
              "at": "/triples_statement",
              "same": {
                "s": {
                  "node": "triples/subject/iri",
                  "expand": true
                }
              },
              "separator": ";",
              "emit": "{p} {o} ."
            }
          },
          "remove": {
            "parts": [
              {
                "item": ".",
                "separator": ","
              },
              {
                "item": "../..",
                "separator": ";"
              }
            ],
            "whole": "../../../../.."
          },
          "doc": "An IRI or blank object in a statement. A blank node is written nowhere: an edit naming one is refused."
        },
        {
          "name": "nested-literal",
          "type": "Triple",
          "at": "/**/blank_node_property_list/predicate_object_list/predicate_object/object_list/object",
          "when": "entry.children[0].type in ['rdf_literal', 'numeric_literal', 'boolean_literal']",
          "attributes": {
            "s": {
              "node": "../../../..",
              "ordinal": "blank"
            },
            "sKind": {
              "value": "'blank'"
            },
            "p": {
              "node": "../../verb",
              "expand": {
                "keywords": {
                  "a": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
                }
              }
            },
            "o": {
              "node": "rdf_literal/string",
              "match": "(?:\"\"\"|'''|\"|')(?<value>(?s:.*?))(?:\"\"\"|'''|\"|')",
              "escape": {
                "with": "\\",
                "quote": "\"",
                "sequences": {
                  "t": "\t",
                  "b": "\b",
                  "n": "\n",
                  "r": "\r",
                  "f": "\f",
                  "'": "'"
                },
                "unicode": {
                  "u": 4,
                  "U": 8
                },
                "writes": [
                  "\n",
                  "\r",
                  "\t"
                ],
                "requote": "\""
              },
              "or": [
                {
                  "node": "numeric_literal"
                },
                {
                  "node": "boolean_literal"
                }
              ]
            },
            "oKind": {
              "value": "'literal'"
            },
            "language": {
              "node": "rdf_literal/LANGTAG",
              "match": "@(?<value>.*)"
            },
            "datatype": {
              "node": "rdf_literal/iri",
              "expand": true,
              "map": {
                "INTEGER": "http://www.w3.org/2001/XMLSchema#integer",
                "DECIMAL": "http://www.w3.org/2001/XMLSchema#decimal",
                "DOUBLE": "http://www.w3.org/2001/XMLSchema#double",
                "boolean_literal": "http://www.w3.org/2001/XMLSchema#boolean"
              },
              "or": [
                {
                  "node": "numeric_literal/*",
                  "name": true
                },
                {
                  "node": "boolean_literal",
                  "name": true
                }
              ]
            },
            "line": {
              "value": "line"
            }
          }
        },
        {
          "name": "nested-term",
          "type": "Triple",
          "at": "/**/blank_node_property_list/predicate_object_list/predicate_object/object_list/object",
          "when": "!(entry.children[0].type in ['rdf_literal', 'numeric_literal', 'boolean_literal'])",
          "attributes": {
            "s": {
              "node": "../../../..",
              "ordinal": "blank"
            },
            "sKind": {
              "value": "'blank'"
            },
            "p": {
              "node": "../../verb",
              "expand": {
                "keywords": {
                  "a": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
                }
              }
            },
            "o": {
              "node": "iri",
              "expand": true,
              "map": {
                "empty_collection": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
              },
              "or": [
                {
                  "node": "blank_node/*",
                  "ordinal": "blank"
                },
                {
                  "node": "collection/object",
                  "ordinal": "blank"
                },
                {
                  "node": "blank_node_property_list",
                  "ordinal": "blank"
                },
                {
                  "node": "empty_collection",
                  "name": true
                }
              ]
            },
            "oKind": {
              "node": "*",
              "name": true,
              "map": {
                "iri": "iri",
                "blank_node": "blank",
                "collection": "blank",
                "blank_node_property_list": "blank",
                "empty_collection": "iri"
              }
            },
            "oLabel": {
              "node": "blank_node/BLANK_NODE_LABEL",
              "match": "_:(?<value>.*)"
            },
            "line": {
              "value": "line"
            }
          }
        },
        {
          "name": "first-literal",
          "type": "Triple",
          "at": "/**/collection/object",
          "when": "entry.children[0].type in ['rdf_literal', 'numeric_literal', 'boolean_literal']",
          "attributes": {
            "s": {
              "node": ".",
              "ordinal": "blank"
            },
            "sKind": {
              "value": "'blank'"
            },
            "p": {
              "value": "'http://www.w3.org/1999/02/22-rdf-syntax-ns#first'"
            },
            "o": {
              "node": "rdf_literal/string",
              "match": "(?:\"\"\"|'''|\"|')(?<value>(?s:.*?))(?:\"\"\"|'''|\"|')",
              "escape": {
                "with": "\\",
                "quote": "\"",
                "sequences": {
                  "t": "\t",
                  "b": "\b",
                  "n": "\n",
                  "r": "\r",
                  "f": "\f",
                  "'": "'"
                },
                "unicode": {
                  "u": 4,
                  "U": 8
                },
                "writes": [
                  "\n",
                  "\r",
                  "\t"
                ],
                "requote": "\""
              },
              "or": [
                {
                  "node": "numeric_literal"
                },
                {
                  "node": "boolean_literal"
                }
              ]
            },
            "oKind": {
              "value": "'literal'"
            },
            "language": {
              "node": "rdf_literal/LANGTAG",
              "match": "@(?<value>.*)"
            },
            "datatype": {
              "node": "rdf_literal/iri",
              "expand": true,
              "map": {
                "INTEGER": "http://www.w3.org/2001/XMLSchema#integer",
                "DECIMAL": "http://www.w3.org/2001/XMLSchema#decimal",
                "DOUBLE": "http://www.w3.org/2001/XMLSchema#double",
                "boolean_literal": "http://www.w3.org/2001/XMLSchema#boolean"
              },
              "or": [
                {
                  "node": "numeric_literal/*",
                  "name": true
                },
                {
                  "node": "boolean_literal",
                  "name": true
                }
              ]
            },
            "line": {
              "value": "line"
            }
          }
        },
        {
          "name": "first-term",
          "type": "Triple",
          "at": "/**/collection/object",
          "when": "!(entry.children[0].type in ['rdf_literal', 'numeric_literal', 'boolean_literal'])",
          "attributes": {
            "s": {
              "node": ".",
              "ordinal": "blank"
            },
            "sKind": {
              "value": "'blank'"
            },
            "p": {
              "value": "'http://www.w3.org/1999/02/22-rdf-syntax-ns#first'"
            },
            "o": {
              "node": "iri",
              "expand": true,
              "map": {
                "empty_collection": "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
              },
              "or": [
                {
                  "node": "blank_node/*",
                  "ordinal": "blank"
                },
                {
                  "node": "collection/object",
                  "ordinal": "blank"
                },
                {
                  "node": "blank_node_property_list",
                  "ordinal": "blank"
                },
                {
                  "node": "empty_collection",
                  "name": true
                }
              ]
            },
            "oKind": {
              "node": "*",
              "name": true,
              "map": {
                "iri": "iri",
                "blank_node": "blank",
                "collection": "blank",
                "blank_node_property_list": "blank",
                "empty_collection": "iri"
              }
            },
            "oLabel": {
              "node": "blank_node/BLANK_NODE_LABEL",
              "match": "_:(?<value>.*)"
            },
            "line": {
              "value": "line"
            }
          }
        },
        {
          "name": "rest",
          "type": "Triple",
          "at": "/**/collection/object/*",
          "doc": "A collection's rest: each member's entry holds one more, the child of its `object`.",
          "attributes": {
            "s": {
              "node": "..",
              "ordinal": "blank"
            },
            "sKind": {
              "value": "'blank'"
            },
            "p": {
              "value": "'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest'"
            },
            "o": {
              "node": "../+",
              "ordinal": "blank",
              "or": [
                {
                  "value": "'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'"
                }
              ]
            },
            "oKind": {
              "node": "../+",
              "name": true,
              "map": {
                "object": "blank"
              },
              "or": [
                {
                  "value": "'iri'"
                }
              ]
            },
            "line": {
              "value": "line"
            }
          }
        }
      ]
    }
  }
}

In an IDE

No IDE host runs this example yet.