summaryrefslogtreecommitdiff
path: root/test/concat2.lm
diff options
context:
space:
mode:
Diffstat (limited to 'test/concat2.lm')
-rw-r--r--test/concat2.lm98
1 files changed, 98 insertions, 0 deletions
diff --git a/test/concat2.lm b/test/concat2.lm
new file mode 100644
index 0000000..781c2f2
--- /dev/null
+++ b/test/concat2.lm
@@ -0,0 +1,98 @@
+##### LM #####
+
+lex
+ literal `type `include
+ token id /[A-Za-z_][A-Za-z_0-9]*/
+ ignore /'#' [^\n]* '\n'/
+ ignore /[ \t\r\n]+/
+end
+
+lex
+ token ifn_part /[a-zA-Z0-9_.\-]+/
+ token ifn_slash /'/'/
+end
+
+def ifn_path_part
+ [ifn_part]
+| [ifn_slash]
+
+def ifn_path
+ [ifn_path_part ifn_path]
+| [ifn_path_part]
+
+
+literal `%%
+
+lex
+ token em_ws /( any - 33..126 )+/
+end
+
+def em_item
+ [em_ws]
+
+def prelude
+ [em_item* `%%]
+
+def item
+ [`include ifn_path]
+| [`type id]
+
+def start
+ [prelude item*]
+
+start parseStart( InputFile: stream )
+{
+ return parse start[ InputFile ]
+}
+
+start parseTxt( T: str )
+{
+ cons a: accum<start>[]
+ send a [T] eos
+ return a.tree
+}
+
+item* concatItems( IL1: item* IL2: item* )
+{
+ for IL: item* in IL1 {
+ if match IL [] {
+ IL = IL2
+ break
+ }
+ }
+ return IL1
+}
+
+item* expandIncludes( ItemList: ref<item*> )
+{
+ for IL: item* in ItemList {
+ if match IL
+ [`include FN: ifn_path Rest: item*]
+ {
+ S: start = parseTxt(
+ "
+ "%%
+ "
+ )
+
+ match S [em_item* `%% IncludedItems: item*]
+
+ IL = concatItems( IncludedItems Rest )
+ }
+ }
+}
+
+int main()
+{
+ S: start = parseStart(stdin)
+ match S [em_item* `%% ItemList: item*]
+ expandIncludes( ItemList )
+}
+
+main()
+##### IN #####
+
+%%
+
+include smtp.vpt
+##### EXP #####