Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc comments and annotations in Souffle datalog #2472

Merged
merged 3 commits into from
Mar 5, 2024

Conversation

quentin
Copy link
Member

@quentin quentin commented Mar 4, 2024

Annotations are free meta-data that can be attached to most items of a Souffle datalog program.

A documentation comment is a syntactic sugar for a doc annotation.

The design is close to Rust's attributes.

All program's and component's items can have outer annotations of the form @[annotation] or /// doc comment. Attributes and ADT branches also accept outer annotations.

Some items can have inner annotations of the for @![annotation] or //! doc comment:

  • after { of a component, before the first component's item.
  • after { of an ADT branch, before the first attribute of the branch.
  • after :- of a clause, before the first constraint.

Annotations should not appear before .include or before any } or before the end of a file.

An annotation's payload may be of these forms:

  • an identifier: @[IDENT]
  • possibly followed by delimited token stream: @[IDENT DELIM]
  • or = and a delimited token stream: @[IDENT = DELIM] or @[IDENT = TOKEN TT*]

Where:

  • IDENT is an identifier or a keyword of Souffle.
  • TOKEN is any token except delimiters.
  • TS ::= TT+ is a token-stream.
  • TT ::= TOKEN | DELIM is a token-tree.
  • DELIM ::= '(' TS? ')' | '[' TS? ']' | '{' TS? '}' is a delimited token-stream.

Annotations are free meta-data that can be attached to most items of a
Souffle datalog program.

A documentation comment is a syntactic sugar for a `doc` annotation.

The design is close to Rust's *attributes*.

All program's and component's items can have *outer* annotations of
the form `@[annotation]` or `/// doc comment`. Attributes and ADT
branches also accept outer annotations.

Some items can have *inner* annotations of the for `@![annotation]`
or `//! doc comment`:
- after `{` of a component, before the first component's item.
- after `{` of an ADT branch, before the first attribute of the branch.
- after `:-` of a clause, before the first constraint.

Annotations should not appear before `.include` or before any `}` or
before the end of a file.

An annotation's payload may be of these forms:
- an identifier: `@[IDENT]`
- possibly followed by delimited token stream: `@[IDENT DELIM]`
- or `=` and a delimited token stream: `@[IDENT = DELIM]` or
  `@[IDENT = TOKEN TT*]`

Where:
- `IDENT` is an identifier or a keyword of Souffle.
- `TOKEN` is any token except delimiters.
- `TS ::= TT+` is a token-stream.
- `TT ::= TOKEN | DELIM` is a token-tree.
- `DELIM ::= '(' TS? ')' | '[' TS? ']' | '{' TS? '}'` is a delimited
  token-stream.
@quentin
Copy link
Member Author

quentin commented Mar 4, 2024

Use cases:

  • documentation comments attached to AST nodes ease the writing of documentation generation tools
  • annotations could replace "dirty" parts of the current Souffle grammar (stateful, choice-domain, .plan ...)
  • annotations brings extensibility without modifications of the core grammar

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 60.87485% with 322 lines in your changes are missing coverage. Please review.

Project coverage is 77.79%. Comparing base (dc8ecf8) to head (454e44c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2472      +/-   ##
==========================================
- Coverage   78.19%   77.79%   -0.40%     
==========================================
  Files         486      492       +6     
  Lines       32423    33179     +756     
==========================================
+ Hits        25352    25812     +460     
- Misses       7071     7367     +296     
Files Coverage Δ
src/ast/Annotation.h 100.00% <100.00%> (ø)
src/ast/Atom.cpp 100.00% <100.00%> (ø)
src/ast/Attribute.cpp 95.65% <100.00%> (+13.83%) ⬆️
src/ast/BranchType.h 100.00% <ø> (ø)
src/ast/Clause.cpp 97.26% <100.00%> (-1.18%) ⬇️
src/ast/Clause.h 100.00% <ø> (ø)
src/ast/Component.h 100.00% <ø> (ø)
src/ast/Counter.cpp 100.00% <100.00%> (ø)
src/ast/ItemContainer.h 100.00% <100.00%> (ø)
src/ast/IterationCounter.cpp 100.00% <100.00%> (ø)
... and 46 more

... and 7 files with indirect coverage changes

@quentin quentin merged commit d804988 into souffle-lang:master Mar 5, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants