index.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 {border: 1px solid #aaa; height:210px; height: auto;}
  12. .CodeMirror-scroll { overflow-x: auto; overflow-y: hidden;}
  13. .CodeMirror pre { font-family: Inconsolata; font-size: 14px}
  14. </style>
  15. <div id=nav>
  16. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  17. <ul>
  18. <li><a href="../../index.html">Home</a>
  19. <li><a href="../../doc/manual.html">Manual</a>
  20. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  21. </ul>
  22. <ul>
  23. <li><a href="../index.html">Language modes</a>
  24. <li><a class=active href="#">VB.NET</a>
  25. </ul>
  26. </div>
  27. <article>
  28. <h2>VB.NET mode</h2>
  29. <script type="text/javascript">
  30. function test(golden, text) {
  31. var ok = true;
  32. var i = 0;
  33. function callback(token, style, lineNo, pos){
  34. //console.log(String(token) + " " + String(style) + " " + String(lineNo) + " " + String(pos));
  35. var result = [String(token), String(style)];
  36. if (golden[i][0] != result[0] || golden[i][1] != result[1]){
  37. return "Error, expected: " + String(golden[i]) + ", got: " + String(result);
  38. ok = false;
  39. }
  40. i++;
  41. }
  42. CodeMirror.runMode(text, "text/x-vb",callback);
  43. if (ok) return "Tests OK";
  44. }
  45. function testTypes() {
  46. var golden = [['Integer','keyword'],[' ','null'],['Float','keyword']]
  47. var text = "Integer Float";
  48. return test(golden,text);
  49. }
  50. function testIf(){
  51. var golden = [['If','keyword'],[' ','null'],['True','keyword'],[' ','null'],['End','keyword'],[' ','null'],['If','keyword']];
  52. var text = 'If True End If';
  53. return test(golden, text);
  54. }
  55. function testDecl(){
  56. var golden = [['Dim','keyword'],[' ','null'],['x','variable'],[' ','null'],['as','keyword'],[' ','null'],['Integer','keyword']];
  57. var text = 'Dim x as Integer';
  58. return test(golden, text);
  59. }
  60. function testAll(){
  61. var result = "";
  62. result += testTypes() + "\n";
  63. result += testIf() + "\n";
  64. result += testDecl() + "\n";
  65. return result;
  66. }
  67. function initText(editor) {
  68. 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';
  69. editor.setValue(content);
  70. for (var i =0; i< editor.lineCount(); i++) editor.indentLine(i);
  71. }
  72. function init() {
  73. editor = CodeMirror.fromTextArea(document.getElementById("solution"), {
  74. lineNumbers: true,
  75. mode: "text/x-vb",
  76. readOnly: false
  77. });
  78. runTest();
  79. }
  80. function runTest() {
  81. document.getElementById('testresult').innerHTML = testAll();
  82. initText(editor);
  83. }
  84. document.body.onload = init;
  85. </script>
  86. <div id="edit">
  87. <textarea style="width:95%;height:200px;padding:5px;" name="solution" id="solution" ></textarea>
  88. </div>
  89. <pre id="testresult"></pre>
  90. <p>MIME type defined: <code>text/x-vb</code>.</p>
  91. </article>