Sha256: 00c2f0ebbd9dfe8fd65f0ff464b09dc552b1ba4c071942704cf4c8a3fcb21fc2

Contents?: true

Size: 1.85 KB

Versions: 48

Compression:

Stored size: 1.85 KB

Contents

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

  include 'common.rl';

  action start_comment_line {
    @buffers[:comment_line] = []
  }

  action append_comment_line {
    @buffers[:comment_line] << fc
  }

  action finish_comment_line {
    @buffers[:comment_line] = comment_line(
                                utf8_string(@buffers[:comment_line]))
  }

  action yield_comment_line {
    yield @buffers[:comment_line]
  }

  COMMENT_LINE  =
    SP*
    NUMBER_SIGN
    (any - NL)* >start_comment_line $append_comment_line %finish_comment_line;

  comment_line := COMMENT_LINE %yield_comment_line NL;
}%%
=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 = {}
            data     = @content.unpack('C*')
            p        = 0
            pe       = 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

48 entries across 48 versions & 1 rubygems

Version Path
bel_parser-1.0.0.alpha.38-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.38 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.37-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.37 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.36-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.36 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.35-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.35 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.34-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.34 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.32-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.32 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.31-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.31 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.30-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.30 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.29-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.29 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.28-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.28 lib/bel_parser/parsers/common/comment_line.rl