Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 5a01622

Browse files
committed
Merge branch 'v0.1-beta' into 'main'
Interim merge See merge request mech-lang/syntax!24
2 parents 84757e9 + f6b3362 commit 5a01622

File tree

12 files changed

+3112
-1984
lines changed

12 files changed

+3112
-1984
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ nom-unicode = "0.3.0"
3030
unicode-segmentation = "1.9.0"
3131
rlibc = { version = "=1.0", optional = true }
3232
serde = "1.0.144"
33-
serde_derive = "1.0.144"
33+
serde_derive = "1.0.144"
34+
colored = "2"

grammar.awk

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/awk -f
2+
3+
# Generate grammar.md from parser.rs
4+
# Usage: `./grammar.awk < src/parser.rs > grammar.md`
5+
6+
BEGIN {
7+
TITLE = 0
8+
PEG = 1
9+
previous = TITLE
10+
print strftime("# Mech Grammar (%m/%d/%Y %H:%M:%S)", systime())
11+
print
12+
print "| Symbol | Semantics |"
13+
print "|:------:|:----------------------------------------------------|"
14+
print "| \"abc\" | input matches string literal \"abc\" (terminal) |"
15+
print "| p* | input matches `p` for 0 or more times (repetition) |"
16+
print "| p+ | input mathces `p` for 1 or more times (repetition) |"
17+
print "| p? | input mathces `p` for 0 or 1 time (optional) |"
18+
print "| p1, p2 | input matches `p1` followed by `p2` (sequence) |"
19+
print "| p1\\|p2 | input matches `p1` or `p2` (ordered choice) |"
20+
print "| !!p | input matches `p`; never consume input (peek) |"
21+
print "| !p | input doesn't match `p`; never consume input (peek) |"
22+
print "| (...) | common grouping |"
23+
print "| <...> | labeled grouping |"
24+
print
25+
}
26+
27+
# match against PEG
28+
/^\/\/\s*[^ ]+\s*::=/ {
29+
if (previous == TITLE) {
30+
print "```"
31+
}
32+
gsub(/^\/\/\s*/, "")
33+
print
34+
previous = PEG
35+
}
36+
37+
# match against markdown title
38+
/^\/\/\s*#{3,6}[^#]/ {
39+
if (previous == PEG) {
40+
print "```"
41+
}
42+
gsub(/^\/\/\s*#/, "")
43+
print "\n"$0"\n"
44+
previous = TITLE
45+
}
46+
47+
# match against "additional lines"
48+
/^\/\/\s*>>/ {
49+
gsub(/^\/\/\s*/, "")
50+
gsub(/>>/, " ")
51+
print
52+
}
53+
54+
END {
55+
if (previous == PEG) {
56+
print "```"
57+
}
58+
}

0 commit comments

Comments
 (0)