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

docs: 18 language design #23

Merged
merged 42 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
07db87c
docs: fix warnings
alex-senger Apr 5, 2024
7c72958
docs: add validity for functions
alex-senger Apr 5, 2024
8f86743
update comments, imports and packages
robmeth Apr 5, 2024
3e38076
Merge remote-tracking branch 'origin/18-language-design' into 18-lang…
robmeth Apr 5, 2024
8f8aeb2
refactor: move validity and statements into common
alex-senger Apr 5, 2024
8f53b4c
docs: change validity of functions to refer to other file
alex-senger Apr 5, 2024
49d3572
docs: add documentation for validity of constants
alex-senger Apr 6, 2024
93f1398
docs: minor improvement in wording and hyperlink
alex-senger Apr 6, 2024
51ccef8
docs: add validity for data and improve wording for constants
alex-senger Apr 6, 2024
b44cfd0
docs: remove sds documentation
alex-senger Apr 6, 2024
f827b0e
docs: remove sds documentation readme
alex-senger Apr 6, 2024
32839f5
docs: add date and date-time literals
alex-senger Apr 7, 2024
ecb0dda
docs: add calls per time syntax
alex-senger Apr 7, 2024
49d2e93
update constants, data, functions
robmeth Apr 7, 2024
fb05818
Merge remote-tracking branch 'origin/18-language-design' into 18-lang…
robmeth Apr 7, 2024
86d21eb
update links in data, functions, modifier, statements
robmeth Apr 8, 2024
88468b0
added timespan to modifier and updated it in functions and data
robmeth Apr 8, 2024
fa4aea8
added aggregations
robmeth Apr 8, 2024
526b258
updated member access and added expression statements
robmeth Apr 13, 2024
89b47e8
renaming Sds to Tsl
robmeth Apr 15, 2024
70747a7
fixed the link to visibility modifier
robmeth Apr 15, 2024
2c70190
implement comments in pull request
robmeth Apr 16, 2024
600a4e6
docs: add documentation comments
alex-senger Apr 16, 2024
b462ea0
docs: add missing reference to documentation comments
alex-senger Apr 16, 2024
56a4e91
docs: update data documentation - remove default value
alex-senger Apr 17, 2024
997fdf2
docs: update expressions - single value returns and fix indentation
alex-senger Apr 17, 2024
14e0ca1
Apply suggestions from code review
alex-senger Apr 17, 2024
b87dae9
docs: apply changes from code review for modifiers
alex-senger Apr 18, 2024
d62d773
docs: change conditional expression to statement
alex-senger Apr 18, 2024
07a7d7b
docs: add int, float, string and boolean to types
alex-senger Apr 21, 2024
a1a1eff
docs: update validity
alex-senger Apr 21, 2024
e0c6fdc
docs: fix warnings and remove validity from data
alex-senger Apr 21, 2024
19ebe85
docs: fix warnings and add semicolons to examples
alex-senger Apr 21, 2024
de607d7
Merge branch 'main' into 18-language-design
alex-senger Apr 21, 2024
e789799
docs: add functionality of leaving out upper bound for temporal validity
alex-senger Apr 24, 2024
1c96f8b
Merge branch 'main' into 18-language-design
lars-reimann Apr 30, 2024
7bbaa81
Merge branch 'main' into 18-language-design
lars-reimann Apr 30, 2024
9ed41a0
docs: fix broken link
lars-reimann Apr 30, 2024
cede1bd
Merge branch 'main' into 18-language-design
alex-senger May 2, 2024
aebdc42
docs: update mkdocs.yml
alex-senger May 2, 2024
4047e36
docs: fix typos
alex-senger May 2, 2024
7e32a57
docs: remove readme
alex-senger May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions docs/language/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions docs/language/common/README.md

This file was deleted.

23 changes: 23 additions & 0 deletions docs/language/common/aggregations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Aggregations

To _aggregate_ [data][data] [grouped by][grouped by] an [ID][id] over a [function][functions] we can use the aggregation expression:

```ttsl
aggregate sum of salery, taxes groupedBy hh_id
```

Let's break down the syntax:

- The keyword `#!ttsl aggregate`.
- The [function][functions] to be executed on the grouped values (here `#!ttsl sum`).
- The keyword `#!ttsl of`.
- A [List][List] of [data][data] separated by a comma (here `#!ttsl salery, taxes`).
- The [grouped by][grouped by] modifier (here with the id `#!ttsl hh_id`).

An aggregation can be executed on one or multiple data values that are all connected to the same given [ID][id].

[data]: data.md
[grouped by]: modifier.md#grouped-by
[id]: modifier.md#id
[functions]: functions.md
[List]: types.md#lists
82 changes: 31 additions & 51 deletions docs/language/common/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ Comments are mostly used to add explanations to the code for future readers —
used to "comment out" code that you want to keep but that should not be run right now, since comments are ignored by the
compiler.

Safe-DS has three types of comments, namely
TTSL has two types of comments, namely

* [_line comments_](#line-comments), which end at a linebreak,
* [_block comments_](#block-comments), which can cover multiple lines, and
* [_documentation comments_](#documentation-comments), which are used to specify the documentation for declarations.
* [_line comments_](#line-comments), which end at a linebreak, and
* [_block comments_](#block-comments), which can cover multiple lines.
alex-senger marked this conversation as resolved.
Show resolved Hide resolved
* [_documentation comments_](#documentation-comments), which are used to document declarations.

## Line Comments

Line comments stop at the end of a line:

```sds
// This is a comment.
```ttsl
# This is a comment.
```

They start with `#!sds //`. There must be no space between the slashes. Everything after the double slashes in the same
They start with `#!ttsl #`. Everything after the # in the same
line is the text of the comment.

To use line comments to "comment out" code you edit in VS Code, select the code and press ++ctrl+slash++ on your
keyboard. This will add `#!sds //` to the beginning of each selected line. You can also trigger this functionality by
keyboard. This will add `#!ttsl #` to the beginning of each selected line. You can also trigger this functionality by
using the `Toggle Line Comment` command in the command palette. To remove the line comments, select the commented code
and press ++ctrl+slash++ again.

## Block Comments

Block comments have a start and end delimiter, which allows them to cover multiple lines:

```sds
```ttsl
/*
This
is
Expand All @@ -39,11 +39,11 @@ comment
*/
```

They start with `#!sds /*` and end at the inverted delimiter `#!sds */`. There must be no space between the slash
They start with `#!ttsl /*` and end at the inverted delimiter `#!ttsl */`. There must be no space between the slash
and the star. Block comments cannot be nested. Everything in between the delimiters is the text of the comment.

To use block comments to "comment out" code you edit in VS Code, select the code and press ++ctrl+shift+slash++ on your
keyboard. This will surround the selected code with `#!sds /*` and `#!sds */`. You can also trigger this functionality
keyboard. This will surround the selected code with `#!ttsl /*` and `#!ttsl */`. You can also trigger this functionality
by using the `Toggle Block Comment` command in the command palette. To remove the block comment, select the commented
code and press ++ctrl+shift+slash++ again.

Expand All @@ -53,14 +53,14 @@ Documentation comments are special [block comments](#block-comments) that are us
documentation is used in various places, e.g. when hovering over a declaration or one of its usage in VS Code. Here is
an example:

```sds
```ttsl
/**
* This is a documentation comment.
*/
class C
function f() { ...
```

They start with `#!sds /**` and end with `#!sds */`. There must be no spaces inside the delimiters. Documentation
They start with `#!ttsl /**` and end with `#!ttsl */`. There must be no spaces inside the delimiters. Documentation
comments cannot be nested. Everything in between the delimiters is the text of the comment, except an optional leading
asterisk in each line, which is ignored. Documentation comments are attached to the declaration that follows them. If
there is no declaration following the documentation comment, it is treated as a normal [block comment](#block-comments),
Expand All @@ -70,11 +70,11 @@ with no special meaning.

Documentation comments support [Markdown](https://www.markdownguide.org/) to format the text. Here is an example:

```sds
```ttsl
/**
* This is a documentation comment with **bold** and *italic* text.
*/
class C
function f() { ...
```

### Tags
Expand All @@ -86,75 +86,55 @@ Documentation comments can contain tags to provide structured information.
`{@link}` is an **inline** tag that can be used to link to another declaration. It takes the name of the declaration as
an argument:

```sds
```ttsl
/**
* Computes the sum of two {@link Int}s.
*/
fun sum(a: Int, b: Int): sum: Int
function sum(x: Int, y: Int): Int { ...
```

#### `@param`

Use `@param` to document a [parameter][parameter] of a callable declaration. This tag takes the name of the parameter
Use `@param` to document a parameter of a callable declaration. This tag takes the name of the parameter
and its description as arguments. Since a callable can have multiple parameters, this tag can be used multiple times.

```sds
```ttsl
/**
* ...
*
* @param a The first integer.
* @param b The second integer.
* @param x The first integer.
* @param y The second integer.
*/
fun sum(a: Int, b: Int): sum: Int
function sum(x: Int, y: Int): Int { ...
```

#### `@result`

Use `@result` to document a [result][result] of a callable declaration. This tag takes the name of the result and its
Use `@result` to document a [result](functions.md) of a callable declaration. This tag takes the name of the result and its
description as arguments. Since a callable can have multiple results, this tag can be used multiple times.

```sds
```ttsl
/**
* ...
*
* @result sum The sum of `a` and `b`.
* @result sum The sum of `x` and `y`.
*/
fun sum(a: Int, b: Int): sum: Int
```

#### `@typeParam`

Use `@typeParam` to document a [type parameter][type-parameter] of a generic declaration. This tag takes the name of the
type parameter and its description as arguments. Since a generic declaration can have multiple type parameters, this
tag can be used multiple times.

```sds
/**
* ...
*
* @typeParam T The type of the elements in the list.
*/
class List<T>
function sum(x: Int, y: Int): Int { ...
```

#### `@since`

The `@since` tag can be used to specify when a declaration was added. It takes the version as argument and should be
used only once.

```sds
```ttsl
/**
* ...
*
* @since 1.0.0
*/
fun sum(a: Int, b: Int): sum: Int
function sum(x: Int, y: Int): Int { ...
```

[^1]: Except [parameter][parameter], [results][result], and [type parameters][type-parameter], which are documented with
the [`@param`](#param), [`@result`](#result), and [`@typeParam`](#typeparam) tags on the containing declaration,
respectively.

[parameter]: parameters.md
[result]: results.md
[type-parameter]: ../stub-language/type-parameters.md
[^1]: Except parameters and results, which are documented with the [`@param`](#param) and [`@result`](#result) tags on
the containing declaration, respectively.
33 changes: 33 additions & 0 deletions docs/language/common/constants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Constants

_Constants_ define a constant value, that can only be defined once and can not be changed. A constant has a certain [type][types], [visibility][Visibility] and [validity][Validity].

```ttsl
constant value1: Int = 1


Here are the pieces of syntax:

- The keyword `#!ttsl constant`
- The name of the constant (here `#!ttsl value1`). This can be any combination of upper- and lowercase letters, underscores, and numbers, as long as it does not start with a number. However, we suggest to use `#!ttsl lowerCamelCase` for the names of parameters.
- A colon.
- The [type][types] of the constant (here `#!ttsl Int`).
- An equals sign.
- The value of the constant (here `#!ttsl 1`). This must be a constant [expression][Expressions], i.e. something that can be evaluated by the compiler. Particularly [calls][calls] usually do not fulfill this requirement.

## Visibility

The [visibility][Visibility] of constants can be chosen by putting one of the three keywords `public`, `packageprivate`, `private` in front of the constant declaration. The default [visibility][Visibility] is public. Here is an example:

```ttsl
packageprivate constant value1: Int = 1
```

## Validity

The documentation for the [validity of constants][constantValidity] can be found in the [validity][Validity] section.

[types]: types.md
[Visibility]: modifier.md#visibility
[Validity]: validity.md
[constantValidity]: validity.md#constants
35 changes: 35 additions & 0 deletions docs/language/common/data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Data

_Data_ defines a value given by the user via an input. It can then be accessed via a chosen namespace. Data has a certain [type][types], [visibility][Visibility], [validity][Validity] and can be an [id][id].

```ttsl
data PersonAge: Int;
```

Here are the pieces of syntax:

- The keyword `#!ttsl data`
- The name of the data (here `#!ttsl PersonAge`). This can be any combination of upper- and lowercase letters, underscores, and numbers, as long as it does not start with a number. However, we suggest to use `#!ttsl lowerCamelCase` for the names of parameters.
- A colon.
- The [type][types] of the data (here `#!ttsl Int`). Data can only be and Int, Float, Boolean or String.

## Visibility

The [visibility][Visibility] of data can be chosen by putting one of the three keywords `public`, `packageprivate`, `private` in front of the constant declaration. The default [visibility][Visibility] is public. Here is an example:

```ttsl
packageprivate data PersonAge: Int;
```

## ID

There can also be an [ID modifier][id] added to the data to implicate that the data is unique and can be used to identify an object. The [ID modifier][id] is added by placing the keyword `id` in front of the data declaration. For example:

```ttsl
id data PersonID: Int;
```

[types]: types.md
[id]: modifier.md#id
[Visibility]: modifier.md#visibility
[Validity]: validity.md
Loading
Loading