Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
<!doctype html>
2
<title>CodeMirror: VB.NET mode</title>
3
<meta charset="utf-8" />
4
<link rel=stylesheet href="../../doc/docs.css">
5
<link rel="stylesheet" href="../../lib/codemirror.css">
6
<link href="http://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css">
7
<script src="../../lib/codemirror.js"></script>
8
<script src="vb.js"></script>
9
<script type="text/javascript" src="../../addon/runmode/runmode.js"></script>
10
<style>
11
    .CodeMirror {
12
        border: 1px solid #aaa;
13
        height: 210px;
14
        height: auto;
15
    }
16
 
17
    .CodeMirror-scroll {
18
        overflow-x: auto;
19
        overflow-y: hidden;
20
    }
21
 
22
    .CodeMirror pre {
23
        font-family: Inconsolata;
24
        font-size: 14px
25
    }
26
</style>
27
<div id=nav>
28
    <a href="http://codemirror.net">
29
        <h1>CodeMirror</h1>
30
        <img id=logo src="../../doc/logo.png">
31
    </a>
32
    <ul>
33
        <li>
34
            <a href="../../index.html">Home</a>
35
            <li>
36
                <a href="../../doc/manual.html">Manual</a>
37
                <li>
38
                    <a href="https://github.com/codemirror/codemirror">Code</a>
39
    </ul>
40
    <ul>
41
        <li>
42
            <a href="../index.html">Language modes</a>
43
            <li>
44
                <a class=active href="#">VB.NET</a>
45
    </ul>
46
</div>
47
<article>
48
    <h2>VB.NET mode</h2>
49
    <script type="text/javascript">
50
        function test(golden, text)
51
        {
52
            var ok = true;
53
            var i = 0;
54
 
55
            function callback(token, style, lineNo, pos)
56
            {
57
                //console.log(String(token) + " " + String(style) + " " + String(lineNo) + " " + String(pos));
58
                var result = [String(token), String(style)];
59
                if (golden[i][0] != result[0] || golden[i][1] != result[1])
60
                {
61
                    return "Error, expected: " + String(golden[i]) + ", got: " + String(result);
62
                    ok = false;
63
                }
64
                i++;
65
            }
66
            CodeMirror.runMode(text, "text/x-vb", callback);
67
            if (ok) return "Tests OK";
68
        }
69
 
70
        function testTypes()
71
        {
72
            var golden = [
73
                ['Integer', 'keyword'],
74
                [' ', 'null'],
75
                ['Float', 'keyword']
76
            ]
77
            var text = "Integer Float";
78
            return test(golden, text);
79
        }
80
 
81
        function testIf()
82
        {
83
            var golden = [
84
                ['If', 'keyword'],
85
                [' ', 'null'],
86
                ['True', 'keyword'],
87
                [' ', 'null'],
88
                ['End', 'keyword'],
89
                [' ', 'null'],
90
                ['If', 'keyword']
91
            ];
92
            var text = 'If True End If';
93
            return test(golden, text);
94
        }
95
 
96
        function testDecl()
97
        {
98
            var golden = [
99
                ['Dim', 'keyword'],
100
                [' ', 'null'],
101
                ['x', 'variable'],
102
                [' ', 'null'],
103
                ['as', 'keyword'],
104
                [' ', 'null'],
105
                ['Integer', 'keyword']
106
            ];
107
            var text = 'Dim x as Integer';
108
            return test(golden, text);
109
        }
110
 
111
        function testAll()
112
        {
113
            var result = "";
114
            result += testTypes() + "\n";
115
            result += testIf() + "\n";
116
            result += testDecl() + "\n";
117
            return result;
118
        }
119
 
120
        function initText(editor)
121
        {
122
            var content = 'Class rocket\nPrivate quality as Double\nPublic Sub launch() as String\nif quality > 0.8\nlaunch = "Successful"\nElse\nlaunch = "Failed"\nEnd If\nEnd sub\nEnd class\n';
123
            editor.setValue(content);
124
            for (var i = 0; i < editor.lineCount(); i++) editor.indentLine(i);
125
        }
126
 
127
        function init()
128
        {
129
            editor = CodeMirror.fromTextArea(document.getElementById("solution"),
130
            {
131
                lineNumbers: true,
132
                mode: "text/x-vb",
133
                readOnly: false
134
            });
135
            runTest();
136
        }
137
 
138
        function runTest()
139
        {
140
            document.getElementById('testresult').innerHTML = testAll();
141
            initText(editor);
142
        }
143
        document.body.onload = init;
144
    </script>
145
    <div id="edit">
146
        <textarea style="width:95%;height:200px;padding:5px;" name="solution" id="solution"></textarea>
147
    </div> <pre id="testresult"></pre>
148
    <p>MIME type defined: <code>text/x-vb</code>.</p>
149
</article>