Sha256: d18c4312421b7a7d9bc2582e188824293b9f130a9af6bfdf2a5cc5f282d8fc31

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

class Code
  class Parser
    class String < Language
      def code
        Code
      end

      def name
        Name
      end

      def single_quote
        str("'")
      end

      def double_quote
        str('"')
      end

      def backslash
        str('\\')
      end

      def opening_curly_bracket
        str("{")
      end

      def closing_curly_bracket
        str("}")
      end

      def colon
        str(":")
      end

      def code_part
        opening_curly_bracket << code << closing_curly_bracket.maybe
      end

      def single_quoted_text_part
        (
          (backslash.ignore << opening_curly_bracket) |
            (backslash.ignore << single_quote) |
            (single_quote.absent << opening_curly_bracket.absent << any)
        ).repeat(1)
      end

      def double_quoted_text_part
        (
          (backslash.ignore << opening_curly_bracket) |
            (backslash.ignore << double_quote) |
            (double_quote.absent << opening_curly_bracket.absent << any)
        ).repeat(1)
      end

      def single_quoted_string
        single_quote.ignore << (
          code_part.aka(:code) | single_quoted_text_part.aka(:text)
        ).repeat << single_quote.ignore.maybe
      end

      def double_quoted_string
        double_quote.ignore << (
          code_part.aka(:code) | double_quoted_text_part.aka(:text)
        ).repeat << double_quote.ignore.maybe
      end

      def symbol
        (colon.ignore << name).aka(:text).repeat(1, 1)
      end

      def root
        (single_quoted_string | double_quoted_string | symbol).aka(:string) |
          Number
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
code-ruby-1.1.3 lib/code/parser/string.rb
code-ruby-1.1.1 lib/code/parser/string.rb
code-ruby-1.1.0 lib/code/parser/string.rb