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

Keep wiki sources in main repository #21

Merged
merged 9 commits into from
Aug 11, 2023
29 changes: 29 additions & 0 deletions .github/workflows/wiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Synchronize Wiki

on:
push:
paths:
- StepLang.Wiki/**
- .github/workflows/wiki.yml
branches:
- main

jobs:
sync:
name: Synchronize Wiki
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Pull GitHub Wiki
run: git clone https://github.com/$GITHUB_REPOSITORY.wiki.git _wiki
- name: Update Wiki files
run: |
rsync -av --delete StepLang.Wiki/ _wiki/ --exclude .git --exclude StepLang.Wiki.csproj
- name: Push Docs to GitHub Wiki
run: |
cd _wiki
git add .
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git commit -m "${{ github.event.head_commit.message }} (${{ github.sha }})"
git push -f --set-upstream https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.wiki.git master
3 changes: 3 additions & 0 deletions STEP.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{
ProjectSection(SolutionItems) = preProject
.github\workflows\publish.yml = .github\workflows\publish.yml
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
.github\workflows\wiki.yml = .github\workflows\wiki.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StepLang.Wiki", "StepLang.Wiki\StepLang.Wiki.csproj", "{C7B31C5F-7112-4CFB-BBC0-15764540545D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
53 changes: 53 additions & 0 deletions StepLang.Wiki/Code-Style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
> # **Work In Progress**
>
> The current state of this document does not reflect the final design.
> It is merely a draft.

A code style is commonly referred to as the way code is written in the literal sense.
It specifies where and how certain tokens should be placed and dictates use of punctuation and white spaces.
As many programming languages support different styles of writing code, there also exist many different opinions on what is "the correct" or "the best" way.
This code style guide is intended to reduce cognitive friction when reading code from different authors (with different preferences for code style) and to establish a "one-true-way" to write STEP code.
It was inspired by PHPs [PSR-12](https://www.php-fig.org/psr/psr-12/).

Keeping a consistent code style among a projects source code helps understand the code at a glance and ensures a high level of technical interoperability between shared code.

# 1. General

## 1.1 Files

- Files MUST use only UTF-8 encoding without BOM for STEP code
- Files MUST end with the `.step` extension
- Files SHOULD use Unix LF (linefeed) line ending

## 1.2 Lines

- Lines SHOULD not be longer than 80 characters; longer lines should be wrapped
- There MUST NOT be trailing whitespace at the end of lines
- Blank lines MAY be added to improve readability and to indicate related blocks of code
- A line MUST not contain more than one statement

## 1.3 Casing

- Variable names should be declared in `camelCase` (including functions)
- All STEP keywords must be in lower case (DON'T: `IF` `If` `While` `ImPort`, DO: `if`, `while`, `import`)

## 1.4 Indenting

- Code MUST be indented using tabs (for accessibility; [ref1](https://adamtuttle.codes/blog/2021/tabs-vs-spaces-its-an-accessibility-issue/); [ref2](https://alexandersandberg.com/articles/default-to-tabs-instead-of-spaces-for-an-accessible-first-environment/))

# 2. Statements

## 2.1 `if` and `else`

An `if` structure looks like the following.
Note the placement of parentheses, indentation and braces.
Also notice that the `if` and `else` keywords are on the same line as the braces.

```step
if (name != "John") {
println("Hello, ", name)
} else {
println("Not you again, John")
}
```

294 changes: 294 additions & 0 deletions StepLang.Wiki/Error-Reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
This page explains errors you may encounter while programming.

## `IncompatibleVariableTypeException`

This exception is thrown when a variable is assigned a value of an incompatible type.

For example:

```step
string myVariable = 1
```

This will throw an `IncompatibleVariableTypeException` because `myVariable` is of type `string`, but `1` is of type `number`.

To fix this, make sure the value assigned to the variable is of the same type as the variable:

```step
number myVariable = 1
```

Or:

```step
string myVariable = "1"
```

## `InvalidArgumentCountException`

This exception is thrown when a function is called with an invalid number of arguments.

For example:

```step
jsonDecode()
```

This will throw an `InvalidArgumentCountException` because `jsonDecode()` requires one argument.

Correct usage:

```step
string myJsonString = "{\"hello\": \"world\"}"

jsonDecode(myJsonString)
```

## `InvalidExpressionTypeException`

This exception is thrown when an expression is used in an invalid context.

For example:

```step
_ = typename("string")
```

This will throw an `InvalidExpressionTypeException` because `typename()` is expects an expression of type `variable`, not `string` as shown here.

Another example with a different expression:

```step
_ = typename(1 + 2)
```

In this case, the expression result of `1 + 2` is of type `number` (value: `3`), and not `variable`.

Correct usage:

```step
string myVariable = "string"

_ = typename(myVariable)
```

Or with a different expression:

```step
number myVariable = 1 + 2

_ = typename(myVariable)
```

## `InvalidResultTypeException`

This exception is thrown when an expression results in an unexpected type.

For example:

```step
string myVariable = 1 + 2
```

This will throw an `InvalidResultTypeException` because the expression `1 + 2` results in a `number` (value: `3`), and not a `string` as expected.

Another example:

```step
number myVariable = "hello world"
```

This will throw an `InvalidResultTypeException` because the expression `"hello world"` results in a `string` (value: `"hello world"`), and not a `number` as expected.

Correct usage:

```step
string myVariable = "1" + "2"
```

Or with a different expression:

```step
number myVariable = 1 + 2
```

## `ListIndexOutOfBoundsException`

This exception is thrown when a list is accessed with an invalid index.

For example:

```step
list myList = ["hello", "world"]

_ = myList[2]
```
The list `myList` has two elements, so the index `2` is out of bounds.
The bounds being all whole number from `0` to `1` (inclusive).

Correct usage:

```step
list myList = ["hello", "world"]

_ = myList[0]
```

## `UndefinedIdentifierException`

This exception is thrown when an identifier is used that was not declared.

For example:

```step
println(myVariable)
```

This will throw an `UndefinedIdentifierException` because `myVariable` was not declared.

Correct usage:

```step
string myVariable = "hello world"

println(myVariable)
```

## `IncompatibleExpressionOperandsException`

This exception is thrown when an expression is used with operands that have incompatible types.

For example:

```step
println(1 + "hello")
```

This will throw an `IncompatibleExpressionOperandsException` because the expression `1 + "hello"` has operands of type `number` and `string` respectively, which cannot be used with the `+` operator.

Correct usage:

```step
println("1" + "hello")
```

Or with a different expression:

```step
println(1 + 2)
```

## `InvalidArgumentTypeException`

This exception is thrown when a function is called with an argument of an unexpected type.

For example:

```step
jsonDecode(1)
```

This will throw an `InvalidArgumentTypeException` because `jsonDecode()` expects a `string` argument, not a `number` as shown here.

To fix this, pass an argument of the expected type:

```step
jsonDecode("{\"hello\": \"world\"}")
```

## `InvalidExpressionException`

This exception is thrown when an expression is invalid.

For example:

```step
number a = 1 + ()
```

This will throw an `InvalidExpressionException` because a pair of empty parentheses `()` is not a valid expression.

To fix this, either:

Replace the empty parentheses with a valid expression:

```step
number a = 1 + 2
```

or with a valid expression surrounded by parentheses:

```step
number a = 1 + (2)
```

## `InvalidFunctionCallException`

See [`InvalidArgumentCountException`](#invalidargumentcountexception) and [`InvalidArgumentTypeException`](#invalidargumenttypeexception).

## `InvalidIndexOperatorException`

This exception is thrown when the index operator `[]` is used in an invalid context.

For example:

```step
string a = "hello"

a[0] = "H"
```

This will throw an `InvalidIndexOperatorException` because the index operator `[]` cannot be used with a `string` to set values.

Or:

```step
list a = ["hello", "world"]

println(a["key"])
```

This will throw an `InvalidIndexOperatorException` because the index operator `[]` used on a `list` only accepts `number` indexes.

To fix this, make sure the variable you're trying to use the index operator on can be used with the index operator (`list` or `map`) and that the index value has the correct type (`number` for `list`s and `string` for `map`s).
`string` values can also be indexed using number indexes to read single character of a string, but not to write to a string.

## `ImportedFileDoesNotExistException`

This exception is thrown when a file that is imported does not exist.

If the path is absolute, make sure it exists.
If the path is relative, make sure it exists relative to the file that is importing it.

## `ImportedFileIsSelfException`

This exception is thrown when a file imports itself.

If this was not intended, check the path given to the `import` statement.

## `ImportsNoLongerAllowedException`

This exception is thrown when a file tries to import another file after the first statement.

For example:

```step
println("hello world")

import "other-file.step"
```

This will throw an `ImportsNoLongerAllowedException` because the `import` statement appears after the `println` statement in the file.

To fix this, move the `import` statement to the top of the file:

```step
import "other-file.step"

println("hello world")
```

## `InvalidVariableAssignmentException`

See [`IncompatibleVariableTypeException`](#incompatiblevariabletypeexception).

Loading