Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hammer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Denley Lam
hammer
Commits
d343b0c8
Commit
d343b0c8
authored
11 years ago
by
Jakob Rath
Committed by
Dan Hirsch
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add accessor methods.
parent
a302953d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/bindings/ruby/lib/hammer.rb
+4
-0
4 additions, 0 deletions
src/bindings/ruby/lib/hammer.rb
src/bindings/ruby/lib/hammer/internal.rb
+49
-1
49 additions, 1 deletion
src/bindings/ruby/lib/hammer/internal.rb
with
53 additions
and
1 deletion
src/bindings/ruby/lib/hammer.rb
+
4
−
0
View file @
d343b0c8
...
...
@@ -40,5 +40,9 @@ parser =
# }
# }
#}
$r
=
parser
.
parse
'abcdefgh'
p
$r
[
:ast
][
:data
][
:seq
].
elements
.
map
{
|
e
|
e
[
:data
][
:uint
]}
# or:
p
$r
.
ast
.
data
.
map
(
&
:data
)
This diff is collapsed.
Click to expand it.
src/bindings/ruby/lib/hammer/internal.rb
+
49
−
1
View file @
d343b0c8
...
...
@@ -28,6 +28,10 @@ module Hammer
:arena
,
:pointer
,
:elements
,
:pointer
# HParsedToken**
def
used
self
[
:used
]
end
def
elements
elem_array
=
FFI
::
Pointer
.
new
(
:pointer
,
self
[
:elements
])
return
(
0
...
self
[
:used
]).
map
{
|
i
|
HParsedToken
.
new
(
elem_array
[
i
].
read_pointer
)
}
...
...
@@ -43,7 +47,12 @@ module Hammer
# Should be the same encoding as the string the token was created with.
# But how do we get to this knowledge at this point?
# Cheap solution: Just ask the user (additional parameter with default value of UTF-8).
return
self
[
:token
].
read_string
(
self
[
:len
]).
force_encoding
(
'UTF-8'
)
self
[
:token
].
read_string
(
self
[
:len
]).
force_encoding
(
'UTF-8'
)
end
# TODO: Probably should rename this to match ruby conventions: length, count, size
def
len
self
[
:len
]
end
end
...
...
@@ -62,6 +71,37 @@ module Hammer
:data
,
HParsedTokenDataUnion
.
by_value
,
:index
,
:size_t
,
:bit_offset
,
:char
def
token_type
self
[
:token_type
]
end
# TODO: Is this name ok?
def
data
return
self
[
:data
][
:bytes
].
token
if
token_type
==
:bytes
return
self
[
:data
][
:sint
]
if
token_type
==
:sint
return
self
[
:data
][
:uint
]
if
token_type
==
:uint
return
self
[
:data
][
:seq
].
elements
if
token_type
==
:sequence
return
self
[
:data
][
:user
]
if
token_type
==
:user
end
def
bytes
raise
ArgumentError
,
'wrong token type'
unless
token_type
==
:bytes
self
[
:data
][
:bytes
]
end
def
seq
raise
ArgumentError
,
'wrong token type'
unless
token_type
==
:sequence
self
[
:data
][
:seq
]
end
def
index
self
[
:index
]
end
def
bit_offset
self
[
:bit_offset
]
end
end
class
HParseResult
<
FFI
::
Struct
...
...
@@ -69,6 +109,14 @@ module Hammer
:bit_length
,
:long_long
,
:arena
,
:pointer
def
ast
self
[
:ast
]
end
def
bit_length
self
[
:bit_length
]
end
def
self
.
release
(
ptr
)
Hammer
::
Internal
.
h_parse_result_free
(
ptr
)
unless
ptr
.
null?
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment