Skip to content

Commit 1dc70fb

Browse files
committed
Merge pull request #9 from roman-d-boiko/master
Implemented EoF handling and partially fixed lexing numbers
2 parents fdcf5fe + e528248 commit 1dc70fb

File tree

2 files changed

+132
-63
lines changed

2 files changed

+132
-63
lines changed

codegen.d

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ string printCaseStatements(K, V)(TrieNode!(K,V) node, string indentString)
6060
if (v.children.length > 0)
6161
{
6262
caseStatement ~= indentString;
63-
caseStatement ~= "\tif (endIndex >= inputString.length)\n";
63+
caseStatement ~= "\tif (isEoF(inputString, endIndex))\n";
6464
caseStatement ~= indentString;
6565
caseStatement ~= "\t{\n";
6666
caseStatement ~= indentString;
@@ -110,3 +110,28 @@ string generateCaseTrie(string[] args ...)
110110
}
111111
return printCaseStatements(t, "");
112112
}
113+
114+
/**
115+
* Returns: true if index points to end of inputString, false otherwise
116+
*/
117+
pure nothrow bool isEoF(S)(S inputString, size_t index)
118+
{
119+
// note: EoF is determined according to D specification
120+
return index >= inputString.length
121+
|| inputString[index] == Character.NUL
122+
|| inputString[index] == Character.SUB;
123+
}
124+
125+
private:
126+
127+
// Unicode character literals
128+
enum Character
129+
{
130+
// End of file (EoF)
131+
NUL = '\u0000', // NUL character
132+
SUB = '\u001A', // Substitute character
133+
134+
// Line feed (EoL)
135+
CR = '\u000D', // CR character
136+
LF = '\u000A', // LF character
137+
}

0 commit comments

Comments
 (0)