Sha256: f280d9dcc3ee7d73d462d7a53be69f47b25680bf0ddb5853b71ac72c88fcf313

Contents?: true

Size: 1.31 KB

Versions: 65

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

class Code
  class Parser
    class If < Language
      def statement
        IfModifier
      end

      def if_class
        If
      end

      def whitespace
        Whitespace
      end

      def code
        Code
      end

      def whitespace?
        whitespace.maybe
      end

      def if_keyword
        str("if")
      end

      def unless_keyword
        str("unless")
      end

      def elsif_keyword
        str("elsif")
      end

      def else_keyword
        str("else")
      end

      def end_keyword
        str("end")
      end

      def root
        (
          (if_keyword | unless_keyword).aka(:first_operator) << whitespace <<
            statement.aka(:first_statement) << code.aka(:first_body) <<
            (
              (
                elsif_keyword.aka(:operator) << whitespace <<
                  statement.aka(:statement) << code.aka(:body)
              ) |
                (
                  else_keyword << whitespace <<
                    (if_keyword | unless_keyword).aka(:operator) <<
                    whitespace << statement.aka(:statement) << code.aka(:body)
                ) | (else_keyword.aka(:operator) << code.aka(:body))
            ).repeat(1).aka(:elses).maybe << end_keyword.maybe
        ).aka(:if) | statement
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
code-ruby-1.1.3 lib/code/parser/if.rb
code-ruby-1.1.1 lib/code/parser/if.rb
code-ruby-1.1.0 lib/code/parser/if.rb
code-ruby-1.0.0 lib/code/parser/if.rb
code-ruby-0.15.16 lib/code/parser/if.rb
code-ruby-0.15.15 lib/code/parser/if.rb
code-ruby-0.15.14 lib/code/parser/if.rb
code-ruby-0.15.13 lib/code/parser/if.rb
code-ruby-0.15.12 lib/code/parser/if.rb
code-ruby-0.15.11 lib/code/parser/if.rb
code-ruby-0.15.10 lib/code/parser/if.rb
code-ruby-0.15.9 lib/code/parser/if.rb
code-ruby-0.15.8 lib/code/parser/if.rb
code-ruby-0.15.7 lib/code/parser/if.rb
code-ruby-0.15.6 lib/code/parser/if.rb
code-ruby-0.15.5 lib/code/parser/if.rb
code-ruby-0.15.4 lib/code/parser/if.rb
code-ruby-0.15.3 lib/code/parser/if.rb
code-ruby-0.15.2 lib/code/parser/if.rb
code-ruby-0.15.0 lib/code/parser/if.rb