summaryrefslogtreecommitdiff
path: root/test/generate2.lm
diff options
context:
space:
mode:
Diffstat (limited to 'test/generate2.lm')
-rw-r--r--test/generate2.lm214
1 files changed, 214 insertions, 0 deletions
diff --git a/test/generate2.lm b/test/generate2.lm
new file mode 100644
index 0000000..946c478
--- /dev/null
+++ b/test/generate2.lm
@@ -0,0 +1,214 @@
+##### LM #####
+context generate
+ def open_item
+ type: str
+ num: int
+ []
+
+ OpenStack: list<open_item>
+
+ lex
+ token stray_close //
+
+ token ocurly /'{'+/
+ {
+ input.pull( match_length )
+
+ cons OI: open_item( '{' match_length ) []
+ OpenStack.push( OI )
+ i: int = 0
+ while ( i < match_length ) {
+ input.push( make_token( typeid<ocurly> '{' ) )
+ i = i + 1
+ }
+ }
+
+ token ccurly1 //
+ token ccurly2 //
+ token ccurly3 //
+ token missing_curly //
+
+ token tmp1 /'}'+/
+ {
+ if OpenStack.length > 0 && OpenStack.tail.type == '{' {
+ length: int = 3
+ if ( length > match_length )
+ length = match_length
+
+ Tail: open_item = OpenStack.pop()
+ if ( length > Tail.num )
+ length = Tail.num
+
+ if ( length == 1 )
+ input.push( make_token( typeid<ccurly1> input.pull( 1 ) ) )
+ else if ( length == 2 )
+ input.push( make_token( typeid<ccurly2> input.pull( 2 ) ) )
+ else if ( length == 3 )
+ input.push( make_token( typeid<ccurly3> input.pull( 3 ) ) )
+
+ Tail.num = Tail.num - length
+
+ if ( Tail.num > 0 )
+ OpenStack.push( Tail )
+ }
+ else {
+ input.push( make_token( typeid<stray_close> input.pull( match_length ) ) )
+ }
+ }
+
+ token osquare /'['+/
+ {
+ input.pull( match_length )
+ OI: open_item = construct open_item( '[' match_length ) []
+ OpenStack.push( OI )
+ i: int = 0
+ while ( i < match_length ) {
+ input.push( make_token( typeid<osquare> '[' ) )
+ i = i + 1
+ }
+ }
+
+ token csquare1 //
+ token csquare2 //
+ token missing_square //
+
+ token tmp2 /']'+/
+ {
+ if OpenStack.length > 0 && OpenStack.tail.type == '[' {
+ length: int = 2
+ if ( length > match_length )
+ length = match_length
+
+ Tail: open_item = OpenStack.pop()
+ if ( length > Tail.num )
+ length = Tail.num
+
+ if ( length == 1 )
+ input.push( make_token( typeid<csquare1> input.pull( 1 ) ) )
+ else if ( length == 2 )
+ input.push( make_token( typeid<csquare2> input.pull( 2 ) ) )
+
+ Tail.num = Tail.num - length
+
+ if ( Tail.num > 0 )
+ OpenStack.push( Tail )
+ }
+ else {
+ input.push( make_token( typeid<stray_close> input.pull( match_length ) ) )
+ }
+ }
+
+ literal `|
+ token char /any/
+
+ preeof {
+ while ( OpenStack.length > 0 ) {
+ Tail: open_item = OpenStack.pop()
+ i: int
+ if ( Tail.type == '{' ) {
+ i = 0
+ while ( i < Tail.num ) {
+ input.push( make_token( typeid<missing_curly> '}' ) )
+ i = i + 1
+ }
+ }
+ else if ( Tail.type == '[' ) {
+ i = 0
+ while ( i < Tail.num ) {
+ input.push( make_token( typeid<missing_square> ']' ) )
+ i = i + 1
+ }
+ }
+ }
+ }
+ end
+
+ #
+ # Internal Links
+ #
+
+
+ lex
+ literal `http:
+ literal `ftp:
+ literal `mailto:
+ end
+
+ def el_prefix
+ [`http:]
+ | [`ftp:]
+ | [`mailto:]
+
+ def external_link
+ [osquare item* csquare1]
+
+ def internal_link
+ [osquare osquare item* csquare2]
+
+ def unclosed_square
+ [osquare item* missing_square]
+
+ #
+ # Templates
+ #
+
+ def sing_template
+ [ocurly item* ccurly1]
+
+ def template
+ [ocurly ocurly item* ccurly2]
+
+ def parameter
+ [ocurly ocurly ocurly item* ccurly3]
+
+ def unclosed_curly
+ [ocurly item* missing_curly]
+
+ #
+ # Template Parameters
+ #
+
+
+ def U1 []
+ def U2 []
+ def U3 []
+
+ def item
+ [external_link]
+ | [internal_link]
+ | [unclosed_curly]
+ | [sing_template]
+ | [template]
+ | [parameter]
+ | [unclosed_curly]
+ | [stray_close]
+ | [osquare]
+ | [`|]
+ | [char]
+
+ def start
+ [item*]
+
+end # generate
+
+cons Generate: generate[]
+
+Generate.OpenStack = construct list<generate::open_item> []
+Sentinal: generate::open_item = construct generate::open_item( '** SENTINAL **' 1 ) []
+Generate.OpenStack.push( Sentinal )
+
+parse S: generate::start(Generate)[stdin]
+
+if S {
+ for I: generate::external_link in S
+ print( 'EXTERNAL LINK: ' I '\n' )
+
+ for I: generate::internal_link in S
+ print( 'INTERNAL LINK: ' I '\n' )
+}
+##### IN #####
+[external]
+[[internal]]
+##### EXP #####
+EXTERNAL LINK: [external]
+INTERNAL LINK: [[internal]]