Gallery
Insidion Engine
Share
Explore

Scanning

The Scanner has two jobs:
remove comments
produce character stream

Removing Comments

The scanner has to iterate over each line, and implement a simple algorithm to ignore the current line if it is a comment or part of a multiline comment.
This is what Scanner.stripComments does:
String stripComments(String source) {
List<String> lines = [];
bool inMultilineComment = false;
source.split("\n").forEach((String line) {
String cleanLine = line.trim();
if (cleanLine.length > 1) {
if (cleanLine[0] == '/') {
if (cleanLine[1] == '/' || cleanLine[1] == '|') {
} else if (cleanLine[1] == '*') {
inMultilineComment = true;
}
} else if (cleanLine[0] == '*' && cleanLine[1] == '/') {
inMultilineComment = false;
} else {
!inMultilineComment ? lines.add(line) : null;
}
} else {
!inMultilineComment ? lines.add(line) : null;
}
});
return lines.join('\n');
}
It adds each line to the cleaned source only if it is not a comment or part of one.

Character Stream

This step is basically taking this:
var myVar = 10;
And turning it into this:
[v, a, r, , m, y, V, a, r, , =, , 1, 0, ;]
The list of characters above is known as a character stream. I don’t suppose we need to see how Insidion implements this because it’s as simple as source.split(’’) .
Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.