aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShevek <[email protected]>2008-05-08 15:06:53 +0000
committerShevek <[email protected]>2008-05-08 15:06:53 +0000
commit8247b6760685ab26fd518ea0ef13601587aad0f2 (patch)
tree9b343a1375554b44cae334fff458f778d701792b /src
parented355ecfc271ff0e7d8dc96e4f0f5f205ef144d9 (diff)
integrate feature support
Diffstat (limited to 'src')
-rw-r--r--src/java/org/anarres/cpp/JoinReader.java4
-rw-r--r--src/java/org/anarres/cpp/LexerSource.java43
-rw-r--r--src/java/org/anarres/cpp/Source.java8
3 files changed, 43 insertions, 12 deletions
diff --git a/src/java/org/anarres/cpp/JoinReader.java b/src/java/org/anarres/cpp/JoinReader.java
index 10ec535..298f49d 100644
--- a/src/java/org/anarres/cpp/JoinReader.java
+++ b/src/java/org/anarres/cpp/JoinReader.java
@@ -46,6 +46,10 @@ import java.io.IOException;
this(in, false);
}
+ public void setTrigraphs(boolean enable) {
+ this.trigraphs = enable;
+ }
+
private int __read() throws IOException {
if (uptr > 0)
return unget[--uptr];
diff --git a/src/java/org/anarres/cpp/LexerSource.java b/src/java/org/anarres/cpp/LexerSource.java
index 8561c04..8e679b5 100644
--- a/src/java/org/anarres/cpp/LexerSource.java
+++ b/src/java/org/anarres/cpp/LexerSource.java
@@ -23,7 +23,8 @@ import java.io.File;
import java.io.IOException;
import java.io.PushbackReader;
import java.io.Reader;
-import java.util.Stack;
+
+import java.util.Set;
import static org.anarres.cpp.Token.*;
@@ -31,11 +32,14 @@ import static org.anarres.cpp.Token.*;
public class LexerSource extends Source {
private static final boolean DEBUG = false;
+ private JoinReader _reader;
private PushbackReader reader;
private boolean ppvalid;
private boolean bol;
private boolean include;
+ private boolean digraphs;
+
private int line;
private int column;
private int lastcolumn;
@@ -45,11 +49,14 @@ public class LexerSource extends Source {
* false in StringLexerSource,
* true in FileLexerSource */
public LexerSource(Reader r, boolean ppvalid) {
- this.reader = new PushbackReader(new JoinReader(r), 5);
+ this._reader = new JoinReader(r);
+ this.reader = new PushbackReader(_reader, 5);
this.ppvalid = ppvalid;
this.bol = true;
this.include = false;
+ this.digraphs = true;
+
this.line = 1;
this.column = 0;
this.lastcolumn = -1;
@@ -57,6 +64,13 @@ public class LexerSource extends Source {
}
@Override
+ public void setFeatures(Set<Feature> features) {
+ super.setFeatures(features);
+ this.digraphs = features.contains(Feature.DIGRAPHS);
+ this._reader.setTrigraphs(features.contains(Feature.TRIGRAPHS));
+ }
+
+ @Override
public int getLine() {
return line;
}
@@ -295,13 +309,22 @@ public class LexerSource extends Source {
int e = read();
if (e != '\'') {
- unread(e);
error("Illegal character constant");
- /* XXX We should consume the rest of the line here. */
+ /* We consume up to the next ' or the rest of the line. */
+ for (;;) {
+ if (e == '\'')
+ break;
+ if (isLineSeparator(e)) {
+ unread(e);
+ break;
+ }
+ text.append((char)e);
+ e = read();
+ }
return new Token(ERROR, text.toString(), null);
}
text.append('\'');
- /* XXX Bad cast. */
+ /* XXX It this a bad cast? */
return new Token(CHARACTER,
text.toString(), Character.valueOf((char)d));
}
@@ -559,9 +582,9 @@ public class LexerSource extends Source {
d = read();
if (d == '=')
tok = new Token(MOD_EQ);
- else if (d == '>')
+ else if (digraphs && d == '>')
tok = new Token('}'); // digraph
- else if (d == ':') PASTE: {
+ else if (digraphs && d == ':') PASTE: {
d = read();
if (d != '%') {
unread(d);
@@ -584,7 +607,7 @@ public class LexerSource extends Source {
case ':':
/* :: */
d = read();
- if (d == '>')
+ if (digraphs && d == '>')
tok = new Token(']'); // digraph
else
unread(d);
@@ -600,9 +623,9 @@ public class LexerSource extends Source {
tok = new Token(LE);
else if (d == '<')
tok = cond('=', LSH_EQ, LSH);
- else if (d == ':')
+ else if (digraphs && d == ':')
tok = new Token('['); // digraph
- else if (d == '%')
+ else if (digraphs && d == '%')
tok = new Token('{'); // digraph
else
unread(d);
diff --git a/src/java/org/anarres/cpp/Source.java b/src/java/org/anarres/cpp/Source.java
index 7b269b6..0bc1476 100644
--- a/src/java/org/anarres/cpp/Source.java
+++ b/src/java/org/anarres/cpp/Source.java
@@ -27,8 +27,9 @@ import java.io.PushbackReader;
import java.io.Reader;
import java.io.StringReader;
-import java.util.List;
import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
import static org.anarres.cpp.Token.*;
@@ -97,10 +98,13 @@ public abstract class Source implements Iterable<Token> {
return parent;
}
- /* pp */ void setListener(PreprocessorListener listener) {
+ public void setListener(PreprocessorListener listener) {
this.listener = listener;
}
+ public void setFeatures(Set<Feature> features) {
+ }
+
/**
* Returns the File currently being lexed.
*