| 12 | | __PACKAGE__->mk_classdata( 'engine' ); |
| 13 | | |
| 14 | | our %bracket = ( |
| 15 | | Quote => [qw( " " )], |
| 16 | | Citation => [qw( >> << )], |
| 17 | | Notes => ['(((',')))'], |
| 18 | | Comparison => [qw( // // )], |
| 19 | | Emphasis => [qw( ** ** )], |
| 20 | | Definition => [qw( ?? ?? )], |
| 21 | | SubScript => [qw( __ __ )], |
| 22 | | SuperScript => [qw( ~~ ~~ )], |
| 23 | | Inserted => [qw( ++ ++ )], |
| 24 | | Deleted => [qw( -- -- )], |
| 25 | | InputText => [qw( [| |] )], |
| 26 | | InputCommand => [qw( [$ $] )], |
| 27 | | Keyboard => [qw( <[ ]> )], |
| 28 | | Sample => [qw( [! !] )], |
| 29 | | Code => [qw( ` ` )], |
| 30 | | Abbreviation => [ '((','))'], |
| 31 | | Acronym => [ '((','))'], |
| 32 | | Ruby => [ '((','))'], |
| 33 | | Variable => [qw( { } )], |
| 34 | | Embedding => [qw( {{ }} )], |
| 35 | | HyperLink => [qw( [[ ]] )], |
| 36 | | ); |
| 37 | | |
| 38 | | our $exclude_re; |
| 39 | | our $text_re; |
| 40 | | |
| 41 | | { |
| 42 | | my @exclude = (); |
| 43 | | for my $def ( values %bracket ) { |
| 44 | | for ( @{ $def } ) { |
| 45 | | $_ = quotemeta( $_ ); |
| 46 | | push @exclude, $_; |
| 47 | | } |
| 48 | | } |
| 49 | | $exclude_re = join q{|}, ( @exclude, quotemeta( '\\' ) ); |
| 50 | | $text_re = qr{(?: (?! $exclude_re ) [^\n] )+}x; |
| 51 | | } |
| 52 | | |
| 53 | | our %variable = ( |
| 54 | | '$' => 'string', |
| 55 | | '#' => 'number', |
| 56 | | '?' => 'boolean', |
| 57 | | ':' => 'reference', |
| 58 | | '*' => 'pointer', |
| 59 | | '&' => 'function', |
| 60 | | '@' => 'array', |
| 61 | | '%' => 'hash', |
| 62 | | '=' => 'structure', |
| 63 | | '+' => 'object', |
| 64 | | '!' => 'class', |
| 65 | | ); |
| 66 | | |
| 67 | | our $variable_re; |
| 68 | | { |
| 69 | | my @symbols = (); |
| 70 | | for my $symbol ( keys %variable ) { |
| 71 | | push @symbols, quotemeta( $symbol ); |
| 72 | | } |
| 73 | | $variable_re = join q{}, @symbols; |
| 74 | | $variable_re = qr{[$variable_re]}; |
| 75 | | } |
| 76 | | |
| 77 | | our $grammer = <<'__GRAMMER__'; |
| | 11 | __PACKAGE__->mk_classdata( $_ ) for qw( engine grammer ); |
| | 12 | |
| | 13 | __PACKAGE__->grammer(<<'__GRAMMER__'); |
| | 19 | use vars qw( |
| | 20 | %bracket %variable |
| | 21 | $exclude_re $text_re $text_re_orig $variable_re |
| | 22 | ); |
| | 23 | |
| | 24 | %bracket = ( |
| | 25 | Quote => [qw( " " )], |
| | 26 | Citation => [qw( >> << )], |
| | 27 | Notes => ['(((',')))'], |
| | 28 | Comparison => [qw( // // )], |
| | 29 | Emphasis => [qw( ** ** )], |
| | 30 | Definition => [qw( ?? ?? )], |
| | 31 | SubScript => [qw( __ __ )], |
| | 32 | SuperScript => [qw( ~~ ~~ )], |
| | 33 | Inserted => [qw( ++ ++ )], |
| | 34 | Deleted => [qw( -- -- )], |
| | 35 | InputText => [qw( [| |] )], |
| | 36 | InputCommand => [qw( [$ $] )], |
| | 37 | Keyboard => [qw( <[ ]> )], |
| | 38 | Sample => [qw( [! !] )], |
| | 39 | Code => [qw( ` ` )], |
| | 40 | Abbreviation => [ '((','))'], |
| | 41 | Acronym => [ '((','))'], |
| | 42 | Ruby => [ '((','))'], |
| | 43 | Variable => [qw( { } )], |
| | 44 | Embedding => [qw( {{ }} )], |
| | 45 | HyperLink => [qw( [[ ]] )], |
| | 46 | ); |
| | 47 | |
| | 48 | { |
| | 49 | my @exclude = (); |
| | 50 | for my $def ( values %bracket ) { |
| | 51 | for ( @{ $def } ) { |
| | 52 | $_ = quotemeta( $_ ); |
| | 53 | push @exclude, $_; |
| | 54 | } |
| | 55 | } |
| | 56 | $exclude_re = join q{|}, ( @exclude, quotemeta( '\\' ) ); |
| | 57 | $text_re = qr{(?: (?! $exclude_re ) [^\n] )+}x; |
| | 58 | $text_re_orig = $text_re; |
| | 59 | } |
| | 60 | |
| | 61 | %variable = ( |
| | 62 | '$' => 'string', |
| | 63 | '#' => 'number', |
| | 64 | '?' => 'boolean', |
| | 65 | ':' => 'reference', |
| | 66 | '*' => 'pointer', |
| | 67 | '&' => 'function', |
| | 68 | '@' => 'array', |
| | 69 | '%' => 'hash', |
| | 70 | '=' => 'structure', |
| | 71 | '+' => 'object', |
| | 72 | '!' => 'class', |
| | 73 | ); |
| | 74 | |
| | 75 | { |
| | 76 | my @symbols = (); |
| | 77 | for my $symbol ( keys %variable ) { |
| | 78 | push @symbols, quotemeta( $symbol ); |
| | 79 | } |
| | 80 | $variable_re = join q{}, @symbols; |
| | 81 | $variable_re = qr{[$variable_re]}; |
| | 82 | } |
| | 83 | |