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-1.1.3 lib/code/parser/function.rb
code-ruby-1.1.1 lib/code/parser/function.rb
code-ruby-1.1.0 lib/code/parser/function.rb
code-ruby-1.0.0 lib/code/parser/function.rb
code-ruby-0.15.16 lib/code/parser/function.rb
code-ruby-0.15.15 lib/code/parser/function.rb
code-ruby-0.15.14 lib/code/parser/function.rb
code-ruby-0.15.13 lib/code/parser/function.rb
code-ruby-0.15.12 lib/code/parser/function.rb
code-ruby-0.15.11 lib/code/parser/function.rb
code-ruby-0.15.10 lib/code/parser/function.rb
code-ruby-0.15.9 lib/code/parser/function.rb
code-ruby-0.15.8 lib/code/parser/function.rb
code-ruby-0.15.7 lib/code/parser/function.rb
code-ruby-0.15.6 lib/code/parser/function.rb
code-ruby-0.15.5 lib/code/parser/function.rb
code-ruby-0.15.4 lib/code/parser/function.rb
code-ruby-0.15.3 lib/code/parser/function.rb
code-ruby-0.15.2 lib/code/parser/function.rb
code-ruby-0.15.0 lib/code/parser/function.rb