line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################################################### |
2
|
|
|
|
|
|
|
# Copyright 2013/2014 by Marcel Greter |
3
|
|
|
|
|
|
|
# This file is part of OCBNET-CSS3 (GPL3) |
4
|
|
|
|
|
|
|
#################################################################################################### |
5
|
|
|
|
|
|
|
# regular expressions to match css2/css3 selectors |
6
|
|
|
|
|
|
|
#################################################################################################### |
7
|
|
|
|
|
|
|
package OCBNET::CSS3::Regex::Stylesheet; |
8
|
|
|
|
|
|
|
#################################################################################################### |
9
|
|
|
|
|
|
|
our $VERSION = '0.2.5'; |
10
|
|
|
|
|
|
|
#################################################################################################### |
11
|
|
|
|
|
|
|
|
12
|
11
|
|
|
11
|
|
58
|
use strict; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
390
|
|
13
|
11
|
|
|
11
|
|
50
|
use warnings; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
398
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#################################################################################################### |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# load exporter and inherit from it |
18
|
11
|
|
|
11
|
|
52
|
BEGIN { use Exporter qw(); our @ISA = qw(Exporter); } |
|
11
|
|
|
11
|
|
19
|
|
|
11
|
|
|
|
|
273
|
|
|
11
|
|
|
|
|
468
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# define our functions that will be exported |
21
|
11
|
|
|
11
|
|
225
|
BEGIN { our @EXPORT = qw(%opener %closer $re_statement $re_bracket); } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#################################################################################################### |
24
|
|
|
|
|
|
|
|
25
|
11
|
|
|
11
|
|
61
|
use OCBNET::CSS3::Regex::Base; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
1233
|
|
26
|
11
|
|
|
11
|
|
56
|
use OCBNET::CSS3::Regex::Comments; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
4973
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#################################################################################################### |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# openers and closers for certain block type |
31
|
|
|
|
|
|
|
# *************************************************************************************** |
32
|
|
|
|
|
|
|
our %opener = ( '{' => '{', '[' => '[', '(' => '(', '\"' => '\"', '\'' => '\'' ); |
33
|
|
|
|
|
|
|
our %closer = ( '{' => '}', '[' => ']', '(' => ')', '\"' => '\"', '\'' => '\'' ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# declare regex to parse a block |
36
|
|
|
|
|
|
|
# with correct bracket counting |
37
|
|
|
|
|
|
|
# *************************************************************************************** |
38
|
|
|
|
|
|
|
our $re_bracket; $re_bracket = |
39
|
|
|
|
|
|
|
qr/ |
40
|
|
|
|
|
|
|
\{ # match opening bracket |
41
|
|
|
|
|
|
|
(?: # inner block capture group |
42
|
|
|
|
|
|
|
# match comment after text |
43
|
|
|
|
|
|
|
# before has already matched |
44
|
|
|
|
|
|
|
(?:(??{$re_comment})|\/)? |
45
|
|
|
|
|
|
|
# allowed chars |
46
|
|
|
|
|
|
|
[^\\\"\'{}]+ | |
47
|
|
|
|
|
|
|
# escaped char |
48
|
|
|
|
|
|
|
(?: \\ .)+ | |
49
|
|
|
|
|
|
|
# a quoted string |
50
|
|
|
|
|
|
|
\' (??{$re_apo}) \' | |
51
|
|
|
|
|
|
|
\" (??{$re_quot}) \" | |
52
|
|
|
|
|
|
|
# recursive blocks |
53
|
|
|
|
|
|
|
(??{$re_bracket}) |
54
|
|
|
|
|
|
|
)* # can be empty or repeat |
55
|
|
|
|
|
|
|
\} # match closing bracket |
56
|
|
|
|
|
|
|
/xs; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# declare regex to parse a rule |
59
|
|
|
|
|
|
|
# optional brackets (ie. media query) |
60
|
|
|
|
|
|
|
# *************************************************************************************** |
61
|
|
|
|
|
|
|
our $re_statement; $re_statement = |
62
|
|
|
|
|
|
|
qr/ |
63
|
|
|
|
|
|
|
(?: |
64
|
|
|
|
|
|
|
# match single comments, or |
65
|
|
|
|
|
|
|
(\s*(??{$re_comment})\s*) | |
66
|
|
|
|
|
|
|
# .. capture complex text |
67
|
|
|
|
|
|
|
((?: |
68
|
|
|
|
|
|
|
# match comment after text |
69
|
|
|
|
|
|
|
# before has already matched |
70
|
|
|
|
|
|
|
(?:(??{$re_comment})|\/)? |
71
|
|
|
|
|
|
|
# capture any text |
72
|
|
|
|
|
|
|
(?: |
73
|
|
|
|
|
|
|
# allowed chars |
74
|
|
|
|
|
|
|
[^\\\"\'\/{};]+ | |
75
|
|
|
|
|
|
|
# escaped char |
76
|
|
|
|
|
|
|
(?: \\ .)+ | |
77
|
|
|
|
|
|
|
# a quoted string |
78
|
|
|
|
|
|
|
\' (??{$re_apo}) \' | |
79
|
|
|
|
|
|
|
\" (??{$re_quot}) \" | |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
# can repeat |
82
|
|
|
|
|
|
|
)+) |
83
|
|
|
|
|
|
|
# get optional scope |
84
|
|
|
|
|
|
|
((??{$re_bracket})?) |
85
|
|
|
|
|
|
|
) |
86
|
|
|
|
|
|
|
# exit clause |
87
|
|
|
|
|
|
|
( (?:\z|;+)? ) |
88
|
|
|
|
|
|
|
/xs; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#################################################################################################### |
91
|
|
|
|
|
|
|
#################################################################################################### |
92
|
|
|
|
|
|
|
1; |