Skip to content

Commit 46c75bc

Browse files
authored
Update extension used by Technique files (#74)
Ironically, the compiler itself doesn't actually care about the extension of the input file, but the samples in the repository needed updating to the new _.tq_ extension. Bumps major version to 0.4, representing both this change and the milestone of having completed the first iteration of the v1 parser! While we're at it, move the golden test examples to _tests/golden/_, other examples that we expect to parse but not necessarily be perfectly formatted (after all, that's the whole point of the parser being as permissive as possible) to _tests/sample/_, and known-bad edge cases to _tests/broken/_. This allows us to run the known-good and known-bad exampkes through the parser as part of the test suite, so we've added an additional test to do that.
2 parents ac0efe8 + ab50221 commit 46c75bc

File tree

16 files changed

+366
-190
lines changed

16 files changed

+366
-190
lines changed

Cargo.lock

Lines changed: 150 additions & 174 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "technique"
3-
version = "0.3.6"
3+
version = "0.4.0"
44
edition = "2021"
55
description = "A domain specific language for procedures."
66
authors = [ "Andrew Cowie" ]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
% technique v1
2+
! MIT; © 2024 ACME, Inc
3+
& checklist
4+
5+
making_coffee : Ingredients -> Coffee
6+
7+
# Heading
8+
9+
Ask these questions: are you really sure you want a coffee?
10+
11+
Assuming you do, then:
12+
13+
1. { repeat <making_coffee>(e) ~ cups }
14+
a. First task
15+
b. Second another task
16+
'Yes' | 'No'
17+
2. Do things { exec(
18+
```bash
19+
./stuff
20+
```
21+
) }
22+
23+
another_example(e) : Input -> Output
24+
{
25+
[
26+
"answer" = 42
27+
"Question Time" = "What is the question?"
28+
"timestamp" = now()
29+
"message" = e
30+
"interpolation" = "The value is { e }"
31+
]
32+
}

src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ fn main() {
5656
.action(ArgAction::Version))
5757
.subcommand(
5858
Command::new("check")
59-
.about("Syntax- and type-check the given procedure")
59+
.about("Validate the syntax, structure, and types in the given Technique document.")
6060
.arg(
6161
Arg::new("watch")
6262
.long("watch")
6363
.action(clap::ArgAction::SetTrue)
64-
.help("Watch the given procedure file and recompile if changes are detected."),
64+
.help("Watch the given file containing a Technique document and recompile if changes are detected."),
6565
)
6666
.arg(
6767
Arg::new("output")
@@ -75,12 +75,12 @@ fn main() {
7575
.arg(
7676
Arg::new("filename")
7777
.required(true)
78-
.help("The file containing the code for the procedure you want to type-check."),
78+
.help("The file containing the code for the Technique you want to type-check."),
7979
),
8080
)
8181
.subcommand(
8282
Command::new("format")
83-
.about("Code format the given procedure")
83+
.about("Format the code in the given Technique document.")
8484
.arg(
8585
Arg::new("raw-control-chars")
8686
.short('R')
@@ -100,29 +100,29 @@ fn main() {
100100
.arg(
101101
Arg::new("filename")
102102
.required(true)
103-
.help("The file containing the code for the procedure you want to format."),
103+
.help("The file containing the code for the Technique you want to format."),
104104
),
105105
)
106106
.subcommand(
107107
Command::new("render")
108-
.about("Render the Technique procedure into a printable PDF")
109-
.long_about("Render the Technique procedure into a printable \
108+
.about("Render the Technique document into a printable PDF.")
109+
.long_about("Render the Technique document into a printable \
110110
PDF. By default this will highlight the source of the \
111111
input file for the purposes of reviewing the raw \
112-
procedure.")
112+
procedure in code form.")
113113
.arg(
114114
Arg::new("output")
115115
.short('o')
116116
.long("output")
117117
.value_parser(["typst", "none"])
118118
.default_value("none")
119119
.action(ArgAction::Set)
120-
.help("Output format: pdf (default) or typst markup.")
120+
.help("Which kind of diagnostic output to print when rendering.")
121121
)
122122
.arg(
123123
Arg::new("filename")
124124
.required(true)
125-
.help("The file containing the code for the procedure you want to print."),
125+
.help("The file containing the code for the Technique you want to print."),
126126
),
127127
)
128128
.get_matches();

tests/broken/BadDeclaration.tq

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
making_coffee : Ingredients Coffee

tests/broken/IllegalUnitSymbol.tq

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
% technique v1
2+
3+
result :
4+
{
5+
[
6+
"speed" = 3.0 × 10⁸ m_s
7+
"weight" = 84.0 +/- 3.6 kg
8+
"height" = 1.93 * 10^2 cm
9+
]
10+
}

tests/broken/MagicLine.tq

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
% technique v0
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
% technique v1
2+
3+
another_example(e) : Input -> Output
4+
{
5+
[
6+
"answer" = 42
7+
"Question Time" = "What is the question?"
8+
"timestamp" = now()
9+
"message" = e
10+
"interpolation" = "The value is { e "
11+
]
12+
}

tests/formatting/golden.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ mod examples {
5959

6060
#[test]
6161
fn ensure_identical_output() {
62-
// Read all .t files from examples/prototype/
63-
let dir = Path::new("examples/golden");
62+
// Read all .tq files from examples/prototype/
63+
let dir = Path::new("tests/golden/");
6464

6565
// Ensure the directory exists
6666
assert!(dir.exists(), "examples directory missing");
6767

68-
// Get all .t files in the directory
68+
// Get all .tq files in the directory
6969
let entries = fs::read_dir(dir).expect("Failed to read examples directory");
7070

7171
let mut files = Vec::new();
@@ -76,14 +76,14 @@ mod examples {
7676
if path
7777
.extension()
7878
.and_then(|s| s.to_str())
79-
== Some("t")
79+
== Some("tq")
8080
{
8181
files.push(path);
8282
}
8383
}
8484

8585
// Ensure we found some test files
86-
assert!(!files.is_empty(), "No .t files found in examples directory");
86+
assert!(!files.is_empty(), "No .tq files found in examples directory");
8787

8888
let mut failures = Vec::new();
8989

0 commit comments

Comments
 (0)