pygments.rb 0.3.2 → 0.3.3
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/README.md +6 -1
- data/lexers +0 -0
- data/lib/pygments/version.rb +1 -1
- data/vendor/pygments-main/AUTHORS +15 -0
- data/vendor/pygments-main/CHANGES +28 -1
- data/vendor/pygments-main/LICENSE +1 -1
- data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +121 -0
- data/vendor/pygments-main/pygments/cmdline.py +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +0 -1
- data/vendor/pygments-main/pygments/formatters/_mapping.py +2 -2
- data/vendor/pygments-main/pygments/formatters/img.py +1 -1
- data/vendor/pygments-main/pygments/formatters/latex.py +8 -8
- data/vendor/pygments-main/pygments/formatters/other.py +0 -2
- data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +5413 -0
- data/vendor/pygments-main/pygments/lexers/_mapping.py +36 -11
- data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +551 -0
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +0 -1
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +546 -0
- data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +174 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +13 -3
- data/vendor/pygments-main/pygments/lexers/agile.py +145 -33
- data/vendor/pygments-main/pygments/lexers/asm.py +2 -2
- data/vendor/pygments-main/pygments/lexers/compiled.py +328 -36
- data/vendor/pygments-main/pygments/lexers/dalvik.py +104 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +8 -14
- data/vendor/pygments-main/pygments/lexers/functional.py +773 -8
- data/vendor/pygments-main/pygments/lexers/jvm.py +184 -36
- data/vendor/pygments-main/pygments/lexers/math.py +349 -23
- data/vendor/pygments-main/pygments/lexers/other.py +315 -492
- data/vendor/pygments-main/pygments/lexers/parsers.py +83 -1
- data/vendor/pygments-main/pygments/lexers/shell.py +4 -1
- data/vendor/pygments-main/pygments/lexers/templates.py +112 -2
- data/vendor/pygments-main/pygments/lexers/text.py +52 -3
- data/vendor/pygments-main/pygments/lexers/web.py +382 -36
- data/vendor/pygments-main/pygments/unistring.py +35 -25
- data/vendor/pygments-main/pygments/util.py +45 -0
- data/vendor/pygments-main/tests/examplefiles/Config.in.cache +1973 -0
- data/vendor/pygments-main/tests/examplefiles/example.Rd +78 -0
- data/vendor/pygments-main/tests/examplefiles/example.bug +54 -0
- data/vendor/pygments-main/tests/examplefiles/example.ceylon +33 -0
- data/vendor/pygments-main/tests/examplefiles/example.jag +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.monkey +152 -0
- data/vendor/pygments-main/tests/examplefiles/example.msc +43 -0
- data/vendor/pygments-main/tests/examplefiles/example.reg +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.rkt +95 -0
- data/vendor/pygments-main/tests/examplefiles/example.rpf +4 -0
- data/vendor/pygments-main/tests/examplefiles/example.stan +97 -0
- data/vendor/pygments-main/tests/examplefiles/example.xtend +34 -0
- data/vendor/pygments-main/tests/examplefiles/example2.msc +79 -0
- data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +123 -0
- data/vendor/pygments-main/tests/examplefiles/hello.smali +40 -0
- data/vendor/pygments-main/tests/examplefiles/hello.sp +9 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +2 -1
- data/vendor/pygments-main/tests/examplefiles/http_response_example +4 -2
- data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +71 -0
- data/vendor/pygments-main/tests/examplefiles/json.lasso +301 -0
- data/vendor/pygments-main/tests/examplefiles/json.lasso9 +213 -0
- data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +41 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_sample +5 -2
- data/vendor/pygments-main/tests/examplefiles/metagrammar.treetop +455 -0
- data/vendor/pygments-main/tests/examplefiles/pytb_test3.pytb +4 -0
- data/vendor/pygments-main/tests/examplefiles/robotframework.txt +39 -0
- data/vendor/pygments-main/tests/examplefiles/rust_example.rs +743 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +149 -115
- data/vendor/pygments-main/tests/examplefiles/test.cu +36 -0
- data/vendor/pygments-main/tests/test_basic_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +18 -0
- metadata +34 -3
- data/vendor/pygments-main/REVISION +0 -1
@@ -0,0 +1,97 @@
|
|
1
|
+
/*
|
2
|
+
A file for testing Stan syntax highlighting.
|
3
|
+
|
4
|
+
It is not a real model and will not compile
|
5
|
+
*/
|
6
|
+
# also a comment
|
7
|
+
// also a comment
|
8
|
+
data {
|
9
|
+
// valid name
|
10
|
+
int abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abc;
|
11
|
+
// all types should be highlighed
|
12
|
+
int a3;
|
13
|
+
real foo[2];
|
14
|
+
vector[3] bar;
|
15
|
+
row_vector[3] baz;
|
16
|
+
matrix[3,3] qux;
|
17
|
+
simplex[3] quux;
|
18
|
+
ordered[3] corge;
|
19
|
+
positive_ordered[3] wibble;
|
20
|
+
corr_matrix[3] grault;
|
21
|
+
cov_matrix[3] garply;
|
22
|
+
|
23
|
+
real<lower=-1,upper=1> foo1;
|
24
|
+
real<lower=0> foo2;
|
25
|
+
real<upper=0> foo3;
|
26
|
+
|
27
|
+
// bad names
|
28
|
+
// includes .
|
29
|
+
// real foo.;
|
30
|
+
// beings with number
|
31
|
+
//real 0foo;
|
32
|
+
// begins with _
|
33
|
+
//real _foo;
|
34
|
+
}
|
35
|
+
transformed data {
|
36
|
+
real xyzzy;
|
37
|
+
int thud;
|
38
|
+
row_vector grault2;
|
39
|
+
matrix qux2;
|
40
|
+
|
41
|
+
// all floating point literals should be recognized
|
42
|
+
// all operators should be recognized
|
43
|
+
// paren should be recognized;
|
44
|
+
xyzzy <- 1234.5687 + .123 - (2.7e3 / 2E-5 * 135e-5);
|
45
|
+
// integer literal
|
46
|
+
thud <- -12309865;
|
47
|
+
// ./ and .* should be recognized as operators
|
48
|
+
grault2 <- grault .* garply ./ garply;
|
49
|
+
// ' and \ should be regognized as operators
|
50
|
+
qux2 <- qux' \ bar;
|
51
|
+
|
52
|
+
}
|
53
|
+
parameters {
|
54
|
+
real fred;
|
55
|
+
real plugh;
|
56
|
+
|
57
|
+
}
|
58
|
+
transformed parameters {
|
59
|
+
}
|
60
|
+
model {
|
61
|
+
// ~, <- are operators,
|
62
|
+
// T may be be recognized
|
63
|
+
// normal is a function
|
64
|
+
fred ~ normal(0, 1) T(-0.5, 0.5);
|
65
|
+
// interior block
|
66
|
+
{
|
67
|
+
real tmp;
|
68
|
+
// for, in should be highlighted
|
69
|
+
for (i in 1:10) {
|
70
|
+
tmp <- tmp + 0.1;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
// lp__ should be highlighted
|
74
|
+
// normal_log as a function
|
75
|
+
lp__ <- lp__ + normal_log(plugh, 0, 1);
|
76
|
+
|
77
|
+
// print statement and string literal
|
78
|
+
print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~@#$%^&*`'-+={}[].,;: ");
|
79
|
+
print("Hello, world!");
|
80
|
+
print("");
|
81
|
+
|
82
|
+
}
|
83
|
+
generated quantities {
|
84
|
+
real bar1;
|
85
|
+
bar1 <- foo + 1;
|
86
|
+
}
|
87
|
+
|
88
|
+
## Baddness
|
89
|
+
//foo <- 2.0;
|
90
|
+
//foo ~ normal(0, 1);
|
91
|
+
//not_a_block {
|
92
|
+
//}
|
93
|
+
|
94
|
+
/*
|
95
|
+
what happens with this?
|
96
|
+
*/
|
97
|
+
// */
|
@@ -0,0 +1,34 @@
|
|
1
|
+
package beer
|
2
|
+
|
3
|
+
import static extension beer.BottleSupport.*
|
4
|
+
import org.junit.Test
|
5
|
+
|
6
|
+
class BottleSong {
|
7
|
+
|
8
|
+
@Test
|
9
|
+
def void singIt() {
|
10
|
+
println(singTheSong(99))
|
11
|
+
}
|
12
|
+
|
13
|
+
def singTheSong(int all) '''
|
14
|
+
�FOR i : all .. 1�
|
15
|
+
�i.Bottles� of beer on the wall, �i.bottles� of beer.
|
16
|
+
Take one down and pass it around, �(i - 1).bottles� of beer on the wall.
|
17
|
+
|
18
|
+
�ENDFOR�
|
19
|
+
No more bottles of beer on the wall, no more bottles of beer.
|
20
|
+
Go to the store and buy some more, �all.bottles� of beer on the wall.
|
21
|
+
'''
|
22
|
+
|
23
|
+
def private java.lang.String bottles(int i) {
|
24
|
+
switch i {
|
25
|
+
case 0 : 'no more bottles'
|
26
|
+
case 1 : 'one bottle'
|
27
|
+
default : '''�i� bottles'''
|
28
|
+
}.toString
|
29
|
+
}
|
30
|
+
|
31
|
+
def String Bottles(int i) {
|
32
|
+
bottles(i).toFirstUpper
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/mscgen -Tpng
|
2
|
+
#
|
3
|
+
# testinput2.msc : Sample msc input file with URLs
|
4
|
+
#
|
5
|
+
# This file is PUBLIC DOMAIN and may be freely reproduced, distributed,
|
6
|
+
# transmitted, used, modified, built upon, or otherwise exploited by
|
7
|
+
# anyone for any purpose, commercial or non-commercial, and in any way,
|
8
|
+
# including by methods that have not yet been invented or conceived.
|
9
|
+
#
|
10
|
+
# This file is provided "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
11
|
+
# EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
12
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
13
|
+
#
|
14
|
+
|
15
|
+
# Note: This is from mscgen-0.20
|
16
|
+
|
17
|
+
msc {
|
18
|
+
|
19
|
+
A,B;
|
20
|
+
|
21
|
+
--- [label="Start", ID="1"];
|
22
|
+
|
23
|
+
A->B [label="signal"];
|
24
|
+
A<-B [label="signal"];
|
25
|
+
|
26
|
+
|
27
|
+
A=>B [label="method"];
|
28
|
+
A<=B [label="method"];
|
29
|
+
|
30
|
+
A>>B [label="return"];
|
31
|
+
A<<B [label="return"];
|
32
|
+
|
33
|
+
A=>>B [label="call-back"];
|
34
|
+
A<<=B [label="call-back", URL="www.google.com"];
|
35
|
+
|
36
|
+
A x- B [label="loss"];
|
37
|
+
A -x B [label="loss"];
|
38
|
+
|
39
|
+
--- [label="Left arcs", ID="2", IDURL="www.google.co.uk"];
|
40
|
+
|
41
|
+
A->A [label="signal"];
|
42
|
+
A<-A [label="signal"];
|
43
|
+
|
44
|
+
|
45
|
+
A=>A [label="method"];
|
46
|
+
A<=A [label="method"];
|
47
|
+
|
48
|
+
A>>A [label="return"];
|
49
|
+
A<<A [label="return"];
|
50
|
+
|
51
|
+
A=>>A [label="call-back"];
|
52
|
+
A<<=A [label="call-back", URL="www.google.com", ID="3"];
|
53
|
+
|
54
|
+
A x- A [label="loss"];
|
55
|
+
A -x A [label="loss"];
|
56
|
+
|
57
|
+
--- [label="Right arcs"];
|
58
|
+
|
59
|
+
B->B [label="signal"];
|
60
|
+
B<-B [label="signal"];
|
61
|
+
|
62
|
+
|
63
|
+
B=>B [label="method"];
|
64
|
+
B<=B [label="method"];
|
65
|
+
|
66
|
+
B>>B [label="return"];
|
67
|
+
B<<B [label="return"];
|
68
|
+
|
69
|
+
B=>>B [label="call-back", ID="4"];
|
70
|
+
B<<=B [label="call-back", URL="www.google.com"];
|
71
|
+
|
72
|
+
B x- B [label="loss"];
|
73
|
+
B -x B [label="loss"];
|
74
|
+
|
75
|
+
--- [label="End of arcs", URL="www.google.com"];
|
76
|
+
|
77
|
+
|
78
|
+
... [label="Some time passes", URL="www.google.com"];
|
79
|
+
}
|
@@ -0,0 +1,123 @@
|
|
1
|
+
/* This is an example in the Koka Language of the Garcia-Wachs algorithm */
|
2
|
+
module garcia-wachs
|
3
|
+
|
4
|
+
public fun main()
|
5
|
+
{
|
6
|
+
test().print
|
7
|
+
}
|
8
|
+
|
9
|
+
//----------------------------------------------------
|
10
|
+
// Trees
|
11
|
+
//----------------------------------------------------
|
12
|
+
public type tree<a> {
|
13
|
+
con Leaf(value :a)
|
14
|
+
con Node(left :tree<a>, right :tree<a>)
|
15
|
+
}
|
16
|
+
|
17
|
+
fun show( t : tree<char> ) : string
|
18
|
+
{
|
19
|
+
match(t) {
|
20
|
+
Leaf(c) -> Core.show(c)
|
21
|
+
Node(l,r) -> "Node(" + show(l) + "," + show(r) + ")"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
//----------------------------------------------------
|
27
|
+
// Non empty lists
|
28
|
+
//----------------------------------------------------
|
29
|
+
public type list1<a> {
|
30
|
+
Cons1( head : a, tail : list<a> )
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
fun map( xs, f ) {
|
35
|
+
val Cons1(y,ys) = xs
|
36
|
+
return Cons1(f(y), Core.map(ys,f))
|
37
|
+
}
|
38
|
+
|
39
|
+
fun zip( xs :list1<a>, ys :list1<b> ) : list1<(a,b)> {
|
40
|
+
Cons1( (xs.head, ys.head), zip(xs.tail, ys.tail))
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
//----------------------------------------------------
|
46
|
+
// Phase 1
|
47
|
+
//----------------------------------------------------
|
48
|
+
|
49
|
+
fun insert( after : list<(tree<a>,int)>, t : (tree<a>,int), before : list<(tree<a>,int)> ) : div tree<a>
|
50
|
+
{
|
51
|
+
match(before) {
|
52
|
+
Nil -> extract( [], Cons1(t,after) )
|
53
|
+
Cons(x,xs) -> {
|
54
|
+
if (x.snd < t.snd) then return insert( Cons(x,after), t, xs )
|
55
|
+
match(xs) {
|
56
|
+
Nil -> extract( [], Cons1(x,Cons(t,after)) )
|
57
|
+
Cons(y,ys) -> extract( ys, Cons1(y,Cons(x,Cons(t,after))) )
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
fun extract( before : list<(tree<a>,int)>, after : list1<(tree<a>,int)> ) : div tree<a>
|
64
|
+
{
|
65
|
+
val Cons1((t1,w1) as x, xs ) = after
|
66
|
+
match(xs) {
|
67
|
+
Nil -> t1
|
68
|
+
Cons((t2,w2) as y, ys) -> match(ys) {
|
69
|
+
Nil -> insert( [], (Node(t1,t2), w1+w2), before )
|
70
|
+
Cons((_,w3),_zs) ->
|
71
|
+
if (w1 <= w3)
|
72
|
+
then insert(ys, (Node(t1,t2), w1+w2), before)
|
73
|
+
else extract(Cons(x,before), Cons1(y,ys))
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
fun balance( xs : list1<(tree<a>,int)> ) : div tree<a>
|
81
|
+
{
|
82
|
+
extract( [], xs )
|
83
|
+
}
|
84
|
+
|
85
|
+
fun mark( depth :int, t :tree<(a,ref<h,int>)> ) : <write<h>> ()
|
86
|
+
{
|
87
|
+
match(t) {
|
88
|
+
Leaf((_,d)) -> d := depth
|
89
|
+
Node(l,r) -> { mark(depth+1,l); mark(depth+1,r) }
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
fun build( depth :int, xs :list1<(a,ref<h,int>)> ) : <read<h>,div> (tree<a>,list<(a,ref<h,int>)>)
|
95
|
+
{
|
96
|
+
if (!xs.head.snd == depth) return (Leaf(xs.head.fst), xs.tail)
|
97
|
+
|
98
|
+
l = build(depth+1, xs)
|
99
|
+
match(l.snd) {
|
100
|
+
Nil -> (l.fst, Nil)
|
101
|
+
Cons(y,ys) -> {
|
102
|
+
r = build(depth+1, Cons1(y,ys))
|
103
|
+
(Node(l.fst,r.fst), r.snd)
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
public fun test() {
|
109
|
+
wlist = Cons1(('a',3), [('b',2),('c',1),('d',4),('e',5)])
|
110
|
+
tree = wlist.garciawachs()
|
111
|
+
tree.show()
|
112
|
+
}
|
113
|
+
|
114
|
+
public fun garciawachs( xs : list1<(a,int)> ) : div tree<a>
|
115
|
+
{
|
116
|
+
refs = xs.map(fst).map( fun(x) { (x, ref(0)) } )
|
117
|
+
wleafs = zip( refs.map(Leaf), xs.map(snd) )
|
118
|
+
|
119
|
+
tree = balance(wleafs)
|
120
|
+
mark(0,tree)
|
121
|
+
build(0,refs).fst
|
122
|
+
}
|
123
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# To Recreate:
|
2
|
+
#
|
3
|
+
# echo -e 'class hello {\n public static void main(String[] args) {\n
|
4
|
+
# System.out.println("hi");\n }\n}\n' > hello.java
|
5
|
+
# javac -target 1.4 -source 1.4 hello.java
|
6
|
+
# dx --dex --output=hello.dex hello.class
|
7
|
+
# baksmali hello.dex
|
8
|
+
# cat out/hello.smali
|
9
|
+
|
10
|
+
.class Lhello;
|
11
|
+
.super Ljava/lang/Object;
|
12
|
+
.source "hello.java"
|
13
|
+
|
14
|
+
|
15
|
+
# direct methods
|
16
|
+
.method constructor <init>()V
|
17
|
+
.registers 1
|
18
|
+
|
19
|
+
.prologue
|
20
|
+
.line 1
|
21
|
+
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
|
22
|
+
|
23
|
+
return-void
|
24
|
+
.end method
|
25
|
+
|
26
|
+
.method public static main([Ljava/lang/String;)V
|
27
|
+
.registers 3
|
28
|
+
.parameter
|
29
|
+
|
30
|
+
.prologue
|
31
|
+
.line 3
|
32
|
+
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
|
33
|
+
|
34
|
+
const-string v1, "hi"
|
35
|
+
|
36
|
+
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
|
37
|
+
|
38
|
+
.line 4
|
39
|
+
return-void
|
40
|
+
.end method
|
@@ -3,7 +3,8 @@ Host: pygments.org
|
|
3
3
|
Connection: keep-alivk
|
4
4
|
Cache-Control: max-age=0
|
5
5
|
Origin: http://pygments.org
|
6
|
-
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2)
|
6
|
+
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2)
|
7
|
+
AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
|
7
8
|
Content-Type: application/x-www-form-urlencoded
|
8
9
|
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
|
9
10
|
Referer: http://pygments.org/
|
@@ -18,8 +18,10 @@ Expires: Tue, 31 Mar 1981 05:00:00 GMT
|
|
18
18
|
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
|
19
19
|
X-MID: a55f21733bc52bb11d1fc58f9b51b4974fbb8f83
|
20
20
|
X-RateLimit-Reset: 1323738416
|
21
|
-
Set-Cookie: k=10.34.234.116.1323735104238974; path=/;
|
22
|
-
|
21
|
+
Set-Cookie: k=10.34.234.116.1323735104238974; path=/;
|
22
|
+
expires=Tue, 20-Dec-11 00:11:44 GMT; domain=.twitter.com
|
23
|
+
Set-Cookie: guest_id=v1%3A13237351042425496; domain=.twitter.com; path=/;
|
24
|
+
expires=Thu, 12-Dec-2013 12:11:44 GMT
|
23
25
|
Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCPS6wjQ0AToHaWQiJTFiMTlhY2E1ZjczYThk%250ANDUwMWQxNjMwZGU2YTQ1ODBhIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--6b502f30a083e8a41a64f10930e142ea362b1561; domain=.twitter.com; path=/; HttpOnly
|
24
26
|
Vary: Accept-Encoding
|
25
27
|
Server: tfe
|
@@ -0,0 +1,71 @@
|
|
1
|
+
re = import!
|
2
|
+
sys = import!
|
3
|
+
|
4
|
+
|
5
|
+
# IPv6address = hexpart [ ":" IPv4address ]
|
6
|
+
# IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
|
7
|
+
# hexpart = [ hexseq ] [ "::" [ hexseq ] ]
|
8
|
+
# hexseq = hex4 *( ":" hex4)
|
9
|
+
# hex4 = 1*4HEXDIG
|
10
|
+
hexpart = r'({0}|)(?:::({0}|)|)'.format r'(?:[\da-f]{1,4})(?::[\da-f]{1,4})*'
|
11
|
+
addrv4 = r'(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})'
|
12
|
+
addrv6 = re.compile $ r'(?i)(?:{})(?::{})?$'.format hexpart addrv4
|
13
|
+
|
14
|
+
|
15
|
+
# Parse a base-N number given a list of its digits.
|
16
|
+
#
|
17
|
+
# :param q: the number of digits in that numeral system
|
18
|
+
#
|
19
|
+
# :param digits: an iterable of integers in range [0..q]
|
20
|
+
#
|
21
|
+
# :return: a decimal integer
|
22
|
+
#
|
23
|
+
base_n = (q digits) -> foldl (x y) -> (x * q + y) 0 digits
|
24
|
+
|
25
|
+
|
26
|
+
# Parse a sequence of hexadecimal numbers
|
27
|
+
#
|
28
|
+
# :param q: a string of colon-separated base-16 integers
|
29
|
+
#
|
30
|
+
# :return: an iterable of Python ints
|
31
|
+
#
|
32
|
+
unhex = q -> q and map p -> (int p 16) (q.split ':')
|
33
|
+
|
34
|
+
|
35
|
+
# Parse an IPv6 address as specified in RFC 4291.
|
36
|
+
#
|
37
|
+
# :param address: a string, obviously.
|
38
|
+
#
|
39
|
+
# :return: an integer which, written in binary form, points to the same node.
|
40
|
+
#
|
41
|
+
inet_pton6 = address ->
|
42
|
+
raise $ ValueError 'not a valid IPv6 address' unless match = addrv6.match address
|
43
|
+
start, end, *ipv4 = match.groups!
|
44
|
+
|
45
|
+
is_ipv4 = not $ None in ipv4
|
46
|
+
shift = (7 - start.count ':' - 2 * is_ipv4) * 16
|
47
|
+
|
48
|
+
raise $ ValueError 'not a valid IPv6 address' if (end is None and shift) or shift < 0
|
49
|
+
hexaddr = (base_n 0x10000 (unhex start) << shift) + base_n 0x10000 (unhex $ end or '')
|
50
|
+
hexaddr unless is_ipv4 else (hexaddr << 32) + base_n 0x100 (map int ipv4)
|
51
|
+
|
52
|
+
|
53
|
+
inet6_type = q -> switch
|
54
|
+
not q = 'unspecified'
|
55
|
+
q == 1 = 'loopback'
|
56
|
+
(q >> 32) == 0x000000000000ffff = 'IPv4-mapped'
|
57
|
+
(q >> 64) == 0xfe80000000000000 = 'link-local'
|
58
|
+
(q >> 120) != 0x00000000000000ff = 'general unicast'
|
59
|
+
(q >> 112) % (1 << 4) == 0x0000000000000000 = 'multicast w/ reserved scope value'
|
60
|
+
(q >> 112) % (1 << 4) == 0x000000000000000f = 'multicast w/ reserved scope value'
|
61
|
+
(q >> 112) % (1 << 4) == 0x0000000000000001 = 'interface-local multicast'
|
62
|
+
(q >> 112) % (1 << 4) == 0x0000000000000004 = 'admin-local multicast'
|
63
|
+
(q >> 112) % (1 << 4) == 0x0000000000000005 = 'site-local multicast'
|
64
|
+
(q >> 112) % (1 << 4) == 0x0000000000000008 = 'organization-local multicast'
|
65
|
+
(q >> 112) % (1 << 4) == 0x000000000000000e = 'global multicast'
|
66
|
+
(q >> 112) % (1 << 4) != 0x0000000000000002 = 'multicast w/ unknown scope value'
|
67
|
+
(q >> 24) % (1 << 112) == 0x00000000000001ff = 'solicited-node multicast'
|
68
|
+
True = 'link-local multicast'
|
69
|
+
|
70
|
+
|
71
|
+
print $ (x -> (inet6_type x, hex x)) $ inet_pton6 $ sys.stdin.read!.strip!
|