summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2019-12-29 16:25:24 +0200
committerAdrian Thurston <thurston@colm.net>2019-12-29 16:27:39 +0200
commitd9716ed74693b64ccbff1bf6de25aed38715acc3 (patch)
tree184da9692b585871bdf045718ba0476276405ac9
parent42e180759b47e71df1c292894b360db88a5b0b66 (diff)
downloadcolm-d9716ed74693b64ccbff1bf6de25aed38715acc3.tar.gz
colm: updated hello_world and assign examples
Removed the string concatenation from hello world examples (even though we want to bring it back eventually). Updated assign example so it does not use named lexical regions. Also removed the overlap between id and number, which resulted in the id form of number never matching. Added some error handling. refs #94
-rw-r--r--doc/colm/0_04_hello_world.adoc3
-rw-r--r--doc/colm/code/assign.lm23
-rw-r--r--doc/colm/code/hello_world.lm2
3 files changed, 17 insertions, 11 deletions
diff --git a/doc/colm/0_04_hello_world.adoc b/doc/colm/0_04_hello_world.adoc
index 0406a159..8cbfab53 100644
--- a/doc/colm/0_04_hello_world.adoc
+++ b/doc/colm/0_04_hello_world.adoc
@@ -57,11 +57,10 @@ TIP: It turns out that print is also a function that can have multiple arguments
[source,chapel]
.hello_world_ext.lm
----
-print( 'hello ', "world" "\r\n" )
+print( 'hello ', "world\r\n" )
----
We also notice that:
* the quotes can be single and double
-* there is no need for a concat operator
* the whitespace is not significant
* the newlines '\n' appear to be '\r\n'
diff --git a/doc/colm/code/assign.lm b/doc/colm/code/assign.lm
index d8b40d76..6add7cce 100644
--- a/doc/colm/code/assign.lm
+++ b/doc/colm/code/assign.lm
@@ -1,13 +1,15 @@
-lex start
+lex
token id / ('a' .. 'z' | 'A' .. 'Z' ) + /
- token value / ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )+ /
+ token number / ( '0' .. '9' )+ /
literal `= `;
- ignore / [ \t\n] /
+ ignore / [ \t\n]+ /
end
-def assignment
- [ id `= value `;]
+def value
+ [id] | [number]
+def assignment
+ [id `= value `;]
def assignment_list
[assignment assignment_list]
@@ -16,7 +18,12 @@ def assignment_list
parse Simple: assignment_list[ stdin ]
-for I:assignment in Simple {
- print( I.id, "->", I.value, "\n" )
+if ( ! Simple ) {
+ print( "[error]\n" )
+ exit( 1 )
+}
+else {
+ for I:assignment in Simple {
+ print( $I.id, "->", $I.value, "\n" )
+ }
}
-
diff --git a/doc/colm/code/hello_world.lm b/doc/colm/code/hello_world.lm
index 5522c5e1..a739e52d 100644
--- a/doc/colm/code/hello_world.lm
+++ b/doc/colm/code/hello_world.lm
@@ -1 +1 @@
-print "hello world" "\n"
+print "hello world\n"