Skip to content

Commit 0d09bab

Browse files
authored
Fix parsing of simple Techniques with only top-level steps (#86)
Documents can be either series of Procedures (containing Technique) or a simple Techniques (with only top-level steps). For some reason parsing of the latter had regressed. Fixed. Add an example file to ensure simple documents like this are readily verifiable and ensure technique documents in both _tests/samples/_ and _examples/minimal/_ files are checked by the test suite.
2 parents f4cb1fa + 26bbbf8 commit 0d09bab

File tree

5 files changed

+63
-43
lines changed

5 files changed

+63
-43
lines changed

Cargo.lock

Lines changed: 30 additions & 36 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.4.5"
3+
version = "0.4.6"
44
edition = "2021"
55
description = "A domain specific language for procedures."
66
authors = [ "Andrew Cowie" ]

examples/minimal/SimpleList.tq

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1. Open door
2+
2. Through door
3+
3. Close door, accepting that it will make a smug and self-satisified
4+
sigh with the knowledge of a job well done.

src/parsing/parser.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ impl<'i> Parser<'i> {
252252
}
253253

254254
// Check if this Technique is a single set of one or more
255-
// top-level Scope::SectionChunk
256-
if is_section(self.source) && procedures.is_empty() {
255+
// top-level Scopes (steps or sections)
256+
if (is_section(self.source) || is_step(self.source)) && procedures.is_empty() {
257257
while !self.is_finished() {
258258
self.trim_whitespace();
259259
if self.is_finished() {
@@ -269,6 +269,24 @@ impl<'i> Parser<'i> {
269269
self.skip_to_next_line();
270270
}
271271
}
272+
} else if is_step_dependent(self.source) {
273+
match self.read_step_dependent() {
274+
Ok(step) => sections.push(step),
275+
Err(error) => {
276+
self.problems
277+
.push(error);
278+
self.skip_to_next_line();
279+
}
280+
}
281+
} else if is_step_parallel(self.source) {
282+
match self.read_step_parallel() {
283+
Ok(step) => sections.push(step),
284+
Err(error) => {
285+
self.problems
286+
.push(error);
287+
self.skip_to_next_line();
288+
}
289+
}
272290
} else {
273291
self.problems
274292
.push(ParsingError::Unrecognized(self.offset, 0));

tests/parsing/samples.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use std::path::Path;
33

44
use technique::parsing;
55

6-
#[test]
7-
fn ensure_parse() {
8-
let dir = Path::new("tests/samples/");
9-
6+
fn check_directory(dir: &Path) {
7+
// Ensure the directory exists
108
assert!(dir.exists(), "samples directory missing");
119

1210
let entries = fs::read_dir(dir).expect("Failed to read samples directory");
@@ -49,3 +47,9 @@ fn ensure_parse() {
4947
);
5048
}
5149
}
50+
51+
#[test]
52+
fn ensure_parse() {
53+
check_directory(Path::new("tests/samples/"));
54+
check_directory(Path::new("examples/minimal/"));
55+
}

0 commit comments

Comments
 (0)