Mercurial > projects > dil
annotate trunk/src/main.d @ 69:24db7c5522d5
- Added module Information for compiler messages like warnings, info and errors to the user.
- Renamed class Problem to Information.
author | aziz |
---|---|
date | Sun, 01 Jul 2007 13:53:00 +0000 |
parents | 8e84db78ad55 |
children | fc645fb2fe72 |
rev | line source |
---|---|
0 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL2 | |
4 +/ | |
5 module dparser; | |
69
24db7c5522d5
- Added module Information for compiler messages like warnings, info and errors to the user.
aziz
parents:
66
diff
changeset
|
6 import Parser; |
3 | 7 import Lexer; |
8 import Token; | |
54 | 9 import Messages; |
3 | 10 import std.stdio; |
4 | 11 import std.file; |
0 | 12 |
5 | 13 char[] xmlescape(char[] text) |
14 { | |
15 char[] result; | |
16 foreach(c; text) | |
17 switch(c) | |
18 { | |
19 case '<': result ~= "<"; break; | |
20 case '>': result ~= ">"; break; | |
21 case '&': result ~= "&"; break; | |
22 default: result ~= c; | |
23 } | |
24 return result; | |
25 } | |
26 | |
0 | 27 void main(char[][] args) |
28 { | |
4 | 29 auto srctext = cast(char[]) std.file.read(args[1]); |
30 | 30 auto lx = new Lexer(srctext, args[1]); |
0 | 31 |
5 | 32 auto tokens = lx.getTokens(); |
33 char* end = lx.text.ptr; | |
34 | |
35 writef(`<?xml version="1.0"?> | |
36 <?xml-stylesheet href="format.css" type="text/css"?> | |
51 | 37 <root> |
38 <compilerinfo>`\n); | |
39 foreach (error; lx.errors) | |
40 { | |
66
8e84db78ad55
- Added support for variadic arguments in error messages.
aziz
parents:
65
diff
changeset
|
41 writefln(`<error t="%s">%s(%d): %s</error>`, "l", lx.fileName, error.loc, error.getMsg); |
51 | 42 } |
43 writef(`</compilerinfo> | |
5 | 44 <sourcetext>`); |
51 | 45 foreach (ref token; tokens) |
4 | 46 { |
5 | 47 if (end != token.start) |
48 writef("%s", xmlescape(end[0 .. token.start - end])); | |
65 | 49 string srcText = xmlescape(token.srcText); |
5 | 50 switch(token.type) |
51 { | |
52 case TOK.Identifier: | |
65 | 53 writef("<i>%s</i>", srcText); |
5 | 54 break; |
55 case TOK.Comment: | |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
56 string c; |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
57 switch (token.start[1]) |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
58 { |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
59 case '/': c = "lc"; break; |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
60 case '*': c = "bc"; break; |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
61 case '+': c = "nc"; break; |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
62 } |
65 | 63 writef(`<c c="%s">%s</c>`, c, srcText); |
5 | 64 break; |
9
5d6968cc751e
- Parsing string and character literals now (rudimentary implementation.)
aziz
parents:
5
diff
changeset
|
65 case TOK.String: |
65 | 66 writef("<sl>%s</sl>", srcText); |
9
5d6968cc751e
- Parsing string and character literals now (rudimentary implementation.)
aziz
parents:
5
diff
changeset
|
67 break; |
5d6968cc751e
- Parsing string and character literals now (rudimentary implementation.)
aziz
parents:
5
diff
changeset
|
68 case TOK.Character: |
65 | 69 writef("<cl>%s</cl>", srcText); |
9
5d6968cc751e
- Parsing string and character literals now (rudimentary implementation.)
aziz
parents:
5
diff
changeset
|
70 break; |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
71 case TOK.Assign, TOK.Equal, |
39
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
72 TOK.Less, TOK.Greater, |
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
73 TOK.LShiftAssign, TOK.LShift, |
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
74 TOK.RShiftAssign, TOK.RShift, |
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
75 TOK.URShiftAssign, TOK.URShift, |
33 | 76 TOK.OrAssign, TOK.OrBinary, |
77 TOK.AndAssign, TOK.AndBinary, | |
78 TOK.PlusAssign, TOK.PlusPlus, TOK.Plus, | |
79 TOK.MinusAssign, TOK.MinusMinus, TOK.Minus, | |
80 TOK.DivAssign, TOK.Div, | |
81 TOK.MulAssign, TOK.Mul, | |
82 TOK.ModAssign, TOK.Mod, | |
83 TOK.XorAssign, TOK.Xor, | |
35
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
84 TOK.CatAssign, TOK.Catenate, |
39
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
85 TOK.Tilde, |
35
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
86 TOK.Unordered, |
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
87 TOK.UorE, |
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
88 TOK.UorG, |
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
89 TOK.UorGorE, |
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
90 TOK.UorL, |
39
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
91 TOK.UorLorE, |
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
92 TOK.LorEorG: |
65 | 93 writef("<op>%s</op>", srcText); |
14 | 94 break; |
39
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
95 case TOK.LorG: |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
96 writef(`<op c="lg"><></op>`); |
39
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
97 break; |
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
98 case TOK.LessEqual: |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
99 writef(`<op c="le"><=</op>`); |
39
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
100 break; |
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
101 case TOK.GreaterEqual: |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
102 writef(`<op c="ge">>=</op>`); |
39
69b940398d7b
- Added unittest to test correct parsing of operator tokens.
aziz
parents:
35
diff
changeset
|
103 break; |
31
94f09f4e988e
- Added struct for strings to Token with 'pf' = postfix.
aziz
parents:
30
diff
changeset
|
104 case TOK.AndLogical: |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
105 writef(`<op c="aa">&&</op>`); |
31
94f09f4e988e
- Added struct for strings to Token with 'pf' = postfix.
aziz
parents:
30
diff
changeset
|
106 break; |
94f09f4e988e
- Added struct for strings to Token with 'pf' = postfix.
aziz
parents:
30
diff
changeset
|
107 case TOK.OrLogical: |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
108 writef(`<op c="oo">||</op>`); |
31
94f09f4e988e
- Added struct for strings to Token with 'pf' = postfix.
aziz
parents:
30
diff
changeset
|
109 break; |
35
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
110 case TOK.NotEqual: |
44
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
111 writef(`<op c="ne">!=</op>`); |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
112 break; |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
113 case TOK.Not: |
5055947e0f98
- Specific operators and comments can be formatted with CSS now.
aziz
parents:
39
diff
changeset
|
114 writef(`<op c="n">!</op>`); |
35
c470b9356e35
- Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents:
33
diff
changeset
|
115 break; |
62
96af5653acef
- Fixed loop of hex number scanner. Moved checks under the switch block.
aziz
parents:
58
diff
changeset
|
116 case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64, |
96af5653acef
- Fixed loop of hex number scanner. Moved checks under the switch block.
aziz
parents:
58
diff
changeset
|
117 TOK.Float32, TOK.Float64, TOK.Float80, |
96af5653acef
- Fixed loop of hex number scanner. Moved checks under the switch block.
aziz
parents:
58
diff
changeset
|
118 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80: |
65 | 119 writef("<n>%s</n>", srcText); |
15 | 120 break; |
20 | 121 case TOK.LParen, TOK.RParen, TOK.LBracket, |
122 TOK.RBracket, TOK.LBrace, TOK.RBrace: | |
65 | 123 writef("<br>%s</br>", srcText); |
20 | 124 break; |
22
b05fff8e2ce4
- Added code for parsing Dot, Slice and Ellipses tokens.
aziz
parents:
21
diff
changeset
|
125 case TOK.EOF: break; |
5 | 126 default: |
28 | 127 if (token.isKeyword()) |
65 | 128 writef("<k>%s</k>", srcText); |
28 | 129 else |
65 | 130 writef("%s", srcText); |
5 | 131 } |
132 end = token.end; | |
4 | 133 } |
51 | 134 writef("\n</sourcetext>\n</root>"); |
0 | 135 } |