Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored parse_signature #61

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/fiddle/cparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ def parse_struct_signature(signature, tymap=nil)
#
def parse_signature(signature, tymap=nil)
tymap ||= {}
case compact(signature)
when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
func, args = $1, $2
return [func, TYPE_VOIDP, split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}]
when /^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/
ret, func, args = $1.strip, $2, $3
return [func, parse_ctype(ret, tymap), split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}]
else
raise(RuntimeError,"can't parse the function prototype: #{signature}")
end
ctype, func, args = case compact(signature)
when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
[TYPE_VOIDP, $1, $2]
when /^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/
[parse_ctype($1.strip, tymap), $2, $3]
else
raise("can't parse the function prototype: #{signature}")
end
[func, ctype, split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}]
end

# Given a String of C type +ty+, returns the corresponding Fiddle constant.
Expand Down