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.27-java lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.27 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.26 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.25 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.24 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.23 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.22 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.21 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.20 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.19 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.18 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.17 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.16 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.15 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.14 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.13 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.12 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.11 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.10 lib/bel_parser/parsers/common/comment_line.rl
bel_parser-1.0.0.alpha.9 lib/bel_parser/parsers/common/comment_line.rl