From 2f5c61b3ebc992f600b43de5031b6cf2a5e1f26a Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 19 Sep 2014 01:10:25 +0200 Subject: [PATCH] Small cleanup for the XPath lexer. --- lib/oga/xpath/lexer.rl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/oga/xpath/lexer.rl b/lib/oga/xpath/lexer.rl index 3e30d3c..b2a1019 100644 --- a/lib/oga/xpath/lexer.rl +++ b/lib/oga/xpath/lexer.rl @@ -186,6 +186,8 @@ module Oga rparen = ')' @{ add_token(:T_RPAREN) }; comma = ',' @{ add_token(:T_COMMA) }; colon = ':' @{ add_token(:T_COLON) }; + lbrack = '[' @{ add_token(:T_LBRACK) }; + rbrack = ']' @{ add_token(:T_RBRACK) }; # Identifiers # @@ -337,7 +339,12 @@ module Oga # # See http://www.w3.org/TR/xpath/#NT-NodeType for more information. - type_test = 'comment' | 'text' | 'processing-instruction' | 'node'; + type_test = ( + 'comment' | + 'text' | + 'processing-instruction' | + 'node' + ) '()'; action emit_type_test { emit(:T_TYPE_TEST, ts, te - 2) @@ -358,13 +365,9 @@ module Oga main := |* operator; - whitespace | slash | lparen | rparen | comma | colon; - - type_test '()' => emit_type_test; - - '[' => { add_token(:T_LBRACK) }; - ']' => { add_token(:T_RBRACK) }; + whitespace | slash | lparen | rparen | comma | colon | lbrack | rbrack; + type_test => emit_type_test; var => emit_variable; string => emit_string; integer => emit_integer;