diff options
author | Adrian Thurston <thurston@complang.org> | 2013-01-27 12:48:45 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-01-27 12:48:45 -0500 |
commit | 73d0bdf8c771116da360cf8cf4b075f4d8431db6 (patch) | |
tree | f5533b447bc2f4e7b345f62d5576ceb79e23c58b | |
parent | 9e1fd9d153df3cca0810f30fce0797b7bce12002 (diff) | |
download | colm-73d0bdf8c771116da360cf8cf4b075f4d8431db6.tar.gz |
test case for nested streams
-rw-r--r-- | test/include1.in | 14 | ||||
-rw-r--r-- | test/include1.lm | 98 | ||||
-rw-r--r-- | test/include1a.in | 2 | ||||
-rw-r--r-- | test/include1b.in | 2 | ||||
-rw-r--r-- | test/include1c.in | 2 |
5 files changed, 118 insertions, 0 deletions
diff --git a/test/include1.in b/test/include1.in new file mode 100644 index 00000000..9c7aa806 --- /dev/null +++ b/test/include1.in @@ -0,0 +1,14 @@ + +hello; + +#include "include1a.in" + +there; + +#include "include1b.in" + +dude; + +#include "include1c.in" + +and dudettes; diff --git a/test/include1.lm b/test/include1.lm new file mode 100644 index 00000000..03a3b046 --- /dev/null +++ b/test/include1.lm @@ -0,0 +1,98 @@ +namespace string + lex + literal '"' + token data /[^"\\]+/ + token escape /'\\' any/ + end + + def string_data + [data] + | [escape] + + def string + ['"' string_data* '"'] + + str unquote( S: string ) + { + match S ['"' DL: string_data* '"'] + for E: escape in DL + E.data = 'x' + return $DL + } + +end string + +namespace hash + + lex + literal 'define', 'include' + literal '#', '\n' ni + + token id /[a-zA-Z_][a-zA-Z_0-9]*/ + token number /[0-9]+/ + + ignore /[ \t]/ + end + + def hash + ['#' 'define' Id: id number '\n'] + | ['#' 'include' Inc: string::string '\n'] + +end hash + +token rest_of_line /[^\n]* '\n'/ + +namespace lang + + lex + ignore /space/ + literal '*', '(', ')', ';' + token id /[a-zA-Z_][a-zA-Z_0-9]*/ + token number /[0-9]+/ + + token hash /'#'/ { + parse_stop H: hash::hash[ input ] + if ( H.tree ) { + if ( H.tree.Inc ) { + FN: str = unquote( H.tree.Inc ) + print( 'opening ' FN '\n' ) + IS: stream = open( FN 'r' ) + if ( ! IS ) { + print( 'ERROR: failed to open ' FN '\n' ) + exit(1) + } + input.push( IS ) + } + } + else { + parse_stop L: rest_of_line[ input ] + if ! L.tree { + print( "ERROR: stuck: " L.error ) + exit(1) + } + print( "ERROR: failed to parse # directive: " L.tree ) + } + } + end + + def item + [id] + | ['(' item* ')'] + + def statement + [item* ';'] + + def start + [statement*] + +end lang + +parse Input: lang::start[ stdin ] + +if ! Input.tree + print( Input.error '\n' ) +else { + #print( Input.tree '\n' ) + S: lang::start = Input.tree + print( Input.tree '\n' ) +} diff --git a/test/include1a.in b/test/include1a.in new file mode 100644 index 00000000..26da0afa --- /dev/null +++ b/test/include1a.in @@ -0,0 +1,2 @@ +a; +b; diff --git a/test/include1b.in b/test/include1b.in new file mode 100644 index 00000000..6c574323 --- /dev/null +++ b/test/include1b.in @@ -0,0 +1,2 @@ +c; +d; diff --git a/test/include1c.in b/test/include1c.in new file mode 100644 index 00000000..5373832d --- /dev/null +++ b/test/include1c.in @@ -0,0 +1,2 @@ +e; +f; |