Support for parsing CSS operators.
This commit is contained in:
1 parent
e03cd42735
commit
8fef62fca0
5 files changed
+153
-2
No files matched your search
+19
-1
@@ -147,7 +147,7 @@ module Oga
|
||||
# Identifiers are used for element and attribute names. Identifiers have
|
||||
# to start with a letter.
|
||||
|
||||
identifier = [a-zA-Z*]+ [a-zA-Z\-_0-9]*;
|
||||
identifier = '*' | [a-zA-Z]+ [a-zA-Z\-_0-9]*;
|
||||
|
||||
action emit_identifier {
|
||||
emit(:T_IDENT, ts, te)
|
||||
@@ -184,6 +184,23 @@ module Oga
|
||||
add_token(:T_INT, value)
|
||||
}
|
||||
|
||||
# Strings
|
||||
#
|
||||
# Strings can be single or double quoted. They are mainly used for
|
||||
# attribute values.
|
||||
#
|
||||
dquote = '"';
|
||||
squote = "'";
|
||||
|
||||
string_dquote = (dquote ^dquote* dquote);
|
||||
string_squote = (squote ^squote* squote);
|
||||
|
||||
string = string_dquote | string_squote;
|
||||
|
||||
action emit_string {
|
||||
emit(:T_STRING, ts + 1, te - 1)
|
||||
}
|
||||
|
||||
# Nth numbers
|
||||
#
|
||||
# These numbers are in the form of 2n+1 and are used for
|
||||
@@ -236,6 +253,7 @@ module Oga
|
||||
nth_integer => emit_nth_integer;
|
||||
nth_identifier => emit_nth_identifier;
|
||||
integer => emit_integer;
|
||||
string => emit_string;
|
||||
|
||||
any;
|
||||
*|;
|
||||
|
||||
+34
-1
@@ -14,6 +14,7 @@ rule
|
||||
expression
|
||||
: path
|
||||
| node_test
|
||||
| node_operators
|
||||
;
|
||||
|
||||
path_member
|
||||
@@ -46,7 +47,39 @@ rule
|
||||
;
|
||||
|
||||
predicate
|
||||
: T_LBRACK expression T_RBRACK { val[1] }
|
||||
: T_LBRACK predicate_members T_RBRACK { val[1] }
|
||||
;
|
||||
|
||||
predicate_members
|
||||
: expression { val[0] }
|
||||
| operator { val[0] }
|
||||
;
|
||||
|
||||
operator
|
||||
: op_members T_EQ op_members { s(:eq, val[0], val[2]) }
|
||||
| op_members T_SPACE_IN op_members { s(:space_in, val[0], val[2]) }
|
||||
| op_members T_STARTS_WITH op_members { s(:starts_with, val[0], val[2]) }
|
||||
| op_members T_ENDS_WITH op_members { s(:ends_with, val[0], val[2]) }
|
||||
| op_members T_IN op_members { s(:in, val[0], val[2]) }
|
||||
| op_members T_HYPHEN_IN op_members { s(:hyphen_in, val[0],val[2]) }
|
||||
;
|
||||
|
||||
node_operators
|
||||
: node_test T_CHILD node_test { s(:child, val[0], val[2]) }
|
||||
| node_test T_FOLLOWING node_test { s(:following, val[0], val[2]) }
|
||||
| node_test T_FOLLOWING_DIRECT node_test
|
||||
{
|
||||
s(:following_direct, val[0], val[2])
|
||||
}
|
||||
;
|
||||
|
||||
op_members
|
||||
: node_test
|
||||
| string
|
||||
;
|
||||
|
||||
string
|
||||
: T_STRING { s(:string, val[0]) }
|
||||
;
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user