Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34038
| Path | csiph.com!feeder.erje.net!2.us.feeder.erje.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail |
|---|---|
| From | Popping mad <rainbow@colition.gov> |
| Newsgroups | comp.lang.java.programmer |
| Subject | MapBuilder |
| Date | Mon, 28 Mar 2016 13:39:26 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 101 |
| Message-ID | <ndbc6e$k7m$4@reader1.panix.com> (permalink) |
| NNTP-Posting-Host | www.mrbrklyn.com |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | reader1.panix.com 1459172366 20726 96.57.23.82 (28 Mar 2016 13:39:26 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Mon, 28 Mar 2016 13:39:26 +0000 (UTC) |
| User-Agent | Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) |
| Xref | csiph.com comp.lang.java.programmer:34038 |
Show key headers only | View raw
Morning
I'm having trouble analyzing this code because I don't see any docs
for this MapBuilder class. Any idea what that is?
~~ris
import org.antlr.v4.runtime.*;
import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
public class ConfigTest extends BaseErrorListener {
public static void main(String[] args) {
System.exit(new ConfigTest().runAllTests());
}
HashMap<String,String> readConf(String filename) throws IOException {
// Instantiate the lexer and parser generated by Config.g4
ANTLRInputStream input = new ANTLRInputStream(new FileReader(filename));
ConfigLexer lexer = new ConfigLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ConfigParser parser = new ConfigParser(tokens);
// Call our syntaxError method when there are parse errors
parser.addErrorListener(this);
// Instantiate the visitor
MapBuilder builder = new MapBuilder(); <<===========================HERE
currentFail = false; // No parse failures yet, but if syntaxError is
// called, currentFail will be set to true.
// Do the parse and then visit the tree with the MapBuilder.
parser.top().accept(builder);
// Return the HashMap containing the configuration data.
return builder.map;
}
final String testsDir = "tests";
ConfFileFilter confFilter = new ConfFileFilter();
int numTests;
int numFails;
boolean currentFail = false;
int runAllTests() {
numTests = numFails = 0;
for(String test : listTests()) {
runOneTest(test);
}
return report();
}
String[] listTests() {
String[] fs = new File(testsDir).list(confFilter);
Arrays.sort(fs);
for(int i = 0; i < fs.length; i++) {
fs[i] = confFilter.baseName(fs[i]);
}
return fs;
}
void announce(String testName) {
numTests++;
System.err.println("========= #" + numTests + ": " + testName);
}
int report() {
System.err.printf("\n!!!!!!!!! %d failures out of %d tests\n",
numFails, numTests);
return numFails;
}
void runOneTest(String testName) {
announce(testName);
String confFile = testsDir + File.separator + testName + ".conf";
String dataFile = testsDir + File.separator + testName + ".dat";
try {
HashMap<String,String> actual = readConf(confFile);
System.err.println(" actual: " + actual);
ObjectInputStream iis = new ObjectInputStream(new FileInputStream(dataFile));
Object expected = iis.readObject();
System.err.println("expected: " + expected);
if(actual.equals(expected) && !currentFail) {
System.err.println(" PASS");
}
else {
numFails++;
System.err.println(" FAIL");
}
}
catch (Exception e) {
numFails++;
e.printStackTrace(System.err);
}
}
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
currentFail = true;
super.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
}
}
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
MapBuilder Popping mad <rainbow@colition.gov> - 2016-03-28 13:39 +0000
Re: MapBuilder Eric Douglas <e.d.programmer@gmail.com> - 2016-03-28 07:30 -0700
Re: MapBuilder Popping mad <rainbow@colition.gov> - 2016-03-28 16:25 +0000
Re: MapBuilder Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-28 14:53 -0400
csiph-web