NextLine();
return;
case LineClassification::Kind::PreprocessorDirective:
- if (std::optional<TokenSequence> toks{TokenizePreprocessorDirective()}) {
- preprocessor_.Directive(*toks, this);
- }
+ preprocessor_.Directive(TokenizePreprocessorDirective(), this);
return;
case LineClassification::Kind::CompilerDirective:
directiveSentinel_ = line.sentinel;
}
inPreprocessorDirective_ = false;
at_ = saveAt;
- return {std::move(tokens)};
+ return {std::move(tokens)}; // TODO: is std::move() necessary?
}
void Prescanner::Say(Message &&message) { messages_.Put(std::move(message)); }
if (*at_ == '\n') {
return false;
}
-
if (*at_ == '\'' || *at_ == '"') {
QuotedCharacterLiteral(tokens);
preventHollerith_ = false;
if (EmitCharAndAdvance(tokens, '*') == '*') {
EmitCharAndAdvance(tokens, '*');
} else {
- preventHollerith_ = true; // ambiguity: CHARACTER*2H
+ // Subtle ambiguity:
+ // CHARACTER*2H declares H because *2 is a kind specifier
+ // DATAC/N*2H / is repeated Hollerith
+ preventHollerith_ = !slashInCurrentLine_;
}
} else {
char ch{*at_};
(ch == '=' && nch == '>')) {
// token comprises two characters
EmitCharAndAdvance(tokens, nch);
+ } else if (ch == '/') {
+ slashInCurrentLine_ = true;
}
}
tokens->CloseToken();
return IsPreprocessorDirectiveLine(lineStart_);
}
-void Prescanner::SkipCommentLines() {
+void Prescanner::SkipCommentLinesAndPreprocessorDirectives() {
while (lineStart_ < limit_) {
LineClassification line{ClassifyLine(lineStart_)};
- if (line.kind != LineClassification::Kind::Comment) {
+ switch (line.kind) {
+ case LineClassification::Kind::PreprocessorDirective:
+ preprocessor_.Directive(TokenizePreprocessorDirective(), this);
break;
+ case LineClassification::Kind::Comment: NextLine(); break;
+ default: return;
}
- NextLine();
}
}
if (*at_ == '&' && inCharLiteral_) {
return false;
}
- SkipCommentLines();
+ SkipCommentLinesAndPreprocessorDirectives();
const char *cont{FixedFormContinuationLine()};
if (cont == nullptr) {
return false;
if (*p != '\n' && (inCharLiteral_ || *p != '!')) {
return false;
}
- SkipCommentLines();
+ SkipCommentLinesAndPreprocessorDirectives();
p = lineStart_;
if (p >= limit_) {
return false;
at_ = at;
column_ = 1;
tabInCurrentLine_ = false;
+ slashInCurrentLine_ = false;
preventHollerith_ = false;
delimiterNesting_ = 0;
}
void QuotedCharacterLiteral(TokenSequence *);
void Hollerith(TokenSequence *, int);
bool PadOutCharacterLiteral(TokenSequence *);
- void SkipCommentLines();
+ void SkipCommentLinesAndPreprocessorDirectives();
bool IsFixedFormCommentLine(const char *) const;
bool IsFreeFormComment(const char *) const;
std::optional<std::size_t> IsIncludeLine(const char *) const;
const char *at_{nullptr}; // next character to process; < lineStart_
int column_{1}; // card image column position of next character
bool tabInCurrentLine_{false};
+ bool slashInCurrentLine_{false};
bool preventHollerith_{false};
bool inCharLiteral_{false};
bool inPreprocessorDirective_{false};