From 0750d642624b2262afdb4dd17b275a16e96971b5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 20 Sep 2017 05:02:53 -0700 Subject: Updated all the code to work with the latest nomsu. --- examples/parser_tests.nom | 63 ++++++++++++----------------------------------- examples/sample_code.nom | 33 +++++++++---------------- examples/tutorial.nom | 29 ++++++---------------- 3 files changed, 36 insertions(+), 89 deletions(-) (limited to 'examples') diff --git a/examples/parser_tests.nom b/examples/parser_tests.nom index 5cf64d3..b1eb23b 100644 --- a/examples/parser_tests.nom +++ b/examples/parser_tests.nom @@ -1,48 +1,38 @@ require "lib/core.nom" -test: say "foo" ..yields ".." +test: say "foo" +..yields ".." |Call [say %]: | "foo" -test: say (4) ..yields ".." +test: say (foo) +..yields ".." |Call [say %]: - | 4 + | Call [foo]! test: - rule: fart ..=: say "poot" + rule [fart] =: say "poot" ..yields ".." |Call [rule % = %]: - | Thunk: + | List: | Call [fart]! | Thunk: | Call [say %]: | "poot" -test: - rule: doublefart ..=: - say "poot" - say "poot" +test: say (subexpressions work) ..yields ".." - |Call [rule % = %]: - | Thunk: - | Call [doublefart]! - | Thunk: - | Call [say %]: - | "poot" - | Call [say %]: - | "poot" - -test: say (subexpressions work) ..yields ".." |Call [say %]: | Call [subexpressions work]! -test: say ["lists", "work"] ..yields ".." +test: say ["lists", "work"] +..yields ".." |Call [say %]: | List: | "lists" | "work" -test: say [] ..yields ".." +test (: say []) yields ".." |Call [say %]: | @@ -71,28 +61,6 @@ test: | 3 | 4 -test: - say both.. - "hello" - and "world" -..yields ".." - |Call [say both % and %]: - | "hello" - | "world" - -test: - say both .. - "a list:" - and [..] - 1,2,(three),(4) -..yields ".." - |Call [say both % and %]: - | "a list:" - | List: - | 1 - | 2 - | Call [three]! - | 4 test: if 1: yes @@ -106,7 +74,7 @@ test: | Call [no]! test: - if 1: yes ..else: no + if 1 (: yes) else: no ..yields ".." |Call [if % % else %]: | 1 @@ -173,10 +141,11 @@ test: say (1 + (-(2 * 3))) test: if %x: x - ..else: if %y: - y ..else: - z + if %y: + y + ..else: + z ..yields ".." |Call [if % % else %]: | Var[x] diff --git a/examples/sample_code.nom b/examples/sample_code.nom index f8315a8..e2b3a62 100644 --- a/examples/sample_code.nom +++ b/examples/sample_code.nom @@ -97,40 +97,31 @@ say (..) 3 * 4 when: - when %x == 1: + ? %x == 1: say "one" - when %x == 2: + ? %x == 2: say "two" - when %x: + ? %x: say "nonzero" - else: + ?: say "???" -when: - * %x == 1: +when %x: + == 1: say "one" - * %x == 2: + == 2: say "two" - * %x: - say "nonzero" - *: - say "???" - -when %x ==: - * 1: - say "one" - * 2: - say "two" - *: + ==: say "???" if %x: say "one" -..else: if %y: - say "two" ..else: - say "three" + if %y: + say "two" + ..else: + say "three" say ".." diff --git a/examples/tutorial.nom b/examples/tutorial.nom index 55e558b..306a0af 100644 --- a/examples/tutorial.nom +++ b/examples/tutorial.nom @@ -3,7 +3,7 @@ continue until dedent # Import files like so: -require "core.nom" +require "lib/core.nom" # Numbers: 23 @@ -114,8 +114,8 @@ do: # Function definition: rule [say both %first and also %second] =: - # Function arguments are accessed just like variables say %first + # Function arguments are accessed just like variables say %second # The last line of a function is the return value @@ -192,29 +192,16 @@ say (2 ++ 3) "say both %first and also %second", and a code block to a function called "rule % %" that takes two arguments. -# Line continuations work by either ending a line with ".." and continuing with an indented block: -say.. - both "Tom" and - also - "Sawyer" - -# Or by starting the next line with ".." +# Line continuations work by starting the next line with ".." say both "Bruce" ..and also "Lee" -# This can be mixed and matched: -say both.. - "Rick" -..and also.. - "Moranis" - -# And combined with the block forms of literals: +# This can be combined with the block forms of literals: say both ".." |Four score and seven years ago our fathers brought forth, upon this continent, |a new nation, conceived in liberty, and dedicated to the proposition that |"all men are created equal" -..and also.. - "-- Abraham Lincoln" +..and also "-- Abraham Lincoln" rule [my favorite number] =: 21 + 2 @@ -223,7 +210,7 @@ say (my favorite number) # There's a multi-line indented block form for subexpressions too: say (..) my favorite - number + ..number # Block strings can interpolate values by enclosing an expression in a pair of \s say ".."|My favorite number is \my favorite number\! @@ -231,7 +218,7 @@ say ".."|My favorite number is \my favorite number\! say ".." |My favorite number is still \(..) my favorite - number + ..number ..\, but this time it uses an indented subexpression! rule [sing %starting-bottles bottles of beer] =: @@ -278,7 +265,7 @@ say ".."|The square root of 2 is \square root of 2\ # "macro block %" is for defining macros that produce blocks of code, not values macro block [unless %condition %body] =: ".." |if not (\%condition as lua expr\) then - | \(lua expr "vars.body.value.value") as lua block\ + | \(lua expr "vars.body.value") as lua block\ |end unless (1 > 10): -- cgit v1.2.3