Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34038 > unrolled thread

MapBuilder

Started byPopping mad <rainbow@colition.gov>
First post2016-03-28 13:39 +0000
Last post2016-03-28 14:53 -0400
Articles 4 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#34038 — MapBuilder

FromPopping mad <rainbow@colition.gov>
Date2016-03-28 13:39 +0000
SubjectMapBuilder
Message-ID<ndbc6e$k7m$4@reader1.panix.com>
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);
    }
}

[toc] | [next] | [standalone]


#34042

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-03-28 07:30 -0700
Message-ID<05d8c731-d5d7-4b54-b755-5aa9b2fbaa40@googlegroups.com>
In reply to#34038
On Monday, March 28, 2016 at 9:39:35 AM UTC-4, Popping mad wrote:
> 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);
>     }
> }

You won't find any docs until we know which MapBuilder you're referring to.
You don't have any reference to a MapBuilder in your imports.  I tried googling MapBuilder and apparently it's in at least a few different APIs.
Try looking for that and your ConfigParser, which accepts your MapBuilder as a parameter.  If you can identify the API we can likely find the doc.

[toc] | [prev] | [next] | [standalone]


#34043

FromPopping mad <rainbow@colition.gov>
Date2016-03-28 16:25 +0000
Message-ID<ndblt1$k7m$6@reader1.panix.com>
In reply to#34042
On Mon, 28 Mar 2016 07:30:03 -0700, Eric Douglas wrote:

> 
> You won't find any docs until we know which MapBuilder you're referring to.
> You don't have any reference to a MapBuilder in your imports.  I tried googling MapBuilder and apparently it's in at least a few different APIs.
> Try looking for that and your ConfigParser, which accepts your MapBuilder as a parameter.  If you can identify the API we can likely find the doc.

ugg, I was just informed that I'm supposed to build the mapbuilder.  It would be nice if I understood the specifications.

[toc] | [prev] | [next] | [standalone]


#34045

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-03-28 14:53 -0400
Message-ID<ndbud8$j4q$1@dont-email.me>
In reply to#34043
On 3/28/2016 12:25 PM, Popping mad wrote:
> On Mon, 28 Mar 2016 07:30:03 -0700, Eric Douglas wrote:
>
>>
>> You won't find any docs until we know which MapBuilder you're referring to.
>> You don't have any reference to a MapBuilder in your imports.  I tried googling MapBuilder and apparently it's in at least a few different APIs.
>> Try looking for that and your ConfigParser, which accepts your MapBuilder as a parameter.  If you can identify the API we can likely find the doc.
>
> ugg, I was just informed that I'm supposed to build the mapbuilder.  It would be nice if I understood the specifications.

     If you do not understand the API's you're using, things
are unlikely to go well ...

     Perhaps your MapBuilder class (or interface?) is part of the
same suite of stuff as your BaseErrorListener, ConfigParser,
ConfigLexer, CommonTokenStream, and so on.  Have a look.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web