aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/code-overview/out.txt68
-rw-r--r--examples/code-overview/overview.tbsp56
-rw-r--r--examples/md-to-html/convert.tbsp65
-rw-r--r--examples/md-to-html/doc.md21
-rw-r--r--examples/md-to-html/out.html20
-rw-r--r--examples/md-to-html/readme.txt3
-rw-r--r--examples/static-analysis/none_comparisons.tbsp24
-rw-r--r--examples/static-analysis/sample.py3
8 files changed, 260 insertions, 0 deletions
diff --git a/examples/code-overview/out.txt b/examples/code-overview/out.txt
new file mode 100644
index 0000000..78c76b1
--- /dev/null
+++ b/examples/code-overview/out.txt
@@ -0,0 +1,68 @@
1module
2 └╴struct Variable
3 └╴trait Variable
4 └╴fn value
5 └╴fn ty
6 └╴fn assign
7 └╴enum Value
8 └╴trait Value
9 └╴fn ty
10 └╴fn default
11 └╴fn default_int
12 └╴fn default_bool
13 └╴fn default_string
14 └╴fn as_boolean
15 └╴fn add
16 └╴fn sub
17 └╴fn mul
18 └╴fn div
19 └╴fn mod_
20 └╴fn equals
21 └╴fn greater_than
22 └╴fn less_than
23 └╴fn greater_than_equals
24 └╴fn less_than_equals
25 └╴fn not
26 └╴fn and
27 └╴fn or
28 └╴trait Value
29 └╴fn fmt
30 └╴struct Visitor
31 └╴struct Visitors
32 └╴trait Visitors
33 └╴fn default
34 └╴trait Visitors
35 └╴fn new
36 └╴fn insert
37 └╴fn get_by_node
38 └╴enum Error
39 └╴struct Context
40 └╴trait Context<'a>
41 └╴fn fmt
42 └╴trait Context<'a>
43 └╴fn new
44 └╴fn with_program
45 └╴fn with_input
46 └╴fn with_cursor
47 └╴fn eval_expr
48 └╴fn eval_lit
49 └╴fn lookup
50 └╴fn lookup_mut
51 └╴fn bind
52 └╴fn eval_bin
53 └╴fn eval_assign
54 └╴fn eval_arith
55 └╴fn eval_cmp
56 └╴fn eval_logic
57 └╴fn eval_unary
58 └╴fn eval_if
59 └╴fn eval_call
60 └╴fn eval_declaration
61 └╴fn eval_statement
62 └╴fn eval_block
63 └╴fn eval
64 └╴fn evaluate
65 └╴mod test
66 └╴fn bin
67 └╴fn test_evaluate_blocks
68 └╴fn test_evaluate_if
diff --git a/examples/code-overview/overview.tbsp b/examples/code-overview/overview.tbsp
new file mode 100644
index 0000000..dd56c55
--- /dev/null
+++ b/examples/code-overview/overview.tbsp
@@ -0,0 +1,56 @@
1BEGIN {
2 int indent = 1;
3 string tab = " ";
4 string tree = "└╴";
5 print("module\n");
6}
7
8enter declaration_list {
9 indent += 1;
10}
11leave declaration_list {
12 indent -= 1;
13}
14
15enter block {
16 indent += 1;
17}
18leave block {
19 indent -= 1;
20}
21
22enter function_item {
23 print(tab * indent);
24 print(tree);
25 print("fn " + text(node.name) + "\n");
26}
27
28enter function_signature_item {
29 print(tab * indent);
30 print(tree);
31 print("fn " + text(node.name) + "\n");
32}
33
34enter struct_item {
35 print(tab * indent);
36 print(tree);
37 print("struct " + text(node.name) + "\n");
38}
39
40enter enum_item {
41 print(tab * indent);
42 print(tree);
43 print("enum " + text(node.name) + "\n");
44}
45
46enter mod_item {
47 print(tab * indent);
48 print(tree);
49 print("mod " + text(node.name) + "\n");
50}
51
52enter impl_item {
53 print(tab * indent);
54 print(tree);
55 print("trait " + text(node.type) + "\n");
56}
diff --git a/examples/md-to-html/convert.tbsp b/examples/md-to-html/convert.tbsp
new file mode 100644
index 0000000..103bcaa
--- /dev/null
+++ b/examples/md-to-html/convert.tbsp
@@ -0,0 +1,65 @@
1BEGIN {
2 int depth = 0;
3
4 print("<html>\n");
5 print("<body>\n");
6}
7
8enter section {
9 depth += 1;
10}
11leave section {
12 depth -= 1;
13}
14
15enter atx_heading {
16 print("<h");
17 print(depth);
18 print(">");
19}
20leave atx_heading {
21 print("</h");
22 print(depth);
23 print(">\n");
24}
25
26enter paragraph {
27 print("<p>");
28}
29leave paragraph {
30 print("</p>\n");
31}
32
33enter list {
34 print("<ol>");
35}
36leave list {
37 print("</ol>\n");
38}
39
40enter list_item {
41 print("<li>");
42}
43leave list_item {
44 print("</li>\n");
45}
46
47enter fenced_code_block {
48 print("<pre>");
49}
50leave fenced_code_block {
51 print("</pre>\n");
52}
53
54enter inline {
55 print(text(node));
56}
57enter code_fence_content {
58 print(text(node));
59}
60
61END {
62 print("</body>\n");
63 print("</html>\n");
64}
65
diff --git a/examples/md-to-html/doc.md b/examples/md-to-html/doc.md
new file mode 100644
index 0000000..2a38bb0
--- /dev/null
+++ b/examples/md-to-html/doc.md
@@ -0,0 +1,21 @@
1# 1 heading
2
3content of first paragraph
4
5## 1.1 heading
6
7content of nested paragraph
8
9# 2 heading
10
11content of second paragraph
12
13```
14// some code in the code block
15fn main() { }
16```
17
18- who dosent
19- despise
20- lists
21
diff --git a/examples/md-to-html/out.html b/examples/md-to-html/out.html
new file mode 100644
index 0000000..9b03976
--- /dev/null
+++ b/examples/md-to-html/out.html
@@ -0,0 +1,20 @@
1<html>
2<body>
3<h1>1 heading</h1>
4<p>content of first paragraph</p>
5<h2>1.1 heading</h2>
6<p>content of nested paragraph</p>
7<h1>2 heading</h1>
8<p>content of second paragraph</p>
9<pre>// some code in the code block
10fn main() { }
11</pre>
12<ol><li><p>who dosent</p>
13</li>
14<li><p>despise</p>
15</li>
16<li><p>lists</p>
17</li>
18</ol>
19</body>
20</html>
diff --git a/examples/md-to-html/readme.txt b/examples/md-to-html/readme.txt
new file mode 100644
index 0000000..812c1e6
--- /dev/null
+++ b/examples/md-to-html/readme.txt
@@ -0,0 +1,3 @@
1proof-of-concept markdown-to-html converter using tbsp:
2
3 tbsp -f convert.tbsp -l md < doc.md > out.html
diff --git a/examples/static-analysis/none_comparisons.tbsp b/examples/static-analysis/none_comparisons.tbsp
new file mode 100644
index 0000000..2d65426
--- /dev/null
+++ b/examples/static-analysis/none_comparisons.tbsp
@@ -0,0 +1,24 @@
1BEGIN {
2 bool in_equal_compare = false;
3 string comparison_text = "";
4}
5
6enter comparison_operator {
7 if (text(node.operators) == "==") {
8 in_equal_compare = true;
9 comparison_text = text(node);
10 };
11}
12
13leave comparison_operator {
14 in_equal_compare = false;
15}
16
17enter none {
18 if (in_equal_compare) {
19 print("using `==` to compare with None, use `is None` instead:\n\t");
20 print(comparison_text);
21 print("\n");
22 } else {
23 };
24}
diff --git a/examples/static-analysis/sample.py b/examples/static-analysis/sample.py
new file mode 100644
index 0000000..7c3ed09
--- /dev/null
+++ b/examples/static-analysis/sample.py
@@ -0,0 +1,3 @@
1def foo():
2 if bar == None:
3 print("none")