Mercurial > projects > dil
changeset 315:29c33ce6c5bb
- Added method scanShebang to class Lexer.
- TOK.Shebang is recognized by the token highlighter.
author | aziz |
---|---|
date | Wed, 15 Aug 2007 20:33:02 +0000 |
parents | ebd21bbf296e |
children | c23a24cc2021 |
files | trunk/src/Lexer.d trunk/src/format.css trunk/src/main.d |
diffstat | 3 files changed, 51 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Lexer.d Wed Aug 15 19:57:01 2007 +0000 +++ b/trunk/src/Lexer.d Wed Aug 15 20:33:02 2007 +0000 @@ -60,6 +60,50 @@ this.head = new Token; this.head.type = TOK.HEAD; this.token = this.head; + scanShebang(); + } + + void scanShebang() + { + if (*p == '#' && p[1] == '!') + { + Token* t = new Token; + t.start = p; + t.type = TOK.Shebang; + ++p; + while (1) + { + switch (*++p) + { + case '\r': + if (p[1] == '\n') + ++p; + case '\n': + ++loc; + if (p[-1] == '\r') + t.end = p-1; + else + t.end = p; + break; + case LS[0]: + t.end = p; + if (p[1] == LS[1] && (p[2] == LS[2] || p[2] == PS[2])) + { + ++p; ++p; + ++loc; + } + break; + case 0, _Z_: + t.end = p; + break; + default: + continue; + } + break; // Exit loop. + } + this.head.next = t; + t.prev = this.head; + } } public void scan(out Token t)
--- a/trunk/src/format.css Wed Aug 15 19:57:01 2007 +0000 +++ b/trunk/src/format.css Wed Aug 15 20:33:02 2007 +0000 @@ -32,6 +32,8 @@ br { color: orange; } /* Special tokens */ st { color: green; font-weight: bold; } +/* When the first line starts with #! it's a "shebang" */ +shebang { color: gray; } /* Particular operators */ op[c=aa] { content: "and"; } /*&& ∧*/ op[c=oo] { content: "or"; } /*|| ∨*/
--- a/trunk/src/main.d Wed Aug 15 19:57:01 2007 +0000 +++ b/trunk/src/main.d Wed Aug 15 20:33:02 2007 +0000 @@ -79,8 +79,8 @@ auto token = lx.getTokens(); char* end = lx.text.ptr; - writef(`<?xml version="1.0"?>` - `<?xml-stylesheet href="format.css" type="text/css"?>` + writefln(`<?xml version="1.0"?>`\n + `<?xml-stylesheet href="format.css" type="text/css"?>`\n `<root>`); if (lx.errors.length) { @@ -188,6 +188,9 @@ case TOK.Special: writef("<st>%s</st>", srcText); break; + case TOK.Shebang: + writef("<shebang>%s</shebang>", srcText); + break; default: if (token.isKeyword()) writef("<k>%s</k>", srcText);