Sha256: 176aeb4f6a6ff10c1dc6ad0d32ae38945092b08d60b56087a110c3e842430ca6

Contents?: true

Size: 1.83 KB

Versions: 65

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

class Code
  class Parser
    class Function < Language
      def name
        Name
      end

      def code
        Code
      end

      def code_present
        Code.new.present
      end

      def whitespace
        Whitespace
      end

      def whitespace?
        whitespace.maybe
      end

      def opening_parenthesis
        str("(")
      end

      def closing_parenthesis
        str(")")
      end

      def colon
        str(":")
      end

      def comma
        str(",")
      end

      def equal
        str("=")
      end

      def greater
        str(">")
      end

      def opening_curly_bracket
        str("{")
      end

      def closing_curly_bracket
        str("}")
      end

      def asterisk
        str("*")
      end

      def ampersand
        str("&")
      end

      def prefix
        (asterisk << asterisk).aka(:keyword_splat) |
          asterisk.aka(:regular_splat) | ampersand.aka(:block)
      end

      def keyword_parameter
        name.aka(:name) << whitespace? << colon.aka(:keyword) <<
          code_present.aka(:default).maybe
      end

      def regular_parameter
        prefix.maybe << name.aka(:name) << whitespace? <<
          (equal << whitespace? << code_present.aka(:default)).maybe
      end

      def parameter
        keyword_parameter | regular_parameter
      end

      def parameters
        opening_parenthesis.ignore << whitespace? <<
          (whitespace? << parameter << (whitespace? << comma).maybe).repeat <<
          (whitespace? << closing_parenthesis.ignore).maybe
      end

      def root
        (
          parameters.aka(:parameters) << whitespace? << equal << greater <<
            whitespace? << opening_curly_bracket << code.aka(:body) <<
            closing_curly_bracket.maybe
        ).aka(:function) | Dictionary
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
code-ruby-0.14.9 lib/code/parser/function.rb
code-ruby-0.14.8 lib/code/parser/function.rb
code-ruby-0.14.6 lib/code/parser/function.rb
code-ruby-0.14.5 lib/code/parser/function.rb
code-ruby-0.14.4 lib/code/parser/function.rb
code-ruby-0.14.3 lib/code/parser/function.rb
code-ruby-0.14.2 lib/code/parser/function.rb
code-ruby-0.14.1 lib/code/parser/function.rb
code-ruby-0.14.0 lib/code/parser/function.rb
code-ruby-0.13.1 lib/code/parser/function.rb
code-ruby-0.13.0 lib/code/parser/function.rb
code-ruby-0.12.0 lib/code/parser/function.rb
code-ruby-0.11.0 lib/code/parser/function.rb
code-ruby-0.10.4 lib/code/parser/function.rb
code-ruby-0.10.3 lib/code/parser/function.rb
code-ruby-0.10.2 lib/code/parser/function.rb
code-ruby-0.10.1 lib/code/parser/function.rb
code-ruby-0.10.0 lib/code/parser/function.rb
code-ruby-0.9.3 lib/code/parser/function.rb
code-ruby-0.9.2 lib/code/parser/function.rb