# HG changeset patch # User Aziz K?ksal # Date 1201895504 -3600 # Node ID 5dd17d4568ce5e6f70effb4bde0a955be1e79d24 # Parent ceaac6a24258baa815e419d5d35eab20387b1706 Wrote code for expandMacros(). diff -r ceaac6a24258 -r 5dd17d4568ce trunk/src/dil/doc/Macro.d --- a/trunk/src/dil/doc/Macro.d Fri Feb 01 19:44:00 2008 +0100 +++ b/trunk/src/dil/doc/Macro.d Fri Feb 01 20:51:44 2008 +0100 @@ -48,12 +48,6 @@ { return parent is null; } } -void skipWhitespace(ref char* p) -{ - while (isspace(*p) || *p == '\n') - p++; -} - struct MacroParser { char* p; @@ -90,9 +84,9 @@ bool findNextMacroId(ref char* ref_idBegin, ref char* ref_idEnd, ref char* ref_bodyBegin) { - while (*p != '\0') + while (p < textEnd) { - skipWhitespace(p); + skipWhitespace(); auto idBegin = p; if (isidbeg(*p) || isUnicodeAlpha(p, textEnd)) // IdStart { @@ -101,12 +95,14 @@ while (isident(*p) || isUnicodeAlpha(p, textEnd)) auto idEnd = p; - skipWhitespace(p); + skipWhitespace(); if (*p == '=') { + p++; + skipWhitespace(); ref_idBegin = idBegin; ref_idEnd = idEnd; - ref_bodyBegin = p + 1; + ref_bodyBegin = p; return true; } } @@ -115,9 +111,15 @@ return false; } + void skipWhitespace() + { + while (p < textEnd && (isspace(*p) || *p == '\n')) + p++; + } + void skipLine() { - while (*p != '\n') + while (p < textEnd && *p != '\n') p++; p++; } @@ -133,10 +135,35 @@ char[] result; char* p = text.ptr; char* textEnd = p + text.length; -// while (p < text.length) -// { - -// } + char* macroEnd = p; + while (p+3 < textEnd) // minimum 4 chars: $(x) + { + if (*p == '$' && p[1] == '(') + { + // Copy string between macros. + result ~= makeString(macroEnd, p); + p += 2; + auto idBegin = p; + if (isidbeg(*p) || isUnicodeAlpha(p, textEnd)) // IdStart + { + do // IdChar* + p++; + while (p < textEnd && (isident(*p) || isUnicodeAlpha(p, textEnd))) + auto macroName = makeString(idBegin, p); + if (*p == ')') + { + p++; + macroEnd = p; + } + auto macro_ = table.search(macroName); + if (macro_) + { + result ~= macro_.text; + } + } + } + p++; + } return result; }