Lex wildcards as T_IDENT instead of T_STAR.

This commit is contained in:
Yorick Peterse 2014-06-20 20:37:34 +02:00
parent 45db337c76
commit 514c342cab
5 changed files with 23 additions and 7 deletions

View File

@ -145,14 +145,13 @@ module Oga
rparen = ')' @{ add_token(:T_RPAREN) };
comma = ',' @{ add_token(:T_COMMA) };
colon = ':' @{ add_token(:T_COLON) };
star = '*' @{ add_token(:T_STAR) };
# Identifiers
#
# Identifiers are used for element names, namespaces, attribute names,
# etc. 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)
@ -281,7 +280,7 @@ module Oga
main := |*
operator;
whitespace | slash | lparen | rparen | comma | colon | star;
whitespace | slash | lparen | rparen | comma | colon;
'[' => { add_token(:T_LBRACK) };
']' => { add_token(:T_RBRACK) };

View File

@ -3,7 +3,7 @@
#
class Oga::XPath::Parser
token T_AXIS T_COLON T_COMMA T_FLOAT T_INT T_IDENT T_STAR
token T_AXIS T_COLON T_COMMA T_FLOAT T_INT T_IDENT
token T_LBRACK T_RBRACK T_LPAREN T_RPAREN T_SLASH T_STRING
token T_PIPE T_AND T_OR T_ADD T_DIV T_MOD T_EQ T_NEQ T_LT T_GT T_LTE T_GTE

View File

@ -16,13 +16,13 @@ describe Oga::XPath::Lexer do
end
example 'lex a whildcard node test' do
lex_xpath('/*').should == [[:T_SLASH, nil], [:T_STAR, nil]]
lex_xpath('/*').should == [[:T_SLASH, nil], [:T_IDENT, '*']]
end
example 'lex a wildcard node test for a namespace' do
lex_xpath('/*:foo').should == [
[:T_SLASH, nil],
[:T_STAR, nil],
[:T_IDENT, '*'],
[:T_COLON, nil],
[:T_IDENT, 'foo']
]

View File

@ -108,7 +108,7 @@ describe Oga::XPath::Lexer do
[:T_SLASH, nil],
[:T_IDENT, 'foo'],
[:T_SLASH, nil],
[:T_STAR, nil],
[:T_IDENT, '*'],
[:T_RBRACK, nil]
]
end

View File

@ -0,0 +1,17 @@
require 'spec_helper'
describe Oga::XPath::Parser do
context 'wildcards' do
example 'parse a wildcard name test' do
parse_xpath('*').should == s(:path, s(:test, nil, '*'))
end
example 'parse a wildcard namespace test' do
parse_xpath('*:A').should == s(:path, s(:test, '*', 'A'))
end
example 'parse a wildcard namespace and name test' do
parse_xpath('*:*').should == s(:path, s(:test, '*', '*'))
end
end
end