##### LM ##### context generate def open_item type: str num: int [] OpenStack: list 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 '{' ) ) 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 input.pull( 1 ) ) ) else if ( length == 2 ) input.push( make_token( typeid input.pull( 2 ) ) ) else if ( length == 3 ) input.push( make_token( typeid input.pull( 3 ) ) ) Tail.num = Tail.num - length if ( Tail.num > 0 ) OpenStack.push( Tail ) } else { input.push( make_token( typeid 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 '[' ) ) 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 input.pull( 1 ) ) ) else if ( length == 2 ) input.push( make_token( typeid input.pull( 2 ) ) ) Tail.num = Tail.num - length if ( Tail.num > 0 ) OpenStack.push( Tail ) } else { input.push( make_token( typeid 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 '}' ) ) i = i + 1 } } else if ( Tail.type == '[' ) { i = 0 while ( i < Tail.num ) { input.push( make_token( typeid ']' ) ) 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 [] 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]]