Sha256: 67585d2de4b0118332aa7507657b0795f114797fc535e3744900802feda35678

Contents?: true

Size: 968 Bytes

Versions: 3

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true

class Code
  class Parser
    class Whitespace < Language
      def space
        str(" ")
      end

      def newline
        str("\n") | str("\r")
      end

      def hashtag
        str("#")
      end

      def slash
        str("/")
      end

      def asterisk
        str("*")
      end

      def hash_comment
        hashtag << (newline.absent << any).repeat << newline.maybe
      end

      def double_slash_comment
        slash << slash << (newline.absent << any).repeat << newline.maybe
      end

      def multi_line_comment
        slash << asterisk << ((asterisk << slash).absent << any).repeat <<
          asterisk.maybe << slash.maybe
      end

      def without_newline
        (space | multi_line_comment).repeat(1)
      end

      def root
        (
          space | newline | hash_comment | double_slash_comment |
            multi_line_comment
        ).repeat(1) | any.absent
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
code-ruby-0.10.4 lib/code/parser/whitespace.rb
code-ruby-0.10.3 lib/code/parser/whitespace.rb
code-ruby-0.10.2 lib/code/parser/whitespace.rb