Fix indentation.

This commit is contained in:
Jakob Rath 2013-11-15 14:50:31 +01:00 committed by Dan Hirsch
parent 3f661b91e3
commit 049a64946b

View file

@ -28,40 +28,40 @@ module Hammer
end end
def self.ch(char) def self.ch(char)
# TODO: Really? Should probably accept Fixnum in appropriate range # TODO: Really? Should probably accept Fixnum in appropriate range
# Also, char.ord gives unexpected results if you pass e.g. Japanese characters: '今'.ord == 20170; Hammer::Parser::Ch.new('今').parse(202.chr) == true # Also, char.ord gives unexpected results if you pass e.g. Japanese characters: '今'.ord == 20170; Hammer::Parser::Ch.new('今').parse(202.chr) == true
# Not really unexpected though, since 20170 & 255 == 202. # Not really unexpected though, since 20170 & 255 == 202.
# But probably it's better to use Ch for Fixnum in 0..255 only, and only Token for strings. # But probably it's better to use Ch for Fixnum in 0..255 only, and only Token for strings.
raise ArgumentError, 'expecting a one-character String' unless char.is_a?(String) && char.length == 1 raise ArgumentError, 'expecting a one-character String' unless char.is_a?(String) && char.length == 1
h_parser = Hammer::Internal.h_ch(char.ord) h_parser = Hammer::Internal.h_ch(char.ord)
parser = Hammer::Parser.new parser = Hammer::Parser.new
parser.instance_variable_set :@h_parser, h_parser parser.instance_variable_set :@h_parser, h_parser
return parser return parser
end end
def self.sequence(*parsers) def self.sequence(*parsers)
args = parsers.flat_map { |p| [:pointer, p.h_parser] } args = parsers.flat_map { |p| [:pointer, p.h_parser] }
h_parser = Hammer::Internal.h_sequence(*args, :pointer, nil) h_parser = Hammer::Internal.h_sequence(*args, :pointer, nil)
sub_parsers = parsers # store them so they don't get garbage-collected (probably not needed, though) sub_parsers = parsers # store them so they don't get garbage-collected (probably not needed, though)
# TODO: Use (managed?) FFI struct instead of void pointers # TODO: Use (managed?) FFI struct instead of void pointers
parser = Hammer::Parser.new parser = Hammer::Parser.new
parser.instance_variable_set :@h_parser, h_parser parser.instance_variable_set :@h_parser, h_parser
parser.instance_variable_set :@sub_parsers, sub_parsers parser.instance_variable_set :@sub_parsers, sub_parsers
return parser return parser
end end
def self.choice(*parsers) def self.choice(*parsers)
args = parsers.flat_map { |p| [:pointer, p.h_parser] } args = parsers.flat_map { |p| [:pointer, p.h_parser] }
h_parser = Hammer::Internal.h_choice(*args, :pointer, nil) h_parser = Hammer::Internal.h_choice(*args, :pointer, nil)
sub_parsers = parsers # store them so they don't get garbage-collected (probably not needed, though) sub_parsers = parsers # store them so they don't get garbage-collected (probably not needed, though)
# TODO: Use (managed?) FFI struct instead of void pointers # TODO: Use (managed?) FFI struct instead of void pointers
parser = Hammer::Parser.new parser = Hammer::Parser.new
parser.instance_variable_set :@h_parser, h_parser parser.instance_variable_set :@h_parser, h_parser
parser.instance_variable_set :@sub_parsers, sub_parsers parser.instance_variable_set :@sub_parsers, sub_parsers
return parser return parser
end end
# Defines a parser constructor with the given name. # Defines a parser constructor with the given name.