Skip to content

Commit 860093e

Browse files
authored
Merge pull request #58 from usethesource/adopt-tutor-docs
cloned Tutor documentation from deprecated rascal-tutor project to here
2 parents f103d08 + d9483cb commit 860093e

55 files changed

Lines changed: 2679 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

courses/Tutor/API/API.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: API documentation
3+
---
4+
5+
#### Synopsis
6+
7+
The Tutor compiler reads Rascal source files and produces ((Concept)) markdown files
8+
for each Rascal module.
9+
10+
#### Description
11+
12+
The compiler generates for every `Module.rsc` a markdown file with the following structure:
13+
14+
``````
15+
---
16+
title: <moduleName>
17+
---
18+
19+
// for each declaration (function, data, syntax, alias, import, extend)
20+
## <declarationName> {#fully-qualified-declaration-name}
21+
22+
#### Synopsis
23+
24+
...
25+
#### Description
26+
...
27+
28+
// etc.
29+
``````
30+
31+
So, for all standard ((Concept)) headers, like `Synopsis` and `Benefits` there is a place at every declaration.
32+
33+
The content of the header paragraphs is either directly derived from source code (like function signature and data definitions), or it is taken from the following tag definitions on each declaration:
34+
* `@doc` may contain literally the headers of a ((Concept)), like `#### Synopsis`. This notation is deprecated in favor of the tags below.
35+
* `@synopsis` is a single line description of the definition.
36+
* `@description` is a multi-line explanantion of the definition.
37+
* `@benefits`, `@pitfalls`, `@examples`, `@types`, `@name` and `@function` each follow the intent of the standard ((Concept)) headers.
38+
39+
The documentation written for features without an explicit synopsis is not rendered. In other words it is obligatory to use at least a `@synopsis` tag or start with a `#### Synopsis` header..
40+
41+
#### Benefits
42+
43+
* A (small) part of documentation writing is automated. The information about the name of a function, data or annotation declaration, or its signature is always consistent.
44+
* You can write examples of the usage of each definition using ((Listing)) markup that is run and checked at documentation compile-time.
45+
46+
#### Pitfalls
47+
48+
* This approach requires that functions with the same name are grouped together in the source file.
49+
* You need to run the tutor compiler before errors in the documentation tags are detected.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Architecture
3+
---
4+
5+
#### Synopsis
6+
7+
The global architecture of the Rascal Tutor
8+
9+
#### Description
10+
11+
The Rascal Tutor is a Markdown and Rascal source file pre-processor. As input it takes [Docusaurus Markdown](https://docusaurus.io/docs/markdown-features/) files organized in hierarchical folders, and Rascal modules organized in hierarchical packages. One root folder is called a "course". As output the pre-processor produces per course
12+
a folder hierarchy again, where each folder has its own `index.md` file (generated or written). After the tutor
13+
compiler has generated such a consistent folder of interconnected markdown files, other downstream processors can turn them into (static) html websites, pdf files or otherwise. The standard way of processing is to use the [Docusaurus](https://docusaurus.io) static website generator.
14+
15+
The important features of the pre-processor, "compiler", are:
16+
17+
1. The compiler is configured via `util::Reflective::PathConfig`, where:
18+
* each entry in the `srcs` list is a single _course_
19+
* each entry in the `libs` list, be it a jar file or not, is searched for an `index.value` file to augment the current index.
20+
1. Concept hierarchy - each folder `/X` has its own index file, called either `X/X.md` or `X/index.md`. Nested folders equal nested concepts.
21+
1. Indexing - to help in easy cross-linking between concepts:
22+
* Each concept of course `A` stored in `X/Y/Z/Z.md` may be linked via `Z`, `Y-Z`, `X-Y-Z`, `A:Z`, `A:Y-Z`, `A:X-Y-Z`
23+
* Each Rascal module of course `A` named `a::b::C` may be linked via `C`, `b-C`, `a::b::C`, `module:a::b::C`, `A:C`, `A:b-C`, `A:a::b::C`, `A:module:a::b::C`
24+
* Each Rascal package of course `A` named `a::b` may be linked via `b`, `a::b`, `package:a::b`, `A:b`, `A:a::b`, `A:module:a::b`
25+
* Each image `x.{png,svg,jpg,jpeg}` stored in `X/Y/Z` may be linked as though it were a concept file.
26+
* The index is a `rel[str,str]` from the above described links to the `index.md` files in the generated hierarchy.
27+
* The compiler reports missing links and ambiguous links as errors.
28+
* A single `index.value` file is written in the output folder for future reference by depending projects.
29+
1. Code execution ensures lively demonstrations which are checked for correctness.
30+
* Code blocks marked `rascal-shell` are executed line-by-line on the REPL prompt. Each prompt starts with a fresh environment. All error and standard output is captured and printed back. The `Content` module that serves HTML or any other file is also inlined in the output Markdown file.
31+
* Code blocks marked `rascal-shell,continue` are executed in the previously constructed environment (from top to bottom in the Markdown file) and behave the same otherwise.
32+
* Code blocks marked `rascal-prepare` with or without `continue` behave the same as above, except that no output or input is printed back into the output file.
33+
1. Links written between `((` and `))` are resolved using the previously described index.
34+
1. Table of contents are generated for the word TOC between three `(((` brackets `)))`; the content of each concept is the concept nested under it in the hierarchy.
35+
1. Each Rascal file is indexed to list the declarations it contains and information is extracted:
36+
* data declarations with their `doc`, `synopsis`, `examples` etc. tags
37+
* (overloaded) function declarations with their `doc`, `synopsis`, `examples` etc. tags
38+
* alias declarations with their `doc`, `synopsis`, `examples` etc. tags
39+
1. Screenshots of interactive ((Library:module:Content) visualizations can be made by configuring the compiler to use selenium and chrome.
40+
41+
Features on the TODO list are:
42+
1. Interactive Questions (have to be revived)
43+
44+
45+
To implement these features the following components are relevant:
46+
* `lang::rascal::tutor::Indexer` implements indexing and lookup
47+
* `lang::rascal::tutor::Compiler` implements linking, code execution, toc, and the generation of index files.
48+
* `lang::rascal::tutor::apidoc::ExtractInfo` parses Rascal code and generates an intermediate overview
49+
* `lang::rascal::tutor::apidoc::GenerateMarkdown` generates a single Markdown file for each Rascal module, and also reuses `Compiler` to process embedded markdown with code examples, links, etc.
50+
* `lang::rascal::tutor::repl::TutorCommandExecutor` encapsulates a Rascal REPL as a set of closures (`eval`, `reset`, and `prompt`)
51+
* for efficiency's sake a single executor is shared among all Markdown and Rascal files that are compiled in a single run. Between every file the executor is reset for a new environment, but previously loaded modules remain in the heap available for reuse.
52+
53+
#### Benefits
54+
55+
* Index creation is modular: an index is created per course and these indices are combined at runtime.
56+
* Code execution is reasonably time efficient, although it may require quite some memory because eventually an entire course will be loaded.
57+
58+
#### Pitfalls
59+
60+
* Courses are compiled on a per-course basis. Support for incremental courses compilation is not yet available.
61+
* Badly balanced code block quotes are not detected by this pre-processor but will fail HTML compilation downstream.
62+
* Manual links are not checked at compile-time by this pre-processor but fill fail HTML compilation downstream.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Authoring
3+
---
4+
5+
#### Synopsis
6+
7+
Creating and writing a course for the Rascal Tutor.
8+
9+
#### Syntax
10+
11+
#### Types
12+
13+
#### Function
14+
15+
#### Description
16+
17+
The life cycle of a course consists of the following steps:
18+
19+
* A new course, say `MyCourse`, is created. This is achieved by:
20+
* Creating a subdirectory named `MyCourse` in the `courses` directory of the current Rascal project.
21+
* Creating a file `MyCourse/MyCourse.md`. This is the root concept of the new course.
22+
* The contents of the course are created by populating the course with subconcepts of the root concept.
23+
* A subconcept, say `CoolIdea` is created by:
24+
* Creating a subdirectory `CoolIdea` of its parent concept.
25+
* Creating a file `CoolIdea/CoolIdea.md` that describes the concept.
26+
* Alternatively, a file `CoolIdea/index.md` works too.
27+
* Renaming/moving/deleting concepts is done at the directory/file level.
28+
29+
Concepts are represented as directories for the following reasons:
30+
31+
* To represent subconcepts as subdirectories.
32+
* To contain all figures and other files that are included in the concept. In this way:
33+
* A complete concept can be easily moved or renamed as a single unit.
34+
* Name clashes between included files per concept are avoided.
35+
36+
#### Examples
37+
38+
#### Benefits
39+
40+
* You can use your favourite Markdown editor and standard system commands to author a course.
41+
* The output of the Tutor compiler is Markdown/HTML that you can process further with any tool you like
42+
* Links to other concepts are all _relative_ to a root directory with all the courses. So `../../Course/A/index.md` would be a link generated from a link to `A` in `/Course/Z/index.md`. This makes it easy to include courses in a website at any subfolder.
43+
* The index that is generated for every project with several courses can be reused by other projects to generate consistent cross-referencing. For example a project `flybytes` which depends on the `rascal` project which contains the `Library` course, could use `Library:IO` to refer to the documentation about the `IO` module in the standard library of Rascal.
44+
45+
#### Pitfalls
46+
47+
* Special features like code execution and cross-referencing concepts are not implemented by generic Markdown editors, so you have to wait and see what happens until you compile the course.
48+
* All images are referenced from `/assets/` so images have to be installed there on any website you want to include the documentation in.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
title: Tutor Compilation
3+
keywords:
4+
- compilation
5+
- compiler
6+
- configuration
7+
- maven
8+
- deployment
9+
- incremental
10+
- dependency
11+
- dependencies
12+
---
13+
14+
After ((Authoring)) tutor files, they have to compiled down to plain docusaurus. The compiler implements features such as linking, screenshots, and executing code fragments.
15+
Most importantly, when there are linking errors (missing or ambiguous) or code execution errors, the compiler reports them such that they can be fixed before releasing the documentation.
16+
17+
## Configuration
18+
19+
The way to execute the rascal tutor compiler is via [rascal-maven-plugin](http://github.com/usethesource/rascal-maven-plugin). First it
20+
has to be configured for your project.
21+
22+
Do configure the tutor, add the plugin to the pom.xml like so:
23+
24+
```xml
25+
<plugins>
26+
<plugin>
27+
<groupId>org.rascalmpl</groupId>
28+
<artifactId>rascal-maven-plugin</artifactId>
29+
<version>0.16.0</version>
30+
<executions>
31+
<execution>
32+
<id>default-cli</id>
33+
<phase>compile</phase>
34+
<goals>
35+
<goal>tutor</goal>
36+
</goals>
37+
<configuration>
38+
<enableStandardLibrary>false</enableStandardLibrary>
39+
<errorsAsWarnings>false</errorsAsWarnings>
40+
<isPackageCourse>true</isPackageCourse>
41+
<bin>${project.build.outputDirectory}</bin>
42+
<srcs>
43+
<src>${project.basedir}/doc/Course1</src>
44+
<src>${project.basedir}/doc/Course2</src>
45+
<src>${project.basedir}/src/main/rascal</src>
46+
</srcs>
47+
<ignores>
48+
<ignore>${project.basedir}/src/main/rascal/experimental</ignore>
49+
</ignores>
50+
</configuration>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
</plugins>
55+
```
56+
57+
1. `enableStandardLibrary` defines which library the links to standard library documentation refer to. Either the version of rascal that the rascal-maven-plugin depends on (`true`), or the version of rascal that the current project depends on (`false`). Also this defines which version of the library the code examples are executed against.
58+
2. `errorsAsWarnings` and `warningsAsError` define failure modes for the compiler. Maven will not fail if `errorsAsWarnings` is set to `true` even if there are errors.
59+
3. `isPackageCourse`, when set to `true` will nest all target documentation in `docs/Packages/projectName`, and rename `src/main/rascal` or `src` to `API`. All links will also be re-routed to these locations. Otherwise, when set to `false` all documentation ends up in `docs/Course1` and `docs/Course2`, etc.
60+
4. `bin` points to the place that defines the root of the resulting `jar` file. All generated files will endup in `bin/docs` and `bin/docs/assets`. This has to be the outputDirectory and if you forget to configure this, it will be set automatically anyway. The compiler also writes `bin/index.value` file after it is done, to store the entire linking index for future usage. This future use can be either the next run of the compiler, or a depending project downstream.
61+
5. `srcs` define root courses, some of which will be pure Concept hierarchies, and others could be the _root_ of Rascal source folders. Note that this also defines the search path for modules during code execution of `rascal-shell` blocks.
62+
6. `ignores` defines files or folders which are to be ignore. These could be folder names inside of Rascal source folders, or files of Rascal modules, or course concept folders, or course concept files. When a folder is ignored, this works transitively for the contents of that folder.
63+
64+
## Dependencies
65+
66+
If the current Maven project has dependencies then the `index.value` files in these jar files are located
67+
and imported in the current link index of the project. This allows you to refer to concepts in one of the
68+
projects you depend on, provided that project was also using the `rascal-maven-plugin` to run the tutor compiler.
69+
70+
The dependency feature depends on the assumption that the `/docs` folders in the jar of the current project and the jars of the
71+
project it depends on are extracted into the `docs` folder of a Docusaurus project later, and that everything
72+
under `/docs/assets` in the same jars is copied to `static/assets`. The `rascal-website` project
73+
achieves this using the `resources` plugin `copy` commands. If you are running your own docusaurus site,
74+
then this should be re-implemented.
75+
76+
## Execution
77+
78+
Simply run the maven `compile` or `package` or `install` command to trigger the rascal tutor compiler:
79+
80+
```bash
81+
$ mvn install
82+
```
83+
84+
However, to exclusively run the tutor you can try this:
85+
86+
```bash
87+
$ mvn rascal:tutor
88+
```
89+
90+
If there are screenshots in the documentation, then selenium must be configured with the location of `chrome` and `chromedriver`:
91+
92+
```bash
93+
$ mvn rascal:tutor -Dwebdriver.chrome.driver=`which chromedriver` -Dwebdriver.chrome.browser=`which chrome`
94+
```
95+
96+
Here we have used the bash feature to splice in the location of chromedrive and chrome using the `which` command. This requires both to
97+
be found on the system `PATH`. If this is not the case, provide the absolute path to the binaries of these two programs. Both on Mac
98+
and Windows the path to `Google Chrome`, for example, may contain many spaces and it is wise to wrap the path in double quotes.
99+
100+
The tutor compiler is **incremental** in a certain way. Running the compile twice in a row, only the markdown files and Rascal modules that have been modified will be compiled again. The compiler
101+
reuses the output of the previous run, including error messages. All error messages and warnings, including those of unmodified files are
102+
always presented at the end.
103+
104+
Simple run the tutor twice to recompile only what has changed:
105+
106+
```bash
107+
mvn rascal:tutor
108+
mvn rascal:tutor
109+
```
110+
111+
:::warning
112+
When folders or files are renamed, the old output files remain in the `bin` folder as well as the old links to those in the link index file.
113+
This can lead to:
114+
* spurious link ambiguity; for example when `A/B.md` has moved to `C/B.md` both versions of `B` will be present in the link administration.
115+
* unreported missing links; for example when `A/B.md` has moved to A/C.md`, `B` will still be linked even though it is not present anymore.
116+
117+
It is therefore always prudent to `mvn clean` such that the output directory including the `index.value` has been removed, when files or folder change name or location.
118+
:::
119+
120+
## Deployment of documentation
121+
122+
* When `mvn install` or `mvn package` is run with the correct configuration for the `bin` folder, then all markdown files and other assets (screenshots) end up in the `jar` file of the current project.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Benefits
3+
---
4+
5+
#### Synopsis
6+
7+
Briefly lists known advantages of the concept.
8+
9+
#### Syntax
10+
11+
```
12+
#### Benefits
13+
14+
_MarkedText_
15+
```
16+
17+
#### Types
18+
19+
#### Function
20+
21+
#### Description
22+
23+
#### Examples
24+
25+
#### Benefits
26+
27+
* Benefits allow a description of the, subjectively, positive aspects of a concept which is clearly delineated. This allows other sections to remain more factual and neutral.
28+
* Benefits alert newcomers to possibilities they would not have thought of otherwise.
29+
30+
#### Pitfalls
31+
32+
* Benefits sections may grow into bragging lists.

courses/Tutor/Concept/Concept.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Concept
3+
details:
4+
- Title
5+
- Keywords
6+
- Synopsis
7+
- Syntax
8+
- Types
9+
- Function
10+
- Details
11+
- Description
12+
- Examples
13+
- Benefits
14+
- Pitfalls
15+
---
16+
17+
#### Synopsis
18+
19+
A _concept_ is the basic building block of a course.
20+
21+
#### Syntax
22+
23+
* `module a/b/Concept` in `a/b/Concept.rsc`
24+
* Or a file `a/b/Concept/Concept.md`, `a/b/Concept/index.md`:
25+
``````
26+
---
27+
title: Concept Title
28+
keywords:
29+
- keyword1
30+
- keyword2
31+
---
32+
33+
#### Synopsis
34+
35+
This is the synopsis.
36+
37+
#### Description
38+
39+
#### Types
40+
41+
#### Function
42+
43+
#### Examples
44+
45+
#### Benefits
46+
47+
#### Pitfalls
48+
``````
49+
50+
All sections are optional, but not the title header. It is always recommended to have at least a Synopsis and some Examples. Empty sections are removed by the preprocessor.
51+
52+
#### Description
53+
54+
A concept describes a separate entity (idea, artefact, function, rule) that is relevant in the scope of the course in which it appears.
55+
It consists of the named sections above that are described separately.
56+
Each section starts with a keyword that should appear at the begin of a line.
57+
58+
Here is a brief summary of the sections of a concept:
59+
(((TOC)))
60+
61+

0 commit comments

Comments
 (0)