Fix indentation.
This commit is contained in:
parent
3f661b91e3
commit
049a64946b
1 changed files with 25 additions and 25 deletions
|
|
@ -28,40 +28,40 @@ module Hammer
|
|||
end
|
||||
|
||||
def self.ch(char)
|
||||
# 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
|
||||
# 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.
|
||||
raise ArgumentError, 'expecting a one-character String' unless char.is_a?(String) && char.length == 1
|
||||
h_parser = Hammer::Internal.h_ch(char.ord)
|
||||
# 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
|
||||
# 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.
|
||||
raise ArgumentError, 'expecting a one-character String' unless char.is_a?(String) && char.length == 1
|
||||
h_parser = Hammer::Internal.h_ch(char.ord)
|
||||
|
||||
parser = Hammer::Parser.new
|
||||
parser.instance_variable_set :@h_parser, h_parser
|
||||
return parser
|
||||
parser = Hammer::Parser.new
|
||||
parser.instance_variable_set :@h_parser, h_parser
|
||||
return parser
|
||||
end
|
||||
|
||||
def self.sequence(*parsers)
|
||||
args = parsers.flat_map { |p| [:pointer, p.h_parser] }
|
||||
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)
|
||||
# TODO: Use (managed?) FFI struct instead of void pointers
|
||||
args = parsers.flat_map { |p| [:pointer, p.h_parser] }
|
||||
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)
|
||||
# TODO: Use (managed?) FFI struct instead of void pointers
|
||||
|
||||
parser = Hammer::Parser.new
|
||||
parser.instance_variable_set :@h_parser, h_parser
|
||||
parser.instance_variable_set :@sub_parsers, sub_parsers
|
||||
return parser
|
||||
parser = Hammer::Parser.new
|
||||
parser.instance_variable_set :@h_parser, h_parser
|
||||
parser.instance_variable_set :@sub_parsers, sub_parsers
|
||||
return parser
|
||||
end
|
||||
|
||||
def self.choice(*parsers)
|
||||
args = parsers.flat_map { |p| [:pointer, p.h_parser] }
|
||||
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)
|
||||
# TODO: Use (managed?) FFI struct instead of void pointers
|
||||
args = parsers.flat_map { |p| [:pointer, p.h_parser] }
|
||||
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)
|
||||
# TODO: Use (managed?) FFI struct instead of void pointers
|
||||
|
||||
parser = Hammer::Parser.new
|
||||
parser.instance_variable_set :@h_parser, h_parser
|
||||
parser.instance_variable_set :@sub_parsers, sub_parsers
|
||||
return parser
|
||||
parser = Hammer::Parser.new
|
||||
parser.instance_variable_set :@h_parser, h_parser
|
||||
parser.instance_variable_set :@sub_parsers, sub_parsers
|
||||
return parser
|
||||
end
|
||||
|
||||
# Defines a parser constructor with the given name.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue