Crates.io | tree-sitter-sdml |
lib.rs | tree-sitter-sdml |
version | 0.4.0 |
source | src |
created_at | 2023-05-13 16:35:05.461832 |
updated_at | 2024-11-04 15:53:39.232152 |
description | sdml grammar for the tree-sitter parsing library |
homepage | |
repository | https://github.com/tree-sitter/tree-sitter-sdml |
max_upload_size | |
id | 863822 |
size | 715,414 |
A tree-sitter grammar for the Simple Domain Modeling Language (SDML). For more information on the language, see the documentation.
module campaign base <https://advertising.amazon.com/api-model> is
import [dc skos xsd]
@skos:prefLabel = "Campaign sub-domain"@en
@skos:version = xsd:decimal(2)
datatype Name <- xsd:string is
@xsd:minLength = 5
@xsd:maxLength = 25
end
datatype Identifier <- opaque xsd:string is
@xsd:length = 20
end
property CampaignId -> Identifier is
@skos:prefLabel = [
"Campaign Identifier"@en
"Identified de campagne"@fr
]
@skos:description = "The globally unique identifier for a Campaign entity"@en
end
structure Tag is
key -> xsd:NMTOKEN
value -> {0..} rdfs:langStrings
end
entity Campaign is
identity ref CampaignId
name -> Name is
@skos:definition = "the name of the campaign"@en
end
tag -> {0..} Tag
target -> {1..} Target
end
entity Target
end
The following bindings are built and released along with any version upgrade of the source version. The tree-sitter tool also generates bindings for C, Go, and Swift that are not built and released to any repository.
Node bindings are published to npmjs and can be installed using the npm command directly, or by making it a project dependency.
〉npm install -g tree_sitter_sdml
Python bindings are published to PyPI and can be installed using any
standard tool, such as pip
.
〉pip3 install tree_sitter_sdml
Rust bindings are published to crates.io and can be installed via cargo in the usual manner.
〉cargo install tree_sitter_sdml
This package is released under the Apache License, Version 2.0. See LICENSE file for details.
The primary aim of this release is to introduce a new definition type, a dimension. This may be seen as a violation of SDML's goal of being technology or implementation independent however it is a pragmatic decision based on usage experience. Modeling the data managed by a business in terms of entities solves many operational purposes but ignores a major purpose of this data -- reporting.
module example is
import [ sales stores xsd ]
dimension Region is
;; define an identifier for this dimension
identity region -> long
;; add members
name -> string
end
dimension Location is
;; tightly bind this dimension to the Sale entity
source sales:Sale
;; define a hierarchy by noting one or more parent dimensions
parent region -> Region
;; reuse members from the source entity
store from sales:Sale
city from sales:Sale
;; add additional members not on the source entity
state -> stores:State
country -> stores:Country
end
end
Detailed changes:
dimension_def
to the choice group in definition
.dimension_def
with name and optional dimension_body
.dimension_body
allows for either a source clause, or an identity clause.dimension_body
allows a set of parent_dimension
clauses before a set of
dimension_member
clauses.parent_dimension
is a simplified name to identifier reference member with
the keyword parent
.dimension_member
is either an existing member_def
, property_ref
or the new
member_from
clause that allows reuse of members from source entities.Breaking Change: the grammar moves the source
keyword and identifier reference
from the event_def
rule to a new event_body
rule. Old code, note that the source
clause was required even for empty events.
module example is
entity Thing
event NewThing source Thing
end
New code, now an empty event looks more like other empty definitions, and adding
a source clause requires is
and end
.
module example is
entity Thing
event Empty
event NewThing is
source Thing
end
end
Additionally, this version of the grammar allows module's to rename imports,
both modules and members. This allows then client module to avoid always using
qualified names, and to use short, or more meaningful, names as appropriate.
``` sdml
module example is
import rentals_billing as billing
import billing:Invoice as Invoice
end
byte
nodes in grammar for binary literals.cc
and tree-sitter
.module
's well-formedness rules to disallow the definitions
rdf_def
and type_class_def
be added to a non-library module.feature_reference
entirely, and it's reference in
rule type_reference
.type_reference: $ => choice(
$.unknown_type,
$.identifier_reference,
$.builtin_simple_type,
$.mapping_type
),
examples/escaped_strings.sdm
file for basic testing.test/corpus/escaped_strings.sdm
file for more complete testing.property_def
is singular.property_ref
uses "ref".property_def: $ => seq(
keyword('property'),
$.member_def
),
member
.
property_ref
or member_def
.property_def
to simply be member_def
.entity_identity
to be member
.entity_identity: $ => seq(
keyword('identity'),
$.member
),
member: $ => choice(
$.member_def,
$.property_ref,
),
member_def: $ => seq(
field('name', $.identifier),
$._type_expression_to,
optional(field('body', $.annotation_only_body))
),
property_ref: $ => seq(
keyword('ref'),
field('property', $.identifier_reference),
),
rdf_def
.rdf_super_types
optional rule to rdf_def
.rdf_thing_def
rule into rdf_def
.uri
to version_uri
on rule module_import
.base
keyword.version
keyword and string/IRI version information.examples/rdf_schema.sdm
"base"
, add new version clause on module definitions.
test/corpus/module_empty_with_version.sdm
sequence_of_predicate_values
to match sequence_of_values
with value constructor, mapping value, and identifier reference choices.value_variant
to remove the assignment to an unsigned
value.feature_reference
to contain the identifier reference,
update the rule _type_expression_to
to have a choice of feature_reference
or
type_reference
.byte
to rule binary
to aid in parser and highlighting.Along with minor changes in highlighting and examples.
optional
for the operator "?" to allow for optional values.
Also added to type reference rules.parameters
to the rule reference type_class_parameters
in rule
type_class_def
.type_variable_subtype
to type_variable_restriction
.type_variable_restriction
.This release is primarily to implement type classes that allow a better description of the standard library for constraints. Adding this support identified some simplifications in functional terms and sequence builders.
module example is
class Typed(T) is
def has_type(v -> T) → Type is
@skos:definition = "Returns the SDML type of the passed value."@en
@skos:example = "~type_of(rentals:Customer) = sdml:Entity~"
end
end
end
type_class_def
and list it as an alternative in definition
.method_def
and include as member of type_class_def
.wildcard
from rule function_type_reference
, wildcards are
only allowed on type class parameters.quantified_sentence
to only have a single
quantified variable binding.
binding
in quantified_sentence
to remove the repeat.body
from _quantified_body
to constraint_sentence
.quantifier_bound_names
to quantified_variable
to denote
singular.source
in quantified_variable
to use existing term
.type_iterator
and sequence_iterator
.quantified_sentence
as body.
body
in rule sequence_builder
from _variable_binding
to
sequence_builder_body
._variable_binding
.sequence_builder_body
which is simply a reference to rule
quantified_sentence
.actual_aruments
for use in rules atomic_sentence
and
functional_term
._boolean_true
to boolean_truth
._boolean_false
to boolean_falsity
.This is a significant refactor intended to simplify the grammar, and reduce the number of constructs used where the differentiation is not as significant as it looked previously.
member_by_value
and role_by_value
.member_by_reference
to member
and role_by_reference
to
member_role
.ref
from rules member
and member_role
.identity_member
to entity_identity
.structure_body
to structured_body
.structure_group
to member_group
._structured_body_inner
rule.feature_set_def
, and update definition
accordingly.features
into the rule _type_expression_to
.opaque
to datatype definition.:=
throughout for assignment /by definition/.
_by_definition
.value_variant
, function_def
, and constant_def
to use
_by_definition
._property_member
to _property_reference
.features
definition to be or/xor only.
UnionBody
.FeatureSetDef
::= "features" Identifier Cardinality? UnionBody?
-! Feature: add support for features from Product Line Engineering.
feature_set_def
to rule definition
.feature_set_def
.unsigned
.binary
.iri_reference
to iri
.↦
to the rule _has_type
which works better
for some typesetting.inequation
alongside equation
.
inequation
and make it a choice within simple_sentence
.not_equal
, less_than
,
less_than_or_equal
, greater_than
, and greater_than_or_equal
.boolean_sentence
into a choice of
unary_boolean_sentence
and binary_boolean_sentence
.
unary_boolean_sentence
for negation only.binary_boolean_sentence
for logical connectives.variable_binding
to ``bindingin rule
quantieid_sentence`._function_type_expression_to
to _function_type
._has_type
and _type_restriction
and allow both ASCII and
Unicode arrows.
_has_type
for values *>
and →
._type_restriction
for values <*
and ←
.quantified_variable_binding
.quantifier_binding
to quantifier_bound_names
._constant_def
to constant_def
.name_path
to function_composition
.quantified_sentence
and
sequence_builder
.
quantifier_binding
(along with _bound_name_set
) now used
in both sentence and builder.expression
into a field named body
of type
constraint_sentence
.expression
and conjunctive_expression
.predicate_value
to match value
and
corresponding sequences.iterator_target
to iterator_source
.from
in type_iterator
to source
.from
in sequence_iterator
to source
.function_cardinality_expression
to allow sequence
constraints.
any_type
to wildcard
.any_cardinality
and replace with wildcard
.list_of_predicate_values
to sequence_of_predicate_values
.list_of_values
to sequence_of_values
.property_role
private as _property_role
._sequence_value_constraints
._sequence_value_constraints
to rule
sequence_of_predicate_values
._sequence_value_constraints
to rule sequence_of_values
.sequence_comprehension
to be more flexible.
sequence_comprehension
to sequence_builder
.returned_value
to variables
and re-write as a choice of:tuple_variable
to return distinct variables.sequence_variable
to return distinct variables as a sequence.mapping_variable
to return two variables as a mapping._property_member
to allow property names to be
identifier_reference
.
name
in a member will be the name of a role.in
, not as
.role
to property
and made it's type identifier_reference
.property_role
to be a choice of three new rules.identity_role
which is a subset of identity_member
.role_by_value
which is a subset of member_by_value
.role_by_reference
which is a subset of member_by_reference
.binding_target
to iterator_target
.binding_type_reference
to type_iterator
and field name from_type
to from
.binding_seq_iterator
to sequence_iterator
and field name
from_sequence
to from
.environment_definition
and made naming more
consistent.
signature
fieldrhs
to body
and change to a choice of function_def
or
_value_def
.function_def
to hold the signature and operators removed from the
environment definition.fn_parameter
to function_parameter
._fn_type
to _function_type_expression_to
.function_cardinality_expression
and any_cardinality
to capture
cardinality or wildcard.function_type_reference
to allow wildcards.highlights
, locals
, and tags
for all changes above.locals.scm
file with scopes for formal constraints.∅
(empty set) as a synonym for []
in constraints.simple_value
to value
. This changes it back.source_cardinality
has been removed.member_inverse_name
has been added.type_definition
to definition
to address the fact
that property definitions aren't types.enum_variant
to value_variant
to align with
type_variant
on unions.annotation
has been renamed annotation_property
constraint
has been added.annotation
is defined as a choice of
annotation_property
or constraint
.module example is
import tag
structure Thing is
inner -> {0..} InnerThing is
;; informal
assert same_tags = "All inner tags contain a tag value \"This\"."
;; formal
assert same_tags_formal is
forall self ( not_empty(self) and contains(self.tags "This") )
end
end
end
structure InnerThing is
tags -> {0..} tag:Tag
end
end
module ddict is
import account
property accountId is
@skos:prefLabel = "accountId"@en
@skos:altLabel = "account_id"@en
identifier -> {1} account:AccountId is
@skos:definition = "Used as an identifier for account-scoped things"@en
end
reference ref {1} -> {1} account:AccountId
end
structure Account is
accountId as identifier
name -> string
end
end
module ddict is
import account
property accountId -> account:AccountId is
@skos:prefLabel = "accountId"@en
@skos:altLabel = "account_id"@en
identifier is
@skos:definition = "Used as ..."@en
end
default = {1..1}
end
structure Account is
accountId as default
name -> string
end
end
builtin_simple_type
(choice of string
, double
, decimal
,
integer
, boolean
, and iri
):
identifier_reference
with new rule data_type_base
for data_type_def
,type_reference
choice used for the member target
field.Allows both:
module example is
datatype mystring <- string
structure Person is
name -> string
age -> integer
end
end
Where the keywords string
and integer
will be expanded into the qualified
identifiers sdml:string
and sdml:integer
respectively.
base
grammar for module rather than using xml:base
as an
attribute.Identifier
to allow decimal digits in any position after
the first.TypeVariant
.Introduces:
module example base <https://example.org/v/example> is
end
Which replaces the annotation form:
module example is
import xml
@xml:base = <https://example.org/v/example>
end
IdentifierReference
valuesTypeVariant
nameTypeVariant
annotation
and language_tag
grammar rule conflictIntroduces:
module example is
union Example is
Variant1
Variant1 as Alternative
end
end
This allows the use of the same type as a variant more than once if the new
identifier is unique within the same union
.
UnionDef
type.UnionDef
type.sourceCardinality
into source_cardinality
.targetCardinality
into target_cardinality
._simple_value
into simple_value
named rule._type_reference
into type_reference
named rule.