Skip to content

Instantly share code, notes, and snippets.

@alco
Created April 24, 2014 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alco/11239848 to your computer and use it in GitHub Desktop.
Save alco/11239848 to your computer and use it in GitHub Desktop.
defmodule Ex do
def extract(file) do
str = File.read!(file) |> String.to_char_list!
all_toks = scan_string(str, 0, [])
# now we have all the tokens, we just need to match each one and see if
# it's a -define() form
all_toks
end
defp scan_string(str, loc, acc) do
{:ok, result, left_over} = scan_form(str, loc)
case result do
{:eof, _} -> acc
{:ok, toks, end_loc} ->
if left_over == [], do: left_over = :eof
scan_string(left_over, end_loc, [toks|acc])
end
end
defp scan_form(str, loc) do
case :erl_scan.tokens([], str, loc) do
{:done, result, left_over} ->
{:ok, result, left_over}
end
end
end
IO.inspect(Ex.extract "wx.hrl")
-record(wxTree,{type :: wxTreeEventType(), %% Callback event: {@link wxTreeEvent}
item :: integer(),
itemOld :: integer(),
pointDrag :: {X::integer(), Y::integer()}}).
-type wxTreeEventType() :: command_tree_begin_drag | command_tree_begin_rdrag | command_tree_begin_label_edit | command_tree_end_label_edit.
%% Hardcoded Records
-record(wxMouseState, {x :: integer(), y :: integer(),
leftDown :: boolean(), middleDown :: boolean, rightDown :: boolean,
controlDown :: boolean(), shiftDown :: boolean(),
altDown :: boolean(), metaDown :: boolean(), cmdDown :: boolean()
}).
-record(wxHtmlLinkInfo, {
href :: unicode:chardata(), target :: unicode:chardata()
}).
%% Hardcoded Defines
-define(wxDefaultSize, {-1,-1}).
-define(wxDefaultPosition, {-1,-1}).
%% Global Variables
-define(wxBLACK, wxe_util:get_const(wxBLACK)).
-define(wxBLACK_BRUSH, wxe_util:get_const(wxBLACK_BRUSH)).
-define(wxBLACK_DASHED_PEN, wxe_util:get_const(wxBLACK_DASHED_PEN)).
-define(wxBLUE_BRUSH, wxe_util:get_const(wxBLUE_BRUSH)).
-define(wxWHITE_PEN, wxe_util:get_const(wxWHITE_PEN)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment