Sha256: fe745af2f455341b99efc2c1089764390c8f430c4b96c20d7502c3065375bf07

Contents?: true

Size: 816 Bytes

Versions: 70

Compression:

Stored size: 816 Bytes

Contents

# frozen_string_literal: true

class Code
  class Parser
    class Ternary < Language
      def statement
        Range
      end

      def ternary
        Ternary
      end

      def whitespace
        Whitespace
      end

      def whitespace?
        whitespace.maybe
      end

      def question_mark
        str("?")
      end

      def colon
        str(":")
      end

      def root
        (
          statement.aka(:left) << (
            whitespace? << question_mark << whitespace? <<
              ternary.aka(:middle) <<
              (whitespace? << colon << whitespace? << ternary.aka(:right)).maybe
          ).maybe
        )
          .aka(:ternary)
          .then do |output|
            output[:ternary][:middle] ? output : output[:ternary][:left]
          end
      end
    end
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
code-ruby-1.2.5 lib/code/parser/ternary.rb
code-ruby-1.2.4 lib/code/parser/ternary.rb
code-ruby-1.2.3 lib/code/parser/ternary.rb
code-ruby-1.2.2 lib/code/parser/ternary.rb
code-ruby-1.2.1 lib/code/parser/ternary.rb
code-ruby-1.1.3 lib/code/parser/ternary.rb
code-ruby-1.1.1 lib/code/parser/ternary.rb
code-ruby-1.1.0 lib/code/parser/ternary.rb
code-ruby-1.0.0 lib/code/parser/ternary.rb
code-ruby-0.15.16 lib/code/parser/ternary.rb
code-ruby-0.15.15 lib/code/parser/ternary.rb
code-ruby-0.15.14 lib/code/parser/ternary.rb
code-ruby-0.15.13 lib/code/parser/ternary.rb
code-ruby-0.15.12 lib/code/parser/ternary.rb
code-ruby-0.15.11 lib/code/parser/ternary.rb
code-ruby-0.15.10 lib/code/parser/ternary.rb
code-ruby-0.15.9 lib/code/parser/ternary.rb
code-ruby-0.15.8 lib/code/parser/ternary.rb
code-ruby-0.15.7 lib/code/parser/ternary.rb
code-ruby-0.15.6 lib/code/parser/ternary.rb