Skip to content

Commit

Permalink
Manually inline whitespace checks in the parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibara committed May 29, 2021
1 parent 3d85acd commit a0a6f22
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,6 @@ private void fileWrite(string outfile) {
private void parse(string line) {
size_t i = 0;

/* Answers the question: Do we have more to process after whitespace? */
bool whitespace()
{
while (i < line.length && (line[i] == ' ' || line[i] == '\t' ||
line[i] == ';')) {
if (line[i] == ';') {
comm = line[i..$];
return false;
}

i++;
}

if (i == line.length)
return false;

return true;
}

/* Is this the end of the token? */
bool endoftoken()
{
Expand All @@ -148,6 +129,7 @@ private void parse(string line) {
if (line.length == 0)
return;

/* Get label. */
if (line[i] != ' ' && line[i] != '\t') {
size_t labend;
for (; i < line.length; i++) {
Expand All @@ -164,9 +146,21 @@ private void parse(string line) {
}
}

if (whitespace() == false)
/* Whitespace check. */
while (i < line.length && (line[i] == ' ' || line[i] == '\t' ||
line[i] == ';')) {
if (line[i] == ';') {
comm = line[i..$];
return;
}

i++;
}

if (i == line.length)
return;

/* Get op. */
auto opstart = i;
for (; i < line.length; i++) {
if (endoftoken()) {
Expand All @@ -182,9 +176,21 @@ private void parse(string line) {
return;
}

if (whitespace() == false)
/* Whitespace check. */
while (i < line.length && (line[i] == ' ' || line[i] == '\t' ||
line[i] == ';')) {
if (line[i] == ';') {
comm = line[i..$];
return;
}

i++;
}

if (i == line.length)
return;

/* Get first arg. */
auto a1start = i;
if (line[i] == '\'') {
i++;
Expand Down Expand Up @@ -223,9 +229,21 @@ private void parse(string line) {
}
}

if (whitespace() == false)
/* Whitespace check. */
while (i < line.length && (line[i] == ' ' || line[i] == '\t' ||
line[i] == ';')) {
if (line[i] == ';') {
comm = line[i..$];
return;
}

i++;
}

if (i == line.length)
return;

/* Get second arg. */
auto a2start = i;
for (; i < line.length; i++) {
if (endoftoken()) {
Expand All @@ -240,7 +258,16 @@ private void parse(string line) {
return;
}

whitespace();
/* Whitespace check. */
while (i < line.length && (line[i] == ' ' || line[i] == '\t' ||
line[i] == ';')) {
if (line[i] == ';') {
comm = line[i..$];
return;
}

i++;
}
}

/**
Expand Down

0 comments on commit a0a6f22

Please sign in to comment.