comparison trunk/src/dil/Lexer.d @ 494:9a7ca8c56e59

Refactored a few things in the Parser. Removed unnecessary 'bool hasBody' parameter from some declarations. Added shebang to list of tokens in Lexer unittest. Added some semantic methods.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 07 Dec 2007 18:22:35 +0100
parents 47be6bfe39cd
children 5a607597dc22
comparison
equal deleted inserted replaced
493:d13502b6fa5f 494:9a7ca8c56e59
2681 { 2681 {
2682 char[] tokenText; 2682 char[] tokenText;
2683 TOK type; 2683 TOK type;
2684 } 2684 }
2685 static Pair[] pairs = [ 2685 static Pair[] pairs = [
2686 {"#!äöüß", TOK.Shebang}, {"\n", TOK.Newline},
2686 {"//çay", TOK.Comment}, {"\n", TOK.Newline}, 2687 {"//çay", TOK.Comment}, {"\n", TOK.Newline},
2687 {"&", TOK.AndBinary}, 2688 {"&", TOK.AndBinary},
2688 {"/*çağ*/", TOK.Comment}, {"&&", TOK.AndLogical}, 2689 {"/*çağ*/", TOK.Comment}, {"&&", TOK.AndLogical},
2689 {"/+çak+/", TOK.Comment}, {"&=", TOK.AndAssign}, 2690 {"/+çak+/", TOK.Comment}, {"&=", TOK.AndAssign},
2690 {">", TOK.Greater}, {"+", TOK.Plus}, 2691 {">", TOK.Greater}, {"+", TOK.Plus},
2723 2724
2724 char[] src; 2725 char[] src;
2725 2726
2726 // Join all token texts into a single string. 2727 // Join all token texts into a single string.
2727 foreach (i, pair; pairs) 2728 foreach (i, pair; pairs)
2728 if (pair.type == TOK.Comment && pair.tokenText[1] == '/') // Line comment. 2729 if (pair.type == TOK.Comment && pair.tokenText[1] == '/' || // Line comment.
2730 pair.type == TOK.Shebang)
2729 { 2731 {
2730 assert(pairs[i+1].type == TOK.Newline); // Must be followed by a newline. 2732 assert(pairs[i+1].type == TOK.Newline); // Must be followed by a newline.
2731 src ~= pair.tokenText; 2733 src ~= pair.tokenText;
2732 } 2734 }
2733 else 2735 else