pygments.rb 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pygments/version.rb +1 -1
- data/vendor/pygments-main/AUTHORS +14 -0
- data/vendor/pygments-main/CHANGES +34 -3
- data/vendor/pygments-main/Makefile +1 -1
- data/vendor/pygments-main/docs/generate.py +1 -1
- data/vendor/pygments-main/external/markdown-processor.py +1 -1
- data/vendor/pygments-main/external/moin-parser.py +1 -1
- data/vendor/pygments-main/external/rst-directive-old.py +1 -1
- data/vendor/pygments-main/external/rst-directive.py +1 -1
- data/vendor/pygments-main/pygments/__init__.py +1 -1
- data/vendor/pygments-main/pygments/cmdline.py +4 -1
- data/vendor/pygments-main/pygments/console.py +1 -1
- data/vendor/pygments-main/pygments/filter.py +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +1 -1
- data/vendor/pygments-main/pygments/formatter.py +1 -1
- data/vendor/pygments-main/pygments/formatters/__init__.py +1 -1
- data/vendor/pygments-main/pygments/formatters/_mapping.py +1 -1
- data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
- data/vendor/pygments-main/pygments/formatters/html.py +2 -2
- data/vendor/pygments-main/pygments/formatters/img.py +1 -1
- data/vendor/pygments-main/pygments/formatters/latex.py +3 -2
- data/vendor/pygments-main/pygments/formatters/other.py +1 -1
- data/vendor/pygments-main/pygments/formatters/rtf.py +1 -1
- data/vendor/pygments-main/pygments/formatters/svg.py +1 -1
- data/vendor/pygments-main/pygments/formatters/terminal.py +5 -2
- data/vendor/pygments-main/pygments/formatters/terminal256.py +5 -2
- data/vendor/pygments-main/pygments/lexer.py +29 -10
- data/vendor/pygments-main/pygments/lexers/__init__.py +14 -11
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_mapping.py +41 -23
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -3
- data/vendor/pygments-main/pygments/lexers/agile.py +148 -443
- data/vendor/pygments-main/pygments/lexers/asm.py +5 -3
- data/vendor/pygments-main/pygments/lexers/compiled.py +298 -294
- data/vendor/pygments-main/pygments/lexers/dotnet.py +40 -34
- data/vendor/pygments-main/pygments/lexers/functional.py +723 -4
- data/vendor/pygments-main/pygments/lexers/hdl.py +228 -6
- data/vendor/pygments-main/pygments/lexers/jvm.py +678 -0
- data/vendor/pygments-main/pygments/lexers/math.py +65 -2
- data/vendor/pygments-main/pygments/lexers/other.py +875 -481
- data/vendor/pygments-main/pygments/lexers/parsers.py +1 -1
- data/vendor/pygments-main/pygments/lexers/shell.py +360 -0
- data/vendor/pygments-main/pygments/lexers/special.py +1 -1
- data/vendor/pygments-main/pygments/lexers/sql.py +565 -0
- data/vendor/pygments-main/pygments/lexers/templates.py +1 -1
- data/vendor/pygments-main/pygments/lexers/text.py +237 -100
- data/vendor/pygments-main/pygments/lexers/web.py +146 -10
- data/vendor/pygments-main/pygments/plugin.py +1 -1
- data/vendor/pygments-main/pygments/scanner.py +1 -1
- data/vendor/pygments-main/pygments/style.py +1 -1
- data/vendor/pygments-main/pygments/styles/__init__.py +2 -1
- data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
- data/vendor/pygments-main/pygments/styles/borland.py +1 -1
- data/vendor/pygments-main/pygments/styles/bw.py +1 -1
- data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
- data/vendor/pygments-main/pygments/styles/default.py +1 -1
- data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
- data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
- data/vendor/pygments-main/pygments/styles/fruity.py +1 -2
- data/vendor/pygments-main/pygments/styles/manni.py +1 -1
- data/vendor/pygments-main/pygments/styles/monokai.py +1 -1
- data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
- data/vendor/pygments-main/pygments/styles/native.py +1 -1
- data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
- data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
- data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
- data/vendor/pygments-main/pygments/styles/tango.py +1 -1
- data/vendor/pygments-main/pygments/styles/trac.py +1 -1
- data/vendor/pygments-main/pygments/styles/vim.py +1 -1
- data/vendor/pygments-main/pygments/styles/vs.py +1 -1
- data/vendor/pygments-main/pygments/token.py +1 -1
- data/vendor/pygments-main/pygments/unistring.py +1 -1
- data/vendor/pygments-main/pygments/util.py +2 -2
- data/vendor/pygments-main/scripts/check_sources.py +2 -2
- data/vendor/pygments-main/scripts/find_codetags.py +1 -1
- data/vendor/pygments-main/scripts/find_error.py +5 -2
- data/vendor/pygments-main/scripts/get_vimkw.py +9 -4
- data/vendor/pygments-main/setup.py +1 -1
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +16 -0
- data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
- data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
- data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
- data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
- data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +4 -2
- data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
- data/vendor/pygments-main/tests/examplefiles/test.cs +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
- data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
- data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
- data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
- data/vendor/pygments-main/tests/old_run.py +1 -1
- data/vendor/pygments-main/tests/run.py +1 -1
- data/vendor/pygments-main/tests/test_basic_api.py +4 -3
- data/vendor/pygments-main/tests/test_clexer.py +1 -1
- data/vendor/pygments-main/tests/test_cmdline.py +1 -1
- data/vendor/pygments-main/tests/test_examplefiles.py +4 -3
- data/vendor/pygments-main/tests/test_html_formatter.py +33 -1
- data/vendor/pygments-main/tests/test_latex_formatter.py +1 -1
- data/vendor/pygments-main/tests/test_perllexer.py +137 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +1 -1
- data/vendor/pygments-main/tests/test_token.py +1 -1
- data/vendor/pygments-main/tests/test_using_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +35 -5
- metadata +30 -4
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# We cannot use to_char_list because it depends on inspect,
|
|
2
|
+
# which depends on protocol, which depends on this module.
|
|
3
|
+
import Elixir::Builtin, except: [to_char_list: 1]
|
|
4
|
+
|
|
5
|
+
defmodule Module do
|
|
6
|
+
require Erlang.ets, as: ETS
|
|
7
|
+
|
|
8
|
+
@moduledoc """
|
|
9
|
+
This module provides many functions to deal with modules during
|
|
10
|
+
compilation time. It allows a developer to dynamically attach
|
|
11
|
+
documentation, merge data, register attributes and so forth.
|
|
12
|
+
|
|
13
|
+
After the module is compiled, using many of the functions in
|
|
14
|
+
this module will raise errors, since it is out of their purpose
|
|
15
|
+
to inspect runtime data. Most of the runtime data can be inspected
|
|
16
|
+
via the `__info__(attr)` function attached to each compiled module.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
@doc """
|
|
20
|
+
Evalutes the quotes contents in the given module context.
|
|
21
|
+
Raises an error if the module was already compiled.
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
defmodule Foo do
|
|
26
|
+
contents = quote do: (def sum(a, b), do: a + b)
|
|
27
|
+
Module.eval_quoted __MODULE__, contents, [], __FILE__, __LINE__
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Foo.sum(1, 2) #=> 3
|
|
31
|
+
"""
|
|
32
|
+
def eval_quoted(module, quoted, binding, filename, line) do
|
|
33
|
+
assert_not_compiled!(:eval_quoted, module)
|
|
34
|
+
{ binding, scope } = Erlang.elixir_module.binding_and_scope_for_eval(line, to_char_list(filename), module, binding)
|
|
35
|
+
Erlang.elixir_def.reset_last(module)
|
|
36
|
+
Erlang.elixir.eval_quoted([quoted], binding, line, scope)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
@doc """
|
|
40
|
+
Checks if the module is compiled or not.
|
|
41
|
+
|
|
42
|
+
## Examples
|
|
43
|
+
|
|
44
|
+
defmodule Foo do
|
|
45
|
+
Module.compiled?(__MODULE__) #=> false
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
Module.compiled?(Foo) #=> true
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
def compiled?(module) do
|
|
52
|
+
table = data_table_for(module)
|
|
53
|
+
table == ETS.info(table, :name)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
@doc """
|
|
57
|
+
Reads the data for the given module. This is used
|
|
58
|
+
to read data of uncompiled modules. If the module
|
|
59
|
+
was already compiled, you shoul access the data
|
|
60
|
+
directly by invoking `__info__(:data)` in that module.
|
|
61
|
+
|
|
62
|
+
## Examples
|
|
63
|
+
|
|
64
|
+
defmodule Foo do
|
|
65
|
+
Module.merge_data __MODULE__, value: 1
|
|
66
|
+
Module.read_data __MODULE__ #=> [value: 1]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
def read_data(module) do
|
|
71
|
+
assert_not_compiled!(:read_data, module)
|
|
72
|
+
ETS.lookup_element(data_table_for(module), :data, 2)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
@doc """
|
|
76
|
+
Reads the data from `module` at the given key `at`.
|
|
77
|
+
|
|
78
|
+
## Examples
|
|
79
|
+
|
|
80
|
+
defmodule Foo do
|
|
81
|
+
Module.merge_data __MODULE__, value: 1
|
|
82
|
+
Module.read_data __MODULE__, :value #=> 1
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
"""
|
|
86
|
+
def read_data(module, at) do
|
|
87
|
+
Orddict.get read_data(module), at
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
@doc """
|
|
91
|
+
Merge the given data into the module, overriding any
|
|
92
|
+
previous one.
|
|
93
|
+
|
|
94
|
+
If any of the given data is a registered attribute, it is
|
|
95
|
+
automatically added to the attribute set, instead of marking
|
|
96
|
+
it as data. See register_attribute/2 and add_attribute/3 for
|
|
97
|
+
more info.
|
|
98
|
+
|
|
99
|
+
## Examples
|
|
100
|
+
|
|
101
|
+
defmodule Foo do
|
|
102
|
+
Module.merge_data __MODULE__, value: 1
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
Foo.__info__(:data) #=> [value: 1]
|
|
106
|
+
|
|
107
|
+
"""
|
|
108
|
+
def merge_data(module, data) do
|
|
109
|
+
assert_not_compiled!(:merge_data, module)
|
|
110
|
+
|
|
111
|
+
table = data_table_for(module)
|
|
112
|
+
old = ETS.lookup_element(table, :data, 2)
|
|
113
|
+
registered = ETS.lookup_element(table, :registered_attributes, 2)
|
|
114
|
+
|
|
115
|
+
{ attrs, new } = Enum.partition data, fn({k,_}) -> List.member?(registered, k) end
|
|
116
|
+
Enum.each attrs, fn({k,v}) -> add_attribute(module, k, v) end
|
|
117
|
+
ETS.insert(table, { :data, Orddict.merge(old, new) })
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
@doc """
|
|
121
|
+
Attaches documentation to a given function. It expects
|
|
122
|
+
the module the function belongs to, the line (a non negative
|
|
123
|
+
integer), the kind (def or defmacro), a tuple representing
|
|
124
|
+
the function and its arity and the documentation, which should
|
|
125
|
+
be either a binary or a boolean.
|
|
126
|
+
|
|
127
|
+
## Examples
|
|
128
|
+
|
|
129
|
+
defmodule MyModule do
|
|
130
|
+
Module.add_doc(__MODULE__, __LINE__ + 1, :def, { :version, 0 }, "Manually added docs")
|
|
131
|
+
def version, do: 1
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
"""
|
|
135
|
+
def add_doc(module, line, kind, tuple, doc) when
|
|
136
|
+
is_binary(doc) or is_boolean(doc) do
|
|
137
|
+
assert_not_compiled!(:add_doc, module)
|
|
138
|
+
case kind do
|
|
139
|
+
match: :defp
|
|
140
|
+
:warn
|
|
141
|
+
else:
|
|
142
|
+
table = docs_table_for(module)
|
|
143
|
+
ETS.insert(table, { tuple, line, kind, doc })
|
|
144
|
+
:ok
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
@doc """
|
|
149
|
+
Checks if a function was defined, regardless if it is
|
|
150
|
+
a macro or a private function. Use function_defined?/3
|
|
151
|
+
to assert for an specific type.
|
|
152
|
+
|
|
153
|
+
## Examples
|
|
154
|
+
|
|
155
|
+
defmodule Example do
|
|
156
|
+
Module.function_defined? __MODULE__, { :version, 0 } #=> false
|
|
157
|
+
def version, do: 1
|
|
158
|
+
Module.function_defined? __MODULE__, { :version, 0 } #=> true
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
"""
|
|
162
|
+
def function_defined?(module, tuple) when is_tuple(tuple) do
|
|
163
|
+
assert_not_compiled!(:function_defined?, module)
|
|
164
|
+
table = function_table_for(module)
|
|
165
|
+
ETS.lookup(table, tuple) != []
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
@doc """
|
|
169
|
+
Checks if a function was defined and also for its `kind`.
|
|
170
|
+
`kind` can be either :def, :defp or :defmacro.
|
|
171
|
+
|
|
172
|
+
## Examples
|
|
173
|
+
|
|
174
|
+
defmodule Example do
|
|
175
|
+
Module.function_defined? __MODULE__, { :version, 0 }, :defp #=> false
|
|
176
|
+
def version, do: 1
|
|
177
|
+
Module.function_defined? __MODULE__, { :version, 0 }, :defp #=> false
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
"""
|
|
181
|
+
def function_defined?(module, tuple, kind) do
|
|
182
|
+
List.member? defined_functions(module, kind), tuple
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
@doc """
|
|
186
|
+
Return all functions defined in the given module.
|
|
187
|
+
|
|
188
|
+
## Examples
|
|
189
|
+
|
|
190
|
+
defmodule Example do
|
|
191
|
+
def version, do: 1
|
|
192
|
+
Module.defined_functions __MODULE__ #=> [{:version,1}]
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
"""
|
|
196
|
+
def defined_functions(module) do
|
|
197
|
+
assert_not_compiled!(:defined_functions, module)
|
|
198
|
+
table = function_table_for(module)
|
|
199
|
+
lc { tuple, _, _ } in ETS.tab2list(table), do: tuple
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
@doc """
|
|
203
|
+
Returns all functions defined in te given module according
|
|
204
|
+
to its kind.
|
|
205
|
+
|
|
206
|
+
## Examples
|
|
207
|
+
|
|
208
|
+
defmodule Example do
|
|
209
|
+
def version, do: 1
|
|
210
|
+
Module.defined_functions __MODULE__, :def #=> [{:version,1}]
|
|
211
|
+
Module.defined_functions __MODULE__, :defp #=> []
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
"""
|
|
215
|
+
def defined_functions(module, kind) do
|
|
216
|
+
assert_not_compiled!(:defined_functions, module)
|
|
217
|
+
table = function_table_for(module)
|
|
218
|
+
entry = kind_to_entry(kind)
|
|
219
|
+
ETS.lookup_element(table, entry, 2)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
@doc """
|
|
223
|
+
Adds a compilation callback hook that is invoked
|
|
224
|
+
exactly before the module is compiled.
|
|
225
|
+
|
|
226
|
+
This callback is useful when used with `use` as a mechanism
|
|
227
|
+
to clean up any internal data in the module before it is compiled.
|
|
228
|
+
|
|
229
|
+
## Examples
|
|
230
|
+
|
|
231
|
+
Imagine you are creating a module/library that is meant for
|
|
232
|
+
external usage called `MyLib`. It could be defined as:
|
|
233
|
+
|
|
234
|
+
defmodule MyLib do
|
|
235
|
+
def __using__(target) do
|
|
236
|
+
Module.merge_data target, some_data: true
|
|
237
|
+
Module.add_compile_callback(target, __MODULE__, :__callback__)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
defmacro __callback__(target) do
|
|
241
|
+
value = Orddict.get(Module.read_data(target), :some_data, [])
|
|
242
|
+
quote do: (def my_lib_value, do: unquote(value))
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
And a module could use `MyLib` with:
|
|
247
|
+
|
|
248
|
+
defmodule App do
|
|
249
|
+
use ModuleTest::ToBeUsed
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
In the example above, `MyLib` defines a data to the target. This data
|
|
253
|
+
can be updated throughout the module definition and therefore, the final
|
|
254
|
+
value of the data can only be compiled using a compiation callback,
|
|
255
|
+
which will read the final value of :some_data and compile to a function.
|
|
256
|
+
"""
|
|
257
|
+
def add_compile_callback(module, target, fun // :__compiling__) do
|
|
258
|
+
assert_not_compiled!(:add_compile_callback, module)
|
|
259
|
+
new = { target, fun }
|
|
260
|
+
table = data_table_for(module)
|
|
261
|
+
old = ETS.lookup_element(table, :compile_callbacks, 2)
|
|
262
|
+
ETS.insert(table, { :compile_callbacks, [new|old] })
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
@doc """
|
|
266
|
+
Adds an Erlang attribute to the given module with the given
|
|
267
|
+
key and value. The same attribute can be added more than once.
|
|
268
|
+
|
|
269
|
+
## Examples
|
|
270
|
+
|
|
271
|
+
defmodule MyModule do
|
|
272
|
+
Module.add_attribute __MODULE__, :custom_threshold_for_lib, 10
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
"""
|
|
276
|
+
def add_attribute(module, key, value) when is_atom(key) do
|
|
277
|
+
assert_not_compiled!(:add_attribute, module)
|
|
278
|
+
table = data_table_for(module)
|
|
279
|
+
attrs = ETS.lookup_element(table, :attributes, 2)
|
|
280
|
+
ETS.insert(table, { :attributes, [{key, value}|attrs] })
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
@doc """
|
|
284
|
+
Deletes all attributes that matches the given key.
|
|
285
|
+
|
|
286
|
+
## Examples
|
|
287
|
+
|
|
288
|
+
defmodule MyModule do
|
|
289
|
+
Module.add_attribute __MODULE__, :custom_threshold_for_lib, 10
|
|
290
|
+
Module.delete_attribute __MODULE__, :custom_threshold_for_lib
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
"""
|
|
294
|
+
def delete_attribute(module, key) when is_atom(key) do
|
|
295
|
+
assert_not_compiled!(:delete_attribute, module)
|
|
296
|
+
table = data_table_for(module)
|
|
297
|
+
attrs = ETS.lookup_element(table, :attributes, 2)
|
|
298
|
+
final = lc {k,v} in attrs, k != key, do: {k,v}
|
|
299
|
+
ETS.insert(table, { :attributes, final })
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
@doc """
|
|
303
|
+
Registers an attribute. This allows a developer to use the data API
|
|
304
|
+
but Elixir will register the data as an attribute automatically.
|
|
305
|
+
By default, `vsn`, `behavior` and other Erlang attributes are
|
|
306
|
+
automatically registered.
|
|
307
|
+
|
|
308
|
+
## Examples
|
|
309
|
+
|
|
310
|
+
defmodule MyModule do
|
|
311
|
+
Module.register_attribute __MODULE__, :custom_threshold_for_lib
|
|
312
|
+
@custom_threshold_for_lib 10
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
"""
|
|
316
|
+
def register_attribute(module, new) do
|
|
317
|
+
assert_not_compiled!(:register_attribute, module)
|
|
318
|
+
table = data_table_for(module)
|
|
319
|
+
old = ETS.lookup_element(table, :registered_attributes, 2)
|
|
320
|
+
ETS.insert(table, { :registered_attributes, [new|old] })
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
@doc false
|
|
324
|
+
# Used internally to compile documentation. This function
|
|
325
|
+
# is private and must be used only internally.
|
|
326
|
+
def compile_doc(module, line, kind, pair) do
|
|
327
|
+
case read_data(module, :doc) do
|
|
328
|
+
match: nil
|
|
329
|
+
# We simply discard nil
|
|
330
|
+
match: doc
|
|
331
|
+
result = add_doc(module, line, kind, pair, doc)
|
|
332
|
+
merge_data(module, doc: nil)
|
|
333
|
+
result
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
## Helpers
|
|
338
|
+
|
|
339
|
+
defp kind_to_entry(:def), do: :public
|
|
340
|
+
defp kind_to_entry(:defp), do: :private
|
|
341
|
+
defp kind_to_entry(:defmacro), do: :macros
|
|
342
|
+
|
|
343
|
+
defp to_char_list(list) when is_list(list), do: list
|
|
344
|
+
defp to_char_list(bin) when is_binary(bin), do: binary_to_list(bin)
|
|
345
|
+
|
|
346
|
+
defp data_table_for(module) do
|
|
347
|
+
list_to_atom Erlang.lists.concat([:d, module])
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
defp function_table_for(module) do
|
|
351
|
+
list_to_atom Erlang.lists.concat([:f, module])
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
defp docs_table_for(module) do
|
|
355
|
+
list_to_atom Erlang.lists.concat([:o, module])
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
defp assert_not_compiled!(fun, module) do
|
|
359
|
+
compiled?(module) ||
|
|
360
|
+
raise ArgumentError, message:
|
|
361
|
+
"could not call #{fun} on module #{module} because it was already compiled"
|
|
362
|
+
end
|
|
363
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
POST /demo/submit/ HTTP/1.1
|
|
2
|
+
Host: pygments.org
|
|
3
|
+
Connection: keep-alivk
|
|
4
|
+
Cache-Control: max-age=0
|
|
5
|
+
Origin: http://pygments.org
|
|
6
|
+
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
|
|
7
|
+
Content-Type: application/x-www-form-urlencoded
|
|
8
|
+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
|
|
9
|
+
Referer: http://pygments.org/
|
|
10
|
+
Accept-Encoding: gzip,deflate,sdch
|
|
11
|
+
Accept-Language: en-US,en;q=0.8
|
|
12
|
+
Accept-Charset: windows-949,utf-8;q=0.7,*;q=0.3
|
|
13
|
+
|
|
14
|
+
name=test&lang=text&code=asdf&user=
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
HTTP/1.1 200 OK
|
|
2
|
+
Date: Tue, 13 Dec 2011 00:11:44 GMT
|
|
3
|
+
Status: 200 OK
|
|
4
|
+
X-Transaction: 50b85fff78dab4a3
|
|
5
|
+
X-RateLimit-Limit: 150
|
|
6
|
+
ETag: "b31143be48ebfe7512b65fe64fe092f3"
|
|
7
|
+
X-Frame-Options: SAMEORIGIN
|
|
8
|
+
Last-Modified: Tue, 13 Dec 2011 00:11:44 GMT
|
|
9
|
+
X-RateLimit-Remaining: 145
|
|
10
|
+
X-Runtime: 0.01190
|
|
11
|
+
X-Transaction-Mask: a6183ffa5f8ca943ff1b53b5644ef1145f6f285d
|
|
12
|
+
Content-Type: application/json; charset=utf-8
|
|
13
|
+
Content-Length: 2389
|
|
14
|
+
Pragma: no-cache
|
|
15
|
+
X-RateLimit-Class: api
|
|
16
|
+
X-Revision: DEV
|
|
17
|
+
Expires: Tue, 31 Mar 1981 05:00:00 GMT
|
|
18
|
+
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
|
|
19
|
+
X-MID: a55f21733bc52bb11d1fc58f9b51b4974fbb8f83
|
|
20
|
+
X-RateLimit-Reset: 1323738416
|
|
21
|
+
Set-Cookie: k=10.34.234.116.1323735104238974; path=/; expires=Tue, 20-Dec-11 00:11:44 GMT; domain=.twitter.com
|
|
22
|
+
Set-Cookie: guest_id=v1%3A13237351042425496; domain=.twitter.com; path=/; expires=Thu, 12-Dec-2013 12:11:44 GMT
|
|
23
|
+
Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCPS6wjQ0AToHaWQiJTFiMTlhY2E1ZjczYThk%250ANDUwMWQxNjMwZGU2YTQ1ODBhIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--6b502f30a083e8a41a64f10930e142ea362b1561; domain=.twitter.com; path=/; HttpOnly
|
|
24
|
+
Vary: Accept-Encoding
|
|
25
|
+
Server: tfe
|
|
26
|
+
|
|
27
|
+
[{"contributors_enabled":false,"profile_background_tile":true,"followers_count":644,"protected":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/69064242\/gb_normal.jpg","screen_name":"birkenfeld","default_profile_image":false,"following":null,"friends_count":88,"profile_sidebar_fill_color":"7AC3EE","url":"http:\/\/pythonic.pocoo.org\/","name":"Georg Brandl","default_profile":false,"is_translator":false,"utc_offset":3600,"profile_sidebar_border_color":"65B0DA","description":"","profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme10\/bg.gif","favourites_count":0,"profile_use_background_image":true,"created_at":"Tue Dec 30 22:25:11 +0000 2008","status":{"retweet_count":10,"favorited":false,"geo":null,"possibly_sensitive":false,"coordinates":null,"in_reply_to_screen_name":null,"in_reply_to_status_id_str":null,"retweeted":false,"in_reply_to_status_id":null,"in_reply_to_user_id_str":null,"created_at":"Sat Jul 09 13:42:35 +0000 2011","truncated":false,"id_str":"89690914515206144","contributors":null,"place":null,"source":"web","in_reply_to_user_id":null,"id":89690914515206144,"retweeted_status":{"retweet_count":10,"favorited":false,"geo":null,"possibly_sensitive":false,"coordinates":null,"in_reply_to_screen_name":null,"in_reply_to_status_id_str":null,"retweeted":false,"in_reply_to_status_id":null,"in_reply_to_user_id_str":null,"created_at":"Sat Jul 09 13:07:04 +0000 2011","truncated":false,"id_str":"89681976755372032","contributors":null,"place":null,"source":"web","in_reply_to_user_id":null,"id":89681976755372032,"text":"Excellent Python posts from @mitsuhiko - http:\/\/t.co\/k1wt6e4 and @ncoghlan_dev - http:\/\/t.co\/eTxacgZ (links fixed)"},"text":"RT @jessenoller: Excellent Python posts from @mitsuhiko - http:\/\/t.co\/k1wt6e4 and @ncoghlan_dev - http:\/\/t.co\/eTxacgZ (links fixed)"},"follow_request_sent":null,"statuses_count":553,"geo_enabled":false,"notifications":null,"profile_text_color":"3D1957","id_str":"18490730","lang":"en","profile_background_image_url":"http:\/\/a1.twimg.com\/images\/themes\/theme10\/bg.gif","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/69064242\/gb_normal.jpg","show_all_inline_media":true,"listed_count":65,"profile_link_color":"FF0000","verified":false,"id":18490730,"time_zone":"Berlin","profile_background_color":"642D8B","location":"Bavaria, Germany"}]
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/usr/bin/env newlisp
|
|
2
|
+
|
|
3
|
+
;; @module IRC
|
|
4
|
+
;; @description a basic irc library
|
|
5
|
+
;; @version early alpha! 0.1 2011-10-31 14:21:26
|
|
6
|
+
;; @author cormullion
|
|
7
|
+
;; Usage:
|
|
8
|
+
;; (IRC:init "newlithper") ; a username/nick (not that one obviously :-)
|
|
9
|
+
;; (IRC:connect "irc.freenode.net" 6667) ; irc/server
|
|
10
|
+
;; (IRC:join-channel {#newlisp}) ; join a room
|
|
11
|
+
;; either (IRC:read-irc-loop) ; loop - monitor only, no input
|
|
12
|
+
;; or (IRC:session) ; a command-line session, end with /QUIT
|
|
13
|
+
|
|
14
|
+
(context 'IRC)
|
|
15
|
+
(define Inickname)
|
|
16
|
+
(define Ichannels)
|
|
17
|
+
(define Iserver)
|
|
18
|
+
(define Iconnected)
|
|
19
|
+
(define Icallbacks '())
|
|
20
|
+
(define Idle-time 400) ; seconds
|
|
21
|
+
(define Itime-stamp) ; time since last message was processed
|
|
22
|
+
|
|
23
|
+
(define (register-callback callback-name callback-function)
|
|
24
|
+
(println {registering callback for } callback-name { : } (sym (term callback-function) (prefix callback-function)))
|
|
25
|
+
(push (list callback-name (sym (term callback-function) (prefix callback-function))) Icallbacks))
|
|
26
|
+
|
|
27
|
+
(define (do-callback callback-name data)
|
|
28
|
+
(when (set 'func (lookup callback-name Icallbacks)) ; find first callback
|
|
29
|
+
(if-not (catch (apply func (list data)) 'error)
|
|
30
|
+
(println {error in callback } callback-name {: } error))))
|
|
31
|
+
|
|
32
|
+
(define (do-callbacks callback-name data)
|
|
33
|
+
(dolist (rf (ref-all callback-name Icallbacks))
|
|
34
|
+
(set 'callback-entry (Icallbacks (first rf)))
|
|
35
|
+
(when (set 'func (last callback-entry))
|
|
36
|
+
(if-not (catch (apply func (list data)) 'error)
|
|
37
|
+
(println {error in callback } callback-name {: } error)))))
|
|
38
|
+
|
|
39
|
+
(define (init str)
|
|
40
|
+
(set 'Inickname str)
|
|
41
|
+
(set 'Iconnected nil)
|
|
42
|
+
(set 'Ichannels '())
|
|
43
|
+
(set 'Itime-stamp (time-of-day)))
|
|
44
|
+
|
|
45
|
+
(define (connect server port)
|
|
46
|
+
(set 'Iserver (net-connect server port))
|
|
47
|
+
(net-send Iserver (format "USER %s %s %s :%s\r\n" Inickname Inickname Inickname Inickname))
|
|
48
|
+
(net-send Iserver (format "NICK %s \r\n" Inickname))
|
|
49
|
+
(set 'Iconnected true)
|
|
50
|
+
(do-callbacks "connect" (list (list "server" server) (list "port" port))))
|
|
51
|
+
|
|
52
|
+
(define (identify password)
|
|
53
|
+
(net-send Iserver (format "PRIVMSG nickserv :identify %s\r\n" password)))
|
|
54
|
+
|
|
55
|
+
(define (join-channel channel)
|
|
56
|
+
(when (net-send Iserver (format "JOIN %s \r\n" channel))
|
|
57
|
+
(push channel Ichannels)
|
|
58
|
+
(do-callbacks "join-channel" (list (list "channel" channel) (list "nickname" Inickname)))))
|
|
59
|
+
|
|
60
|
+
(define (part chan)
|
|
61
|
+
(if-not (empty? chan)
|
|
62
|
+
; leave specified
|
|
63
|
+
(begin
|
|
64
|
+
(net-send Iserver (format "PART %s\r\n" chan))
|
|
65
|
+
(replace channel Ichannels)
|
|
66
|
+
(do-callbacks "part" (list (list "channel" channel))))
|
|
67
|
+
; leave all
|
|
68
|
+
(begin
|
|
69
|
+
(dolist (channel Ichannels)
|
|
70
|
+
(net-send Iserver (format "PART %s\r\n" channel))
|
|
71
|
+
(replace channel Ichannels)
|
|
72
|
+
(do-callbacks "part" (list (list "channel" channel)))))))
|
|
73
|
+
|
|
74
|
+
(define (do-quit message)
|
|
75
|
+
(do-callbacks "quit" '()) ; chance to do stuff before quit...
|
|
76
|
+
(net-send Iserver (format "QUIT :%s\r\n" message))
|
|
77
|
+
(sleep 1000)
|
|
78
|
+
(set 'Ichannels '())
|
|
79
|
+
(close Iserver)
|
|
80
|
+
(set 'Iconnected nil))
|
|
81
|
+
|
|
82
|
+
(define (privmsg user message)
|
|
83
|
+
(net-send Iserver (format "PRIVMSG %s :%s\r\n" user message)))
|
|
84
|
+
|
|
85
|
+
(define (notice user message)
|
|
86
|
+
(net-send Iserver (format "NOTICE %s :%s\r\n" user message)))
|
|
87
|
+
|
|
88
|
+
(define (send-to-server message (channel nil))
|
|
89
|
+
(cond
|
|
90
|
+
((starts-with message {/}) ; default command character
|
|
91
|
+
(set 'the-message (replace "^/" (copy message) {} 0)) ; keep original
|
|
92
|
+
(net-send Iserver (format "%s \r\n" the-message)) ; send it
|
|
93
|
+
; do a quit
|
|
94
|
+
(if (starts-with (lower-case the-message) "quit")
|
|
95
|
+
(do-quit { enough})))
|
|
96
|
+
(true
|
|
97
|
+
(if (nil? channel)
|
|
98
|
+
; say to all channels
|
|
99
|
+
(dolist (c Ichannels)
|
|
100
|
+
(net-send Iserver (format "PRIVMSG %s :%s\r\n" c message)))
|
|
101
|
+
; say to specified channel
|
|
102
|
+
(if (find channel Ichannels)
|
|
103
|
+
(net-send Iserver (format "PRIVMSG %s :%s\r\n" channel message))))))
|
|
104
|
+
(do-callbacks "send-to-server" (list (list "channel" channel) (list "message" message))))
|
|
105
|
+
|
|
106
|
+
(define (process-command sender command text)
|
|
107
|
+
(cond
|
|
108
|
+
((= sender "PING")
|
|
109
|
+
(net-send Iserver (format "PONG %s\r\n" command)))
|
|
110
|
+
((or (= command "NOTICE") (= command "PRIVMSG"))
|
|
111
|
+
(process-message sender command text))
|
|
112
|
+
((= command "JOIN")
|
|
113
|
+
(set 'username (first (clean empty? (parse sender {!|:} 0))))
|
|
114
|
+
(set 'channel (last (clean empty? (parse sender {!|:} 0))))
|
|
115
|
+
(println {username } username { joined } channel)
|
|
116
|
+
(do-callbacks "join" (list (list "channel" channel) (list "username" username))))
|
|
117
|
+
(true
|
|
118
|
+
nil)))
|
|
119
|
+
|
|
120
|
+
(define (process-message sender command text)
|
|
121
|
+
(let ((username {} target {} message {}))
|
|
122
|
+
(set 'username (first (clean empty? (parse sender {!|:} 0))))
|
|
123
|
+
(set 'target (trim (first (clean empty? (parse text {!|:} 0)))))
|
|
124
|
+
(set 'message (slice text (+ (find {:} text) 1)))
|
|
125
|
+
(cond
|
|
126
|
+
((starts-with message "\001")
|
|
127
|
+
(process-ctcp username target message))
|
|
128
|
+
((find target Ichannels)
|
|
129
|
+
(cond
|
|
130
|
+
((= command {PRIVMSG})
|
|
131
|
+
(do-callbacks "channel-message" (list (list "channel" target) (list "username" username) (list "message" message))))
|
|
132
|
+
((= command {NOTICE})
|
|
133
|
+
(do-callbacks "channel-notice" (list (list "channel" target) (list "username" username) (list "message" message))))))
|
|
134
|
+
((= target Inickname)
|
|
135
|
+
(cond
|
|
136
|
+
((= command {PRIVMSG})
|
|
137
|
+
(do-callbacks "private-message" (list (list "username" username) (list "message" message))))
|
|
138
|
+
((= command {NOTICE})
|
|
139
|
+
(do-callbacks "private-notice" (list (list "username" username) (list "message" message))))))
|
|
140
|
+
(true
|
|
141
|
+
nil))))
|
|
142
|
+
|
|
143
|
+
(define (process-ctcp username target message)
|
|
144
|
+
(cond
|
|
145
|
+
((starts-with message "\001VERSION\001")
|
|
146
|
+
(net-send Iserver (format "NOTICE %s :\001VERSION %s\001\r\n" username version)))
|
|
147
|
+
((starts-with message "\001PING")
|
|
148
|
+
(set 'data (first (rest (clean empty? (parse message { } 0)))))
|
|
149
|
+
(set 'data (trim data "\001" "\001"))
|
|
150
|
+
(net-send Iserver (format "NOTICE %s :\001PING %s\001\r\n" username data)))
|
|
151
|
+
((starts-with message "\001ACTION")
|
|
152
|
+
(set 'data (first (rest (clean empty? (parse message { } 0)))))
|
|
153
|
+
(set 'data (join data { }))
|
|
154
|
+
(set 'data (trim data "\001" "\001"))
|
|
155
|
+
(if (find target Ichannels)
|
|
156
|
+
(do-callbacks "channel-action" (list (list "username" username) (list "message" message))))
|
|
157
|
+
(if (= target Inickname)
|
|
158
|
+
(do-callbacks "private-action" (list (list "username" username) (list "message" message)))))
|
|
159
|
+
((starts-with message "\001TIME\001")
|
|
160
|
+
(net-send Iserver (format "NOTICE %s:\001TIME :%s\001\r\n" username (date))))))
|
|
161
|
+
|
|
162
|
+
(define (parse-buffer raw-buffer)
|
|
163
|
+
(let ((messages (clean empty? (parse raw-buffer "\r\n" 0)))
|
|
164
|
+
(sender {} command {} text {}))
|
|
165
|
+
; check for elapsed time since last activity
|
|
166
|
+
(when (> (sub (time-of-day) Itime-stamp) (mul Idle-time 1000))
|
|
167
|
+
(do-callbacks "idle-event")
|
|
168
|
+
(set 'Itime-stamp (time-of-day)))
|
|
169
|
+
(dolist (message messages)
|
|
170
|
+
(set 'message-parts (parse message { }))
|
|
171
|
+
(unless (empty? message-parts)
|
|
172
|
+
(set 'sender (first message-parts))
|
|
173
|
+
(catch (set 'command (first (rest message-parts))) 'error)
|
|
174
|
+
(catch (set 'text (join (rest (rest message-parts)) { })) 'error))
|
|
175
|
+
(process-command sender command text))))
|
|
176
|
+
|
|
177
|
+
(define (read-irc)
|
|
178
|
+
(let ((buffer {}))
|
|
179
|
+
(when (!= (net-peek Iserver) 0)
|
|
180
|
+
(net-receive Iserver buffer 8192 "\n")
|
|
181
|
+
(unless (empty? buffer)
|
|
182
|
+
(parse-buffer buffer)))))
|
|
183
|
+
|
|
184
|
+
(define (read-irc-loop) ; monitoring
|
|
185
|
+
(let ((buffer {}))
|
|
186
|
+
(while Iconnected
|
|
187
|
+
(read-irc)
|
|
188
|
+
(sleep 1000))))
|
|
189
|
+
|
|
190
|
+
(define (print-raw-message data) ; example of using a callback
|
|
191
|
+
(set 'raw-data (lookup "message" data))
|
|
192
|
+
(set 'channel (lookup "channel" data))
|
|
193
|
+
(set 'message-text raw-data)
|
|
194
|
+
(println (date (date-value) 0 {%H:%M:%S }) username {> } message-text))
|
|
195
|
+
|
|
196
|
+
(define (print-outgoing-message data)
|
|
197
|
+
(set 'raw-data (lookup "message" data))
|
|
198
|
+
(set 'channel (lookup "channel" data))
|
|
199
|
+
(set 'message-text raw-data)
|
|
200
|
+
(println (date (date-value) 0 {%H:%M:%S }) Inickname {> } message-text))
|
|
201
|
+
|
|
202
|
+
(define (session); interactive terminal
|
|
203
|
+
; must add callbacks to display messages
|
|
204
|
+
(register-callback "channel-message" 'print-raw-message)
|
|
205
|
+
(register-callback "send-to-server" 'print-outgoing-message)
|
|
206
|
+
(while Iconnected
|
|
207
|
+
(while (zero? (peek 0))
|
|
208
|
+
(read-irc))
|
|
209
|
+
(send-to-server (string (read-line 0))))
|
|
210
|
+
(println {finished session } (date))
|
|
211
|
+
(exit))
|
|
212
|
+
|
|
213
|
+
; end of IRC code
|
|
214
|
+
|