lib/opulent/tokens.rb in opulent-1.5.5 vs lib/opulent/tokens.rb in opulent-1.6.0
- old
+ new
@@ -1,15 +1,17 @@
# @Opulent
module Opulent
# Opulent KEYWORDS
- KEYWORDS = %i(def yield include if else elsif unless case when each while until doctype)
+ KEYWORDS = %i(
+ def yield include if else elsif unless case when each while until doctype
+ )
# @Tokens
class Tokens
# All tokens available within Opulent
#
- @@tokens = {
+ @tokens = {
# Indentation
indent: /\A\s*/,
# Node
node: /\A\w+(\-\w+)*/,
@@ -18,16 +20,15 @@
# Shorthand attributes
shorthand: /\A[\.\#\&]/,
shorthand_lookahead: /\A[\.\#\&][a-zA-Z\_\(\"]/,
# Leading and trailing whitespace
- leading_whitespace: /\A(\<\-)/,
- leading_trailing_whitespace: /\A(\>)/,
- trailing_whitespace: /\A(\-\>)/,
+ leading_whitespace: /\A(\')/,
+ trailing_whitespace: /\A(\")/,
# Self enclosing node
- self_enclosing: /\A\/(.*)/,
+ self_enclosing: %r{\A\/(.*)},
# Definition
def: /\Adef +/,
# Definition
@@ -84,15 +85,15 @@
curly_bracket: /\A(\{)/,
angular_bracket: /\A(\<)/,
# Receive matching brackets for allowing multiple bracket types for
# element attributes
- :brackets => /\A([\(\[\{])/,
- :'(' => /\A(\))/,
- :'[' => /\A(\])/,
- :'{' => /\A(\})/,
- :'<' => /\A(\>)/,
+ brackets: /\A([\(\[\{])/,
+ '(': /\A(\))/,
+ '[': /\A(\])/,
+ '{': /\A(\})/,
+ '<': /\A(\>)/,
# Terminators
comma: /\A(\s*\,\s*)/,
colon: /\A(\s*\:\s*)/,
semicolon: /\A(\s*\;\s*)/,
@@ -104,31 +105,32 @@
exp_identifier: /\A([a-zA-Z\_][a-zA-Z0-9\_]*[\!\?]?)/,
exp_assignment: /\A(\=)/,
exp_operation: /\A( *(\+|\-|\*\*|\*|\/|\<\<|\>\>|\.\.|\%|\<\=\>|\<\=|\^|\<|\>\=|\>|\=\~|\!\~|\=\=\=|\=\=|\!|not|\&\&|\&|and|\|\||\||or) *)/,
exp_regex: /\A(\/((?:[^\/\\]|\\.)*?)\/)/,
exp_string: /\A(("((?:[^"\\]|\\.)*?)")|('(?:[^'\\]|\\.)*?'))/,
+ exp_string_match: /\A(("((?:[^"\\]|\\.)*?)")|('(?:[^'\\]|\\.)*?'))\Z/,
exp_percent: /\A(\%[wWqQrxsiI]?.)/,
exp_double: /\A([0-9]+\.[0-9]+([eE][-+]?[0-9]+)?)/,
exp_fixnum: /\A([0-9]+)/,
exp_nil: /\A(nil)/,
exp_boolean: /\A(true|false)/,
exp_ternary: /\A( *\? *)/,
exp_ternary_else: /\A( *\: *)/,
exp_identifier_lookahead: /\A[a-zA-Z\_][a-zA-Z0-9\_]*[\!\?]?/,
+ exp_identifier_stripped_lookahead: /\A *[a-zA-Z\_][a-zA-Z0-9\_]*[\!\?]?/,
# Hash
hash_terminator: /\A(\s*(\,)\s*)/,
hash_assignment: /\A(\s*(\=\>)\s*)/,
hash_symbol: /\A([a-zA-Z\_][a-zA-Z0-9\_]*\:(?!\:))/,
# Whitespace
whitespace: /\A\s+/,
# Evaluation
- eval: /\A\-(.*)/,
- eval_multiline: /\A\+(.*)/,
+ eval: /\A\-/,
# Whitespace
newline: /\A(\n+)/,
# Feed
@@ -152,18 +154,18 @@
# Return the requested token to the parser
#
# @param name [Symbol] Token requested by the parser accept method
#
def self.[](name)
- @@tokens[name]
+ @tokens[name]
end
# Set a new token at runtime
#
# @param name [Symboidentifierl] Identifier for the token
# @param token [Token] Token data to be set
#
def self.[]=(name, token)
- @@tokens[name] = token
+ @tokens[name] = token
end
end
end