ht's Scheme Interpreter  1.0
a simplified scheme interpreter implementation
preprocessor.cpp
Go to the documentation of this file.
1 #include <istream>
2 #include <string>
3 #include <cstddef>
4 #include "preprocessor.hpp"
5 
6 SchemeUnit::SchemeUnit(std::istream& schemeStream)
7 {
8  preprocess(schemeStream);
9 }
10 
11 void SchemeUnit::preprocess(std::istream& schemeStream)
12 {
13  inComment = false;
14  static std::string buffer;
15  while (!schemeStream.eof())
16  {
17  getline(schemeStream, buffer);
19 
20  stripSemiColon(buffer);
21  if (!inComment)
22  lines.push_back(buffer);
23  }
24 }
25 
26 
28 {
29  size_t pos = line.find("#!");
30  if (pos != line.npos && ( pos <2 || ( line[pos-1] != '\\' && line[pos-2]!='#')))
31  {
32  inComment = true;
33  line.erase(pos);
34  return CommentStart;
35  }
36 
37  size_t pos2 = line.find("!#");
38  if (pos2 != line.npos && ( pos <2 || ( line[pos2-1] != '\\' && line[pos2-2]!='#')))
39  {
40  if (inComment)
41  {
42  inComment = false;
43  line = line.substr(pos2+2);
44  return CommentEnd;
45  }
46  }
47  return Neutral;
48 }
49 
50 void SchemeUnit::stripSemiColon(std::string &line)
51 {
52  size_t pos = line.find(';');
53  if (pos != line.npos) line.erase(pos);
54 }
SchemeUnit(std::istream &schemeStream)
Definition: preprocessor.cpp:6
MultilineCommentStatus processMultilineComment(std::string &line)
void preprocess(std::istream &schemeStream)
void stripSemiColon(std::string &line)
std::vector< std::string > lines