-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathfuzzy.html
executable file
·83 lines (76 loc) · 2.53 KB
/
fuzzy.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Antlr-Javascript:Examples/fuzzy</title>
<!-- ANTLR includes -->
<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
<script type="text/javascript" src="FuzzyJava.js"></script>
<!-- Test Code -->
<script type="text/javascript">
var sourceText = [
"import org.antlr.runtime.*;",
"",
"public class Main {",
" public static void main(String[] args) throws Exception {",
" for (int i=0; i<args.length; i++) {",
" CharStream input = new ANTLRFileStream(args[i]);",
" FuzzyJava lex = new FuzzyJava(input);",
" TokenStream tokens = new CommonTokenStream(lex);",
" tokens.toString();",
" //System.out.println(tokens);",
" }",
" }",
"}"].join("\n");
FuzzyJava.prototype.emitErrorMessage = function(msg) {print(msg);}
function parse(text) {
text = text.replace(/\r\n?/g,"\n");
var input = new org.antlr.runtime.ANTLRStringStream(text);
var lexer = new FuzzyJava(input);
var tokens = new org.antlr.runtime.CommonTokenStream(lexer);
print(tokens.toString());
}
var print = (function () {
var outputBox;
return function(text) {
text = text.replace(/[^\r]\n/g, "\r\n");
if(!outputBox) outputBox = document.getElementById("outputBox");
if(typeof text == "string") {
outputBox.appendChild(document.createTextNode(text + "\r\n"));
} else {
for(var i=0;i<text.length;i++) {
outputBox.appendChild(document.createTextNode(text[i] + "\r\n"));
}
}
};
})();
function onLoad() {
if(!this.inputElement) this.inputElement = document.getElementById("inputBox");
inputElement.value = sourceText;
}
</script>
<style type="text/css">
#outputBox {
font-family:monospace;
font-size:12px;
white-space: pre;
overflow:scroll;
border: thin solid lightGrey;
height: 300px;
width:750px;
}
</style>
</head>
<body onload="onLoad();">
<h1>Fuzzy</h1>
<div style="float:left"> <p style="font-size:8pt;">(All CR/LF's will be converted to "\n")</p>
<textarea id="inputBox" cols="90" rows="10"></textarea><br/>
<input type="button" onclick="parse(inputElement.value);" value="Parse"/><br/>
<p>Output/Error:</p>
<div id="outputBox"></div>
</div>
<div style="float:right">
</div>
</body>
</html>