opulent 1.5.5 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CODE_OF_CONDUCT.md +13 -0
 - data/{LICENSE → LICENSE.md} +0 -0
 - data/bin/opulent +0 -0
 - data/lib/opulent.rb +10 -10
 - data/lib/opulent/compiler.rb +15 -9
 - data/lib/opulent/compiler/buffer.rb +123 -62
 - data/lib/opulent/compiler/comment.rb +3 -4
 - data/lib/opulent/compiler/control.rb +20 -26
 - data/lib/opulent/compiler/define.rb +88 -36
 - data/lib/opulent/compiler/doctype.rb +20 -22
 - data/lib/opulent/compiler/eval.rb +23 -2
 - data/lib/opulent/compiler/filter.rb +4 -5
 - data/lib/opulent/compiler/node.rb +18 -12
 - data/lib/opulent/compiler/root.rb +4 -5
 - data/lib/opulent/compiler/text.rb +7 -2
 - data/lib/opulent/compiler/yield.rb +2 -3
 - data/lib/opulent/engine.rb +21 -20
 - data/lib/opulent/exec.rb +21 -63
 - data/lib/opulent/logger.rb +230 -3
 - data/lib/opulent/parser.rb +14 -76
 - data/lib/opulent/parser/comment.rb +45 -34
 - data/lib/opulent/parser/control.rb +132 -111
 - data/lib/opulent/parser/define.rb +15 -12
 - data/lib/opulent/parser/doctype.rb +15 -15
 - data/lib/opulent/parser/eval.rb +16 -6
 - data/lib/opulent/parser/expression.rb +87 -84
 - data/lib/opulent/parser/filter.rb +31 -25
 - data/lib/opulent/parser/include.rb +38 -42
 - data/lib/opulent/parser/node.rb +136 -118
 - data/lib/opulent/parser/root.rb +24 -18
 - data/lib/opulent/parser/text.rb +150 -123
 - data/lib/opulent/parser/yield.rb +23 -23
 - data/lib/opulent/settings.rb +70 -51
 - data/lib/opulent/tokens.rb +17 -15
 - data/lib/opulent/utils.rb +5 -4
 - data/lib/opulent/version.rb +1 -1
 - metadata +4 -43
 - data/.libold/opulent.rb +0 -96
 - data/.libold/opulent/context.rb +0 -80
 - data/.libold/opulent/engine.rb +0 -88
 - data/.libold/opulent/filter.rb +0 -101
 - data/.libold/opulent/logger.rb +0 -67
 - data/.libold/opulent/nodes.rb +0 -13
 - data/.libold/opulent/nodes/block.rb +0 -29
 - data/.libold/opulent/nodes/comment.rb +0 -35
 - data/.libold/opulent/nodes/control.rb +0 -230
 - data/.libold/opulent/nodes/define.rb +0 -42
 - data/.libold/opulent/nodes/eval.rb +0 -41
 - data/.libold/opulent/nodes/expression.rb +0 -28
 - data/.libold/opulent/nodes/filter.rb +0 -70
 - data/.libold/opulent/nodes/helper.rb +0 -69
 - data/.libold/opulent/nodes/node.rb +0 -101
 - data/.libold/opulent/nodes/root.rb +0 -62
 - data/.libold/opulent/nodes/text.rb +0 -54
 - data/.libold/opulent/nodes/theme.rb +0 -36
 - data/.libold/opulent/parser.rb +0 -252
 - data/.libold/opulent/parser/block.rb +0 -70
 - data/.libold/opulent/parser/comment.rb +0 -32
 - data/.libold/opulent/parser/control.rb +0 -83
 - data/.libold/opulent/parser/define.rb +0 -39
 - data/.libold/opulent/parser/eval.rb +0 -33
 - data/.libold/opulent/parser/expression.rb +0 -350
 - data/.libold/opulent/parser/filter.rb +0 -41
 - data/.libold/opulent/parser/node.rb +0 -232
 - data/.libold/opulent/parser/root.rb +0 -96
 - data/.libold/opulent/parser/text.rb +0 -114
 - data/.libold/opulent/parser/theme.rb +0 -36
 - data/.libold/opulent/preprocessor.rb +0 -102
 - data/.libold/opulent/runtime.rb +0 -144
 - data/.libold/opulent/template.rb +0 -43
 - data/.libold/opulent/tokens.rb +0 -276
 - data/.libold/opulent/version.rb +0 -5
 - data/.travis.yml +0 -4
 - data/benchmark/benchmark.rb +0 -57
 - data/benchmark/cases/node/node.haml +0 -7
 - data/benchmark/cases/node/node.op +0 -7
 - data/benchmark/cases/node/node.slim +0 -7
 
| 
         @@ -14,21 +14,24 @@ module Opulent 
     | 
|
| 
       14 
14 
     | 
    
         
             
                # @param nodes [Array] Parent node to which we append to
         
     | 
| 
       15 
15 
     | 
    
         
             
                #
         
     | 
| 
       16 
16 
     | 
    
         
             
                def define(parent, indent)
         
     | 
| 
       17 
     | 
    
         
            -
                   
     | 
| 
       18 
     | 
    
         
            -
                    # Process data
         
     | 
| 
       19 
     | 
    
         
            -
                    name = accept(:node, :*).to_sym
         
     | 
| 
      
 17 
     | 
    
         
            +
                  return unless accept(:def)
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
                  # Definition parent check
         
     | 
| 
      
 20 
     | 
    
         
            +
                  Logger.error :parse, @code, @i, @j, :definition if parent[@type] != :root
         
     | 
| 
       23 
21 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                    # nodes (we do not check if they are have a definition or not).
         
     | 
| 
       27 
     | 
    
         
            -
                    root definition, indent
         
     | 
| 
      
 22 
     | 
    
         
            +
                  # Process data
         
     | 
| 
      
 23 
     | 
    
         
            +
                  name = accept(:node, :*).to_sym
         
     | 
| 
       28 
24 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
                  # Create node
         
     | 
| 
      
 26 
     | 
    
         
            +
                  definition = [:def, name, { parameters: attributes }, [], indent]
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  # Set definition as root node and let the parser know that we're inside
         
     | 
| 
      
 29 
     | 
    
         
            +
                  # a definition. This is used because inside definitions we do not
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # process nodes (we do not check if they are have a definition or not).
         
     | 
| 
      
 31 
     | 
    
         
            +
                  root definition, indent
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  # Add to parent
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @definitions[name] = definition
         
     | 
| 
       32 
35 
     | 
    
         
             
                end
         
     | 
| 
       33 
36 
     | 
    
         
             
              end
         
     | 
| 
       34 
37 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,15 +1,15 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # @Opulent
         
     | 
| 
       2 
     | 
    
         
            -
            module Opulent
         
     | 
| 
       3 
     | 
    
         
            -
              # @Parser
         
     | 
| 
       4 
     | 
    
         
            -
              class Parser
         
     | 
| 
       5 
     | 
    
         
            -
                # Match one line or multiline comments
         
     | 
| 
       6 
     | 
    
         
            -
                #
         
     | 
| 
       7 
     | 
    
         
            -
                def doctype(parent, indent)
         
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                   
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # @Opulent
         
     | 
| 
      
 2 
     | 
    
         
            +
            module Opulent
         
     | 
| 
      
 3 
     | 
    
         
            +
              # @Parser
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Parser
         
     | 
| 
      
 5 
     | 
    
         
            +
                # Match one line or multiline comments
         
     | 
| 
      
 6 
     | 
    
         
            +
                #
         
     | 
| 
      
 7 
     | 
    
         
            +
                def doctype(parent, indent)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  return unless accept :doctype
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  buffer = accept(:line_feed)
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  parent[@children] << [:doctype, buffer.strip.to_sym, {}, nil, indent]
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/opulent/parser/eval.rb
    CHANGED
    
    | 
         @@ -6,16 +6,26 @@ module Opulent 
     | 
|
| 
       6 
6 
     | 
    
         
             
                #
         
     | 
| 
       7 
7 
     | 
    
         
             
                def evaluate(parent, indent)
         
     | 
| 
       8 
8 
     | 
    
         
             
                  # Accept eval or multiline eval syntax and return a new node,
         
     | 
| 
       9 
     | 
    
         
            -
                   
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
      
 9 
     | 
    
         
            +
                  return unless accept :eval
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  multiline = accept(:text)
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  if multiline
         
     | 
| 
      
 14 
     | 
    
         
            +
                    # Get first evaluation line
         
     | 
| 
      
 15 
     | 
    
         
            +
                    evaluate_code = accept(:line_feed) || ''
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       12 
17 
     | 
    
         
             
                    # Get all the lines which are more indented than the current one
         
     | 
| 
       13 
     | 
    
         
            -
                    eval_node = [:evaluate,  
     | 
| 
       14 
     | 
    
         
            -
                    eval_node[@value] += accept(:newline) ||  
     | 
| 
      
 18 
     | 
    
         
            +
                    eval_node = [:evaluate, evaluate_code.strip, {}, nil, indent]
         
     | 
| 
      
 19 
     | 
    
         
            +
                    eval_node[@value] += accept(:newline) || ''
         
     | 
| 
       15 
20 
     | 
    
         
             
                    eval_node[@value] += get_indented_lines(indent)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  else
         
     | 
| 
      
 22 
     | 
    
         
            +
                    evaluate_code = accept(:line_feed) || ''
         
     | 
| 
      
 23 
     | 
    
         
            +
                    eval_node = [:evaluate, evaluate_code.strip, {}, [], indent]
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    root eval_node, indent
         
     | 
| 
       16 
26 
     | 
    
         
             
                  end
         
     | 
| 
       17 
27 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                  parent[@children] << eval_node 
     | 
| 
      
 28 
     | 
    
         
            +
                  parent[@children] << eval_node
         
     | 
| 
       19 
29 
     | 
    
         
             
                end
         
     | 
| 
       20 
30 
     | 
    
         
             
              end
         
     | 
| 
       21 
31 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,46 +5,50 @@ module Opulent 
     | 
|
| 
       5 
5 
     | 
    
         
             
                # Check if the parser matches an expression node
         
     | 
| 
       6 
6 
     | 
    
         
             
                #
         
     | 
| 
       7 
7 
     | 
    
         
             
                def expression(allow_assignments = true, wrapped = true, whitespace = true)
         
     | 
| 
       8 
     | 
    
         
            -
                  buffer =  
     | 
| 
      
 8 
     | 
    
         
            +
                  buffer = ''
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                  # Build a ruby expression out of accepted literals
         
     | 
| 
       11 
     | 
    
         
            -
                  while (term = (whitespace ? accept(:whitespace) : nil) 
     | 
| 
       12 
     | 
    
         
            -
                                modifier 
     | 
| 
       13 
     | 
    
         
            -
                                identifier 
     | 
| 
       14 
     | 
    
         
            -
                                method_call 
     | 
| 
       15 
     | 
    
         
            -
                                paranthesis 
     | 
| 
       16 
     | 
    
         
            -
                                array 
     | 
| 
       17 
     | 
    
         
            -
                                hash 
     | 
| 
       18 
     | 
    
         
            -
                                symbol 
     | 
| 
       19 
     | 
    
         
            -
                                percent 
     | 
| 
      
 11 
     | 
    
         
            +
                  while (term = (whitespace ? accept(:whitespace) : nil) ||
         
     | 
| 
      
 12 
     | 
    
         
            +
                                modifier ||
         
     | 
| 
      
 13 
     | 
    
         
            +
                                identifier ||
         
     | 
| 
      
 14 
     | 
    
         
            +
                                method_call ||
         
     | 
| 
      
 15 
     | 
    
         
            +
                                paranthesis ||
         
     | 
| 
      
 16 
     | 
    
         
            +
                                array ||
         
     | 
| 
      
 17 
     | 
    
         
            +
                                hash ||
         
     | 
| 
      
 18 
     | 
    
         
            +
                                symbol ||
         
     | 
| 
      
 19 
     | 
    
         
            +
                                percent ||
         
     | 
| 
       20 
20 
     | 
    
         
             
                                primary_term)
         
     | 
| 
       21 
21 
     | 
    
         
             
                    buffer += term
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                    # Accept operations which have a right term and raise an error if
         
     | 
| 
       24 
24 
     | 
    
         
             
                    # we have an unfinished expression such as "a +", "b - 1 >" and other
         
     | 
| 
       25 
25 
     | 
    
         
             
                    # expressions following the same pattern
         
     | 
| 
       26 
     | 
    
         
            -
                    if wrapped && (op = operation || 
     | 
| 
      
 26 
     | 
    
         
            +
                    if wrapped && (op = operation ||
         
     | 
| 
      
 27 
     | 
    
         
            +
                      (allow_assignments ? accept_stripped(:exp_assignment) : nil))
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       27 
29 
     | 
    
         
             
                      buffer += op
         
     | 
| 
       28 
30 
     | 
    
         
             
                      if (right_term = expression(allow_assignments, wrapped)).nil?
         
     | 
| 
       29 
     | 
    
         
            -
                        error :expression
         
     | 
| 
      
 31 
     | 
    
         
            +
                        Logger.error :parse, @code, @i, @j, :expression
         
     | 
| 
       30 
32 
     | 
    
         
             
                      else
         
     | 
| 
       31 
33 
     | 
    
         
             
                        buffer += right_term[@value]
         
     | 
| 
       32 
34 
     | 
    
         
             
                      end
         
     | 
| 
       33 
     | 
    
         
            -
                    elsif ( 
     | 
| 
       34 
     | 
    
         
            -
                      buffer 
     | 
| 
      
 35 
     | 
    
         
            +
                    elsif (op = array || op = method_call || op = ternary_operator(allow_assignments, wrapped))
         
     | 
| 
      
 36 
     | 
    
         
            +
                      p buffer
         
     | 
| 
      
 37 
     | 
    
         
            +
                      p op
         
     | 
| 
      
 38 
     | 
    
         
            +
                      buffer += op
         
     | 
| 
       35 
39 
     | 
    
         
             
                    end
         
     | 
| 
       36 
40 
     | 
    
         | 
| 
       37 
41 
     | 
    
         
             
                    # Do not continue if the expression has whitespace method calls in
         
     | 
| 
       38 
42 
     | 
    
         
             
                    # an unwrapped context because this will confuse the parser
         
     | 
| 
       39 
43 
     | 
    
         
             
                    unless buffer.strip.empty?
         
     | 
| 
       40 
     | 
    
         
            -
                      break  
     | 
| 
      
 44 
     | 
    
         
            +
                      break if lookahead(:exp_identifier_lookahead).nil?
         
     | 
| 
       41 
45 
     | 
    
         
             
                    end
         
     | 
| 
       42 
46 
     | 
    
         
             
                  end
         
     | 
| 
       43 
47 
     | 
    
         | 
| 
       44 
48 
     | 
    
         
             
                  if buffer.strip.empty?
         
     | 
| 
       45 
     | 
    
         
            -
                     
     | 
| 
      
 49 
     | 
    
         
            +
                    undo buffer
         
     | 
| 
       46 
50 
     | 
    
         
             
                  else
         
     | 
| 
       47 
     | 
    
         
            -
                     
     | 
| 
      
 51 
     | 
    
         
            +
                    [:expression, buffer.strip, {}]
         
     | 
| 
       48 
52 
     | 
    
         
             
                  end
         
     | 
| 
       49 
53 
     | 
    
         
             
                end
         
     | 
| 
       50 
54 
     | 
    
         | 
| 
         @@ -55,12 +59,12 @@ module Opulent 
     | 
|
| 
       55 
59 
     | 
    
         
             
                # [array_elements]
         
     | 
| 
       56 
60 
     | 
    
         
             
                #
         
     | 
| 
       57 
61 
     | 
    
         
             
                def array
         
     | 
| 
       58 
     | 
    
         
            -
                   
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                   
     | 
| 
      
 62 
     | 
    
         
            +
                  return unless (buffer = accept :square_bracket)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  accept_newline
         
     | 
| 
      
 64 
     | 
    
         
            +
                  buffer += array_elements
         
     | 
| 
      
 65 
     | 
    
         
            +
                  accept_newline
         
     | 
| 
      
 66 
     | 
    
         
            +
                  buffer += accept :'[', :*
         
     | 
| 
      
 67 
     | 
    
         
            +
                  buffer
         
     | 
| 
       64 
68 
     | 
    
         
             
                end
         
     | 
| 
       65 
69 
     | 
    
         | 
| 
       66 
70 
     | 
    
         
             
                # Recursively gather expressions separated by a comma and add them to the
         
     | 
| 
         @@ -75,7 +79,7 @@ module Opulent 
     | 
|
| 
       75 
79 
     | 
    
         
             
                    buffer += term[@value]
         
     | 
| 
       76 
80 
     | 
    
         
             
                    # If there is an array_terminator ",", recursively gather the next
         
     | 
| 
       77 
81 
     | 
    
         
             
                    # array element into the buffer
         
     | 
| 
       78 
     | 
    
         
            -
                    if (terminator = accept_stripped :comma) 
     | 
| 
      
 82 
     | 
    
         
            +
                    if (terminator = accept_stripped :comma)
         
     | 
| 
       79 
83 
     | 
    
         
             
                      accept_newline
         
     | 
| 
       80 
84 
     | 
    
         
             
                      buffer += array_elements terminator
         
     | 
| 
       81 
85 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -83,11 +87,9 @@ module Opulent 
     | 
|
| 
       83 
87 
     | 
    
         | 
| 
       84 
88 
     | 
    
         
             
                  # Array ended prematurely with a trailing comma, therefore the current
         
     | 
| 
       85 
89 
     | 
    
         
             
                  # parsing process will stop
         
     | 
| 
       86 
     | 
    
         
            -
                  if buffer.strip[-1] == ','
         
     | 
| 
       87 
     | 
    
         
            -
                    error :array_elements_terminator
         
     | 
| 
       88 
     | 
    
         
            -
                  end
         
     | 
| 
      
 90 
     | 
    
         
            +
                  error :array_elements_terminator if buffer.strip[-1] == ','
         
     | 
| 
       89 
91 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
                   
     | 
| 
      
 92 
     | 
    
         
            +
                  buffer
         
     | 
| 
       91 
93 
     | 
    
         
             
                end
         
     | 
| 
       92 
94 
     | 
    
         | 
| 
       93 
95 
     | 
    
         
             
                # Check if it's possible to parse a ruby hash literal. First, try to see
         
     | 
| 
         @@ -97,12 +99,12 @@ module Opulent 
     | 
|
| 
       97 
99 
     | 
    
         
             
                # { hash_elements }
         
     | 
| 
       98 
100 
     | 
    
         
             
                #
         
     | 
| 
       99 
101 
     | 
    
         
             
                def hash
         
     | 
| 
       100 
     | 
    
         
            -
                   
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
                   
     | 
| 
      
 102 
     | 
    
         
            +
                  return unless (buffer = accept :curly_bracket)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  accept_newline
         
     | 
| 
      
 104 
     | 
    
         
            +
                  buffer += hash_elements
         
     | 
| 
      
 105 
     | 
    
         
            +
                  accept_newline
         
     | 
| 
      
 106 
     | 
    
         
            +
                  buffer += accept :'{', :*
         
     | 
| 
      
 107 
     | 
    
         
            +
                  buffer
         
     | 
| 
       106 
108 
     | 
    
         
             
                end
         
     | 
| 
       107 
109 
     | 
    
         | 
| 
       108 
110 
     | 
    
         
             
                # Recursively gather expression attributions separated by a comma and add
         
     | 
| 
         @@ -113,7 +115,7 @@ module Opulent 
     | 
|
| 
       113 
115 
     | 
    
         
             
                # @param buffer [String] Accumulator for the hash elements
         
     | 
| 
       114 
116 
     | 
    
         
             
                #
         
     | 
| 
       115 
117 
     | 
    
         
             
                def hash_elements(buffer = '')
         
     | 
| 
       116 
     | 
    
         
            -
                  value =  
     | 
| 
      
 118 
     | 
    
         
            +
                  value = proc do
         
     | 
| 
       117 
119 
     | 
    
         
             
                    # Get the value associated to the current hash key
         
     | 
| 
       118 
120 
     | 
    
         
             
                    if (exp = expression)
         
     | 
| 
       119 
121 
     | 
    
         
             
                      buffer += exp[@value]
         
     | 
| 
         @@ -123,7 +125,7 @@ module Opulent 
     | 
|
| 
       123 
125 
     | 
    
         | 
| 
       124 
126 
     | 
    
         
             
                    # If there is an hash_terminator ",", recursively gather the next
         
     | 
| 
       125 
127 
     | 
    
         
             
                    # array element into the buffer
         
     | 
| 
       126 
     | 
    
         
            -
                    if (terminator = accept_stripped :comma) 
     | 
| 
      
 128 
     | 
    
         
            +
                    if (terminator = accept_stripped :comma)
         
     | 
| 
       127 
129 
     | 
    
         
             
                      accept_newline
         
     | 
| 
       128 
130 
     | 
    
         
             
                      buffer += hash_elements terminator
         
     | 
| 
       129 
131 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -139,7 +141,7 @@ module Opulent 
     | 
|
| 
       139 
141 
     | 
    
         
             
                    value[]
         
     | 
| 
       140 
142 
     | 
    
         
             
                  elsif (exp = expression false)
         
     | 
| 
       141 
143 
     | 
    
         
             
                    buffer += exp[@value]
         
     | 
| 
       142 
     | 
    
         
            -
                    if(assign = accept_stripped :hash_assignment)
         
     | 
| 
      
 144 
     | 
    
         
            +
                    if (assign = accept_stripped :hash_assignment)
         
     | 
| 
       143 
145 
     | 
    
         
             
                      buffer += assign
         
     | 
| 
       144 
146 
     | 
    
         
             
                      value[]
         
     | 
| 
       145 
147 
     | 
    
         
             
                    else
         
     | 
| 
         @@ -149,31 +151,28 @@ module Opulent 
     | 
|
| 
       149 
151 
     | 
    
         | 
| 
       150 
152 
     | 
    
         
             
                  # Array ended prematurely with a trailing comma, therefore the current
         
     | 
| 
       151 
153 
     | 
    
         
             
                  # parsing process will stop
         
     | 
| 
       152 
     | 
    
         
            -
                  if buffer.strip[-1] == ','
         
     | 
| 
       153 
     | 
    
         
            -
                    error :hash_elements_terminator
         
     | 
| 
       154 
     | 
    
         
            -
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                  error :hash_elements_terminator if buffer.strip[-1] == ','
         
     | 
| 
       155 
155 
     | 
    
         | 
| 
       156 
     | 
    
         
            -
                   
     | 
| 
      
 156 
     | 
    
         
            +
                  buffer
         
     | 
| 
       157 
157 
     | 
    
         
             
                end
         
     | 
| 
       158 
158 
     | 
    
         | 
| 
       159 
159 
     | 
    
         
             
                # Accept a ruby identifier such as a class, module, method or variable
         
     | 
| 
       160 
160 
     | 
    
         
             
                #
         
     | 
| 
       161 
161 
     | 
    
         
             
                def identifier
         
     | 
| 
       162 
     | 
    
         
            -
                   
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
                    end
         
     | 
| 
       166 
     | 
    
         
            -
                    return buffer
         
     | 
| 
      
 162 
     | 
    
         
            +
                  return unless (buffer = accept :exp_identifier)
         
     | 
| 
      
 163 
     | 
    
         
            +
                  if (args = call)
         
     | 
| 
      
 164 
     | 
    
         
            +
                    buffer += args
         
     | 
| 
       167 
165 
     | 
    
         
             
                  end
         
     | 
| 
      
 166 
     | 
    
         
            +
                  buffer
         
     | 
| 
       168 
167 
     | 
    
         
             
                end
         
     | 
| 
       169 
168 
     | 
    
         | 
| 
       170 
169 
     | 
    
         
             
                # Check if it's possible to parse a ruby paranthesis expression wrapper.
         
     | 
| 
       171 
170 
     | 
    
         
             
                #
         
     | 
| 
       172 
171 
     | 
    
         
             
                def paranthesis
         
     | 
| 
       173 
     | 
    
         
            -
                   
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
                   
     | 
| 
      
 172 
     | 
    
         
            +
                  return unless (buffer = accept :round_bracket)
         
     | 
| 
      
 173 
     | 
    
         
            +
                  buffer += expression[@value]
         
     | 
| 
      
 174 
     | 
    
         
            +
                  buffer += accept_stripped :'(', :*
         
     | 
| 
      
 175 
     | 
    
         
            +
                  buffer
         
     | 
| 
       177 
176 
     | 
    
         
             
                end
         
     | 
| 
       178 
177 
     | 
    
         | 
| 
       179 
178 
     | 
    
         
             
                # Check if it's possible to parse a ruby call literal. First, try to see
         
     | 
| 
         @@ -183,10 +182,11 @@ module Opulent 
     | 
|
| 
       183 
182 
     | 
    
         
             
                # ( call_elements )
         
     | 
| 
       184 
183 
     | 
    
         
             
                #
         
     | 
| 
       185 
184 
     | 
    
         
             
                def call
         
     | 
| 
       186 
     | 
    
         
            -
                   
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
                   
     | 
| 
      
 185 
     | 
    
         
            +
                  return unless (buffer = accept :round_bracket)
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
                  buffer += call_elements
         
     | 
| 
      
 188 
     | 
    
         
            +
                  buffer += accept_stripped :'(', :*
         
     | 
| 
      
 189 
     | 
    
         
            +
                  buffer
         
     | 
| 
       190 
190 
     | 
    
         
             
                end
         
     | 
| 
       191 
191 
     | 
    
         | 
| 
       192 
192 
     | 
    
         
             
                # Recursively gather expression attributes separated by a comma and add
         
     | 
| 
         @@ -215,13 +215,13 @@ module Opulent 
     | 
|
| 
       215 
215 
     | 
    
         | 
| 
       216 
216 
     | 
    
         
             
                    # If there is an comma ",", recursively gather the next
         
     | 
| 
       217 
217 
     | 
    
         
             
                    # array element into the buffer
         
     | 
| 
       218 
     | 
    
         
            -
                    if (terminator = accept_stripped :comma) 
     | 
| 
      
 218 
     | 
    
         
            +
                    if (terminator = accept_stripped :comma)
         
     | 
| 
       219 
219 
     | 
    
         
             
                      buffer += call_elements terminator
         
     | 
| 
       220 
220 
     | 
    
         
             
                    end
         
     | 
| 
       221 
221 
     | 
    
         
             
                  elsif (exp = expression(true))
         
     | 
| 
       222 
222 
     | 
    
         
             
                    buffer += exp[@value]
         
     | 
| 
       223 
223 
     | 
    
         | 
| 
       224 
     | 
    
         
            -
                    if(assign = accept_stripped :hash_assignment)
         
     | 
| 
      
 224 
     | 
    
         
            +
                    if (assign = accept_stripped :hash_assignment)
         
     | 
| 
       225 
225 
     | 
    
         
             
                      buffer += assign
         
     | 
| 
       226 
226 
     | 
    
         | 
| 
       227 
227 
     | 
    
         
             
                      # Get the value associated to the current hash key
         
     | 
| 
         @@ -234,7 +234,7 @@ module Opulent 
     | 
|
| 
       234 
234 
     | 
    
         | 
| 
       235 
235 
     | 
    
         
             
                    # If there is an comma ",", recursively gather the next
         
     | 
| 
       236 
236 
     | 
    
         
             
                    # array element into the buffer
         
     | 
| 
       237 
     | 
    
         
            -
                    if (terminator = accept_stripped :comma) 
     | 
| 
      
 237 
     | 
    
         
            +
                    if (terminator = accept_stripped :comma)
         
     | 
| 
       238 
238 
     | 
    
         
             
                      buffer += call_elements terminator
         
     | 
| 
       239 
239 
     | 
    
         
             
                    end
         
     | 
| 
       240 
240 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -248,14 +248,13 @@ module Opulent 
     | 
|
| 
       248 
248 
     | 
    
         
             
                # :symbol
         
     | 
| 
       249 
249 
     | 
    
         
             
                #
         
     | 
| 
       250 
250 
     | 
    
         
             
                def symbol
         
     | 
| 
       251 
     | 
    
         
            -
                   
     | 
| 
       252 
     | 
    
         
            -
             
     | 
| 
      
 251 
     | 
    
         
            +
                  return unless (colon = accept :colon)
         
     | 
| 
      
 252 
     | 
    
         
            +
                  return undo colon if lookahead(:whitespace)
         
     | 
| 
       253 
253 
     | 
    
         | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
       255 
     | 
    
         
            -
             
     | 
| 
       256 
     | 
    
         
            -
             
     | 
| 
       257 
     | 
    
         
            -
             
     | 
| 
       258 
     | 
    
         
            -
                    end
         
     | 
| 
      
 254 
     | 
    
         
            +
                  if (exp = expression).nil?
         
     | 
| 
      
 255 
     | 
    
         
            +
                    error :symbol
         
     | 
| 
      
 256 
     | 
    
         
            +
                  else
         
     | 
| 
      
 257 
     | 
    
         
            +
                    colon + exp[@value]
         
     | 
| 
       259 
258 
     | 
    
         
             
                  end
         
     | 
| 
       260 
259 
     | 
    
         
             
                end
         
     | 
| 
       261 
260 
     | 
    
         | 
| 
         @@ -268,30 +267,29 @@ module Opulent 
     | 
|
| 
       268 
267 
     | 
    
         
             
                  accept(:exp_context) || accept(:exp_module)
         
     | 
| 
       269 
268 
     | 
    
         
             
                end
         
     | 
| 
       270 
269 
     | 
    
         | 
| 
       271 
     | 
    
         
            -
             
     | 
| 
       272 
270 
     | 
    
         
             
                # Accept a ruby percentage operator for arrays of strings, symbols and
         
     | 
| 
       273 
271 
     | 
    
         
             
                # simple escaped strings
         
     | 
| 
       274 
272 
     | 
    
         
             
                #
         
     | 
| 
       275 
273 
     | 
    
         
             
                # %w(word1 word2 word3)
         
     | 
| 
       276 
274 
     | 
    
         
             
                #
         
     | 
| 
       277 
275 
     | 
    
         
             
                def percent
         
     | 
| 
       278 
     | 
    
         
            -
                   
     | 
| 
       279 
     | 
    
         
            -
             
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
                    unless Tokens[match_name]
         
     | 
| 
       283 
     | 
    
         
            -
                      match_end = Tokens.bracket(match_start) || match_start
         
     | 
| 
      
 276 
     | 
    
         
            +
                  return unless (buffer = accept_stripped :exp_percent)
         
     | 
| 
      
 277 
     | 
    
         
            +
                  match_start = buffer[-1]
         
     | 
| 
      
 278 
     | 
    
         
            +
                  match_name = :"percent#{match_start}"
         
     | 
| 
       284 
279 
     | 
    
         | 
| 
       285 
     | 
    
         
            -
             
     | 
| 
       286 
     | 
    
         
            -
             
     | 
| 
      
 280 
     | 
    
         
            +
                  unless Tokens[match_name]
         
     | 
| 
      
 281 
     | 
    
         
            +
                    match_end = Tokens.bracket(match_start) || match_start
         
     | 
| 
       287 
282 
     | 
    
         | 
| 
       288 
     | 
    
         
            -
             
     | 
| 
      
 283 
     | 
    
         
            +
                    match_inner = "\\#{match_start}"
         
     | 
| 
      
 284 
     | 
    
         
            +
                    match_inner += "\\#{match_end}" unless match_end == match_start
         
     | 
| 
       289 
285 
     | 
    
         | 
| 
       290 
     | 
    
         
            -
             
     | 
| 
       291 
     | 
    
         
            -
                    end
         
     | 
| 
      
 286 
     | 
    
         
            +
                    pattern = /(((?:[^#{match_inner}\\]|\\.)*?)#{'\\' + match_end})/
         
     | 
| 
       292 
287 
     | 
    
         | 
| 
       293 
     | 
    
         
            -
                     
     | 
| 
      
 288 
     | 
    
         
            +
                    Tokens[match_name] = pattern
         
     | 
| 
       294 
289 
     | 
    
         
             
                  end
         
     | 
| 
      
 290 
     | 
    
         
            +
             
     | 
| 
      
 291 
     | 
    
         
            +
                  buffer += accept match_name
         
     | 
| 
      
 292 
     | 
    
         
            +
                  buffer
         
     | 
| 
       295 
293 
     | 
    
         
             
                end
         
     | 
| 
       296 
294 
     | 
    
         | 
| 
       297 
295 
     | 
    
         
             
                # Accept any primary term and return it without the leading whitespace to
         
     | 
| 
         @@ -306,12 +304,12 @@ module Opulent 
     | 
|
| 
       306 
304 
     | 
    
         
             
                # /.*/
         
     | 
| 
       307 
305 
     | 
    
         
             
                #
         
     | 
| 
       308 
306 
     | 
    
         
             
                def primary_term
         
     | 
| 
       309 
     | 
    
         
            -
                  accept_stripped(:exp_string) 
     | 
| 
       310 
     | 
    
         
            -
             
     | 
| 
       311 
     | 
    
         
            -
             
     | 
| 
       312 
     | 
    
         
            -
             
     | 
| 
       313 
     | 
    
         
            -
             
     | 
| 
       314 
     | 
    
         
            -
             
     | 
| 
      
 307 
     | 
    
         
            +
                  accept_stripped(:exp_string) ||
         
     | 
| 
      
 308 
     | 
    
         
            +
                    accept_stripped(:exp_fixnum) ||
         
     | 
| 
      
 309 
     | 
    
         
            +
                    accept_stripped(:exp_double) ||
         
     | 
| 
      
 310 
     | 
    
         
            +
                    accept_stripped(:exp_nil) ||
         
     | 
| 
      
 311 
     | 
    
         
            +
                    accept_stripped(:exp_regex) ||
         
     | 
| 
      
 312 
     | 
    
         
            +
                    accept_stripped(:exp_boolean)
         
     | 
| 
       315 
313 
     | 
    
         
             
                end
         
     | 
| 
       316 
314 
     | 
    
         | 
| 
       317 
315 
     | 
    
         
             
                # Accept an operation between two or more expressions
         
     | 
| 
         @@ -323,7 +321,12 @@ module Opulent 
     | 
|
| 
       323 
321 
     | 
    
         
             
                # Accept a ruby method call modifier
         
     | 
| 
       324 
322 
     | 
    
         
             
                #
         
     | 
| 
       325 
323 
     | 
    
         
             
                def method_call
         
     | 
| 
       326 
     | 
    
         
            -
                  accept(:exp_method_call)
         
     | 
| 
      
 324 
     | 
    
         
            +
                  return unless (method_code = accept(:exp_method_call))
         
     | 
| 
      
 325 
     | 
    
         
            +
             
     | 
| 
      
 326 
     | 
    
         
            +
                  argument = call
         
     | 
| 
      
 327 
     | 
    
         
            +
                  method_code += argument if argument
         
     | 
| 
      
 328 
     | 
    
         
            +
             
     | 
| 
      
 329 
     | 
    
         
            +
                  method_code
         
     | 
| 
       327 
330 
     | 
    
         
             
                end
         
     | 
| 
       328 
331 
     | 
    
         | 
| 
       329 
332 
     | 
    
         
             
                # Accept ternary operator syntax
         
     | 
| 
         @@ -1,25 +1,31 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # @Opulent
         
     | 
| 
       2 
     | 
    
         
            -
            module Opulent
         
     | 
| 
       3 
     | 
    
         
            -
              # @Parser
         
     | 
| 
       4 
     | 
    
         
            -
              class Parser
         
     | 
| 
       5 
     | 
    
         
            -
                # Check if we match an compile time filter
         
     | 
| 
       6 
     | 
    
         
            -
                #
         
     | 
| 
       7 
     | 
    
         
            -
                # :filter
         
     | 
| 
       8 
     | 
    
         
            -
                #
         
     | 
| 
       9 
     | 
    
         
            -
                # @param parent [Node] Parent node to which we append the element
         
     | 
| 
       10 
     | 
    
         
            -
                #
         
     | 
| 
       11 
     | 
    
         
            -
                def filter(parent, indent)
         
     | 
| 
       12 
     | 
    
         
            -
                   
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # @Opulent
         
     | 
| 
      
 2 
     | 
    
         
            +
            module Opulent
         
     | 
| 
      
 3 
     | 
    
         
            +
              # @Parser
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Parser
         
     | 
| 
      
 5 
     | 
    
         
            +
                # Check if we match an compile time filter
         
     | 
| 
      
 6 
     | 
    
         
            +
                #
         
     | 
| 
      
 7 
     | 
    
         
            +
                # :filter
         
     | 
| 
      
 8 
     | 
    
         
            +
                #
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @param parent [Node] Parent node to which we append the element
         
     | 
| 
      
 10 
     | 
    
         
            +
                #
         
     | 
| 
      
 11 
     | 
    
         
            +
                def filter(parent, indent)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  return unless (filter_name = accept :filter)
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  # Get element attributes
         
     | 
| 
      
 15 
     | 
    
         
            +
                  atts = attributes(shorthand_attributes) || {}
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  # Accept inline text or multiline text feed as first child
         
     | 
| 
      
 18 
     | 
    
         
            +
                  error :fiter unless accept(:line_feed).strip.empty?
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  # Get everything under the filter and set it as the node value
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # and create a new node and set its extension
         
     | 
| 
      
 22 
     | 
    
         
            +
                  parent[@children] << [
         
     | 
| 
      
 23 
     | 
    
         
            +
                    :filter,
         
     | 
| 
      
 24 
     | 
    
         
            +
                    filter_name[1..-1].to_sym,
         
     | 
| 
      
 25 
     | 
    
         
            +
                    atts,
         
     | 
| 
      
 26 
     | 
    
         
            +
                    get_indented_lines(indent),
         
     | 
| 
      
 27 
     | 
    
         
            +
                    indent
         
     | 
| 
      
 28 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     |