File Coverage

blib/lib/MarpaX/Database/Terminfo/Grammar/Regexp.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1 18     18   63 use strict;
  18         19  
  18         434  
2 18     18   53 use warnings FATAL => 'all';
  18         22  
  18         572  
3              
4             package MarpaX::Database::Terminfo::Grammar::Regexp;
5 18     18   6302 use MarpaX::Database::Terminfo::Grammar::CharacterClasses;
  18         26  
  18         386  
6 18     18   71 use Exporter 'import';
  18         18  
  18         9847  
7              
8             our @EXPORT_OK = qw/@TOKENSRE %TOKENSRE/;
9              
10             # ABSTRACT: Terminfo grammar regexps
11              
12             our $VERSION = '0.012'; # VERSION
13              
14              
15             #
16             # List of escaped characters allowed in terminfo source files
17             # ^x : Control-x (for any appropriate x)
18             # any appropriate x here is all the ASCII Control Characters (C0 set + DEL, even if it is outdated)
19             # \x where x can be a b E e f l n r s t ^ \ , : 0 [0-7]{3}
20             #
21             our $C0 = qr/[\@A-Z\[\\\]\^_ \?]/;
22             our $CONTROLX = qr/(?\^\^)*\^$C0/; # Takes care of ^^
23             our $ALLOWED_BACKSLASHED_CHARACTERS = qr/(?:a|b|E|e|f|l|n|r|s|t|\^|\\|,|:|0|[0-7]{3})/;
24             our $BACKSLASHX = qr/(?\\\\)*\\$ALLOWED_BACKSLASHED_CHARACTERS/; # Takes care of \\
25             our $ESCAPED = qr/(?:$CONTROLX|$BACKSLASHX)/;
26             our $I_CONSTANT = qr/(?:(0[xX][a-fA-F0-9]+(?:[uU](?:ll|LL|[lL])?|(?:ll|LL|[lL])[uU]?)?) # Hexadecimal
27             |([1-9][0-9]*(?:[uU](?:ll|LL|[lL])?|(?:ll|LL|[lL])[uU]?)?) # Decimal
28             |(0[0-7]*(?:[uU](?:ll|LL|[lL])?|(?:ll|LL|[lL])[uU]?)?) # Octal
29             |([uUL]?'(?:[^'\\\n]|\\(?:[\'\"\?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F0-9]+))+') # Character
30             )/x;
31              
32 18     18   1067 our %TOKENSRE = (
  18         33  
  18         203  
33             'ALIASINCOLUMNONE' => qr/\G^((?:$ESCAPED|\p{MarpaX::Database::Terminfo::Grammar::CharacterClasses::InAlias})+)/ms,
34             'PIPE' => qr/\G(\|)/,
35             'LONGNAME' => qr/\G((?:$ESCAPED|\p{MarpaX::Database::Terminfo::Grammar::CharacterClasses::InNcursesLongname})+), ?/,
36             'ALIAS' => qr/\G((?:$ESCAPED|\p{MarpaX::Database::Terminfo::Grammar::CharacterClasses::InAlias})+)/,
37             'NUMERIC' => qr/\G(((?:$ESCAPED|\p{MarpaX::Database::Terminfo::Grammar::CharacterClasses::InName})+)#($I_CONSTANT))/,
38             'STRING' => qr/\G(((?:$ESCAPED|\p{MarpaX::Database::Terminfo::Grammar::CharacterClasses::InName})+)=((?:$ESCAPED|\p{MarpaX::Database::Terminfo::Grammar::CharacterClasses::InIsPrintExceptComma})*))/,
39             'BOOLEAN' => qr/\G((?:$ESCAPED|\p{MarpaX::Database::Terminfo::Grammar::CharacterClasses::InName})+)/,
40             'COMMA' => qr/\G(, ?)/,
41             'NEWLINE' => qr/\G(\n)/,
42             'WS_many' => qr/\G( +)/,
43             'BLANKLINE' => qr/\G^([ \t]*\n)/ms,
44             'COMMENT' => qr/\G^([ \t]*#[^\n]*\n)/ms,
45             );
46              
47             #
48             # It is important to have LONGNAME before ALIAS because LONGNAME will do a lookahead on COMMA
49             # It is important to have NUMERIC and STRING before BOOLEAN because BOOLEAN is a subset of them
50             # It is important to have BLANKLINE and COMMENT at the end: they are 'discarded' by the grammar
51             # In these regexps we add the embedded comma: \, (i.e. these are TWO characters)
52             #
53              
54             our @TOKENSRE = (
55             [ 'ALIASINCOLUMNONE' , $TOKENSRE{ALIASINCOLUMNONE} ],
56             [ 'PIPE' , $TOKENSRE{PIPE} ],
57             [ 'LONGNAME' , $TOKENSRE{LONGNAME} ],
58             [ 'ALIAS' , $TOKENSRE{ALIAS} ],
59             [ 'NUMERIC' , $TOKENSRE{NUMERIC} ],
60             [ 'STRING' , $TOKENSRE{STRING} ],
61             [ 'BOOLEAN' , $TOKENSRE{BOOLEAN} ],
62             [ 'COMMA' , $TOKENSRE{COMMA} ],
63             [ 'NEWLINE' , $TOKENSRE{NEWLINE} ],
64             [ 'WS_many' , $TOKENSRE{WS_many} ],
65             [ 'BLANKLINE' , $TOKENSRE{BLANKLINE} ],
66             [ 'COMMENT' , $TOKENSRE{COMMENT} ],
67             );
68              
69             1;
70              
71             __END__