In: |
rexml/parsers/xpathparser.rb
|
Parent: | Object |
You don’t want to use this class. Really. Use XPath, which is a wrapper for this class. Believe me. You don’t want to poke around in here. There is strange, dark magic at work in this code. Beware. Go back! Go back while you still can!
LITERAL | = | /^'([^']*)'|^"([^"]*)"/u |
AXIS | = | /^(ancestor|ancestor-or-self|attribute|child|descendant|descendant-or-self|following|following-sibling|namespace|parent|preceding|preceding-sibling|self)::/ |
RelativeLocationPath
| Step | (AXIS_NAME '::' | '@' | '') AxisSpecifier NodeTest Predicate | '.' | '..' AbbreviatedStep | RelativeLocationPath '/' Step | RelativeLocationPath '//' Step |
||
NCNAMETEST | = | /^(#{NCNAME_STR}):\*/u |
Returns a 1-1 map of the nodeset The contents of the resulting array are either: true/false, if a positive match String, if a name matchNodeTest | ('*' | NCNAME ':' '*' | QNAME) NameTest | NODE_TYPE '(' ')' NodeType | PI '(' LITERAL ')' PI | '[' expr ']' Predicate |
||
QNAME | = | Namespace::NAMESPLIT |
NODE_TYPE | = | /^(comment|text|node)\(\s*\)/m |
PI | = | /^processing-instruction\(/ |
VARIABLE_REFERENCE | = | /^\$(#{NAME_STR})/u |
| VARIABLE_REFERENCE | ’(’ expr ’)’ | LITERAL | NUMBER | FunctionCall | ||
NUMBER | = | /^(\d*\.?\d+)/ |
NT | = | /^comment|text|processing-instruction|node$/ |
# File rexml/parsers/xpathparser.rb, line 14 def namespaces=( namespaces ) Functions::namespace_context = namespaces @namespaces = namespaces end
# File rexml/parsers/xpathparser.rb, line 19 def parse path path.gsub!(/([\(\[])\s+/, '\1') # Strip ignorable spaces path.gsub!( /\s+([\]\)])/, '\1' ) parsed = [] path = LocationPath(path, parsed) parsed end
# File rexml/parsers/xpathparser.rb, line 27 def predicate path parsed = [] Predicate( "[#{path}]", parsed ) parsed end
# File rexml/parsers/xpathparser.rb, line 66 def predicate_to_string( path ) string = "" case path[0] when :and, :or, :mult, :plus, :minus, :neq, :eq, :lt, :gt, :lteq, :gteq, :div, :mod, :neq, :union op = path.shift left = predicate_to_string( path.shift ) right = predicate_to_string( path.shift ) string << " " string << left string << " " string << op.to_s string << " " string << right string << " " when :function path.shift name = path.shift string << name string << "( " string << predicate_to_string( path.shift ) string << " )" when :literal path.shift string << " " string << path.shift.inspect string << " " else string << " " string << to_string( path ) string << " " end return string.squeeze(" ") end
# File rexml/parsers/xpathparser.rb, line 33 def to_string( path ) string = "" while path.size > 0 case path[0] when :ancestor, :ancestor_or_self, :attribute, :child, :descendant, :descendant_or_self, :following, :following_sibling, :namespace, :parent, :preceding, :preceding_sibling, :self op = path.shift string << "/" unless string.size == 0 string << op.to_s string << "::" when :any path.shift string << "*" when :qname path.shift prefix = path.shift name = path.shift string << prefix+":" if prefix.size > 0 string << name when :predicate path.shift string << '[' string << predicate_to_string( path.shift ) string << ' ]' else string << "/" unless string.size == 0 string << "UNKNOWN(" string << path.shift.inspect string << ")" end end return string end