Sha256: 8e7ce18f708569a59b20acc86789fd7cc78f13a38053ed1600ada099ff30d3ad

Contents?: true

Size: 1.91 KB

Versions: 39

Compression:

Stored size: 1.91 KB

Contents

# begin: ragel
=begin
%%{
  machine bel;

  include 'common.rl';

  action comment_line_start {
    @incomplete[:comment_line] = []
    @started = true
  }

  action comment_line_more {
    @incomplete[:comment_line] << fc
  }

  action comment_line_yield {
    cl = @incomplete.delete(:comment_line) || []
    completed = @started
    yield comment_line(utf8_string(cl), complete: completed)
  }

  comment_start = SP* NUMBER_SIGN;
  comment = comment_start (any - NL)*
            >comment_line_start
            $comment_line_more;
  main := comment? NL? @comment_line_yield;
}%%
=end
# end: ragel

require_relative '../ast/node'
require_relative '../mixin/buffer'
require_relative '../nonblocking_io_wrapper'

module BELParser
  module Parsers
    module Common
      module CommentLine

        class << self

          MAX_LENGTH = 1024 * 128 # 128K

          def parse(content)
            return nil unless content

            Parser.new(content).each do |obj|
              yield obj
            end
          end
        end

        private

        class Parser
          include Enumerable
          include BELParser::Parsers::Buffer
          include BELParser::Parsers::AST::Sexp

          def initialize(content)
            @content = content
      # begin: ragel
            %% write data;
      # end: ragel
          end

          def each
            @buffers    = {}
            @started    = false
            @incomplete = {}
            data        = @content.unpack('C*')
            p           = 0
            pe          = data.length
            eof         = data.length

      # begin: ragel
            %% write init;
            %% write exec;
      # end: ragel
          end
        end
      end
    end
  end
end

if __FILE__ == $0
  $stdin.each_line do |line|
    BELParser::Parsers::Common::CommentLine.parse(line) { |obj|
      puts obj.inspect
    }
  end
end

# vim: ft=ruby ts=2 sw=2:
# encoding: utf-8

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
bel_parser-1.0.4 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.3-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.3 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.2-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.2 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.1-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.1 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.61-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.61 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.60-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.60 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.59-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.59 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.58-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.58 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.57-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.57 lib/bel_parser/parsers/common/comment_line.rl