Package edu.umn.cs.melt.copper.compiletime.logging

Examples of edu.umn.cs.melt.copper.compiletime.logging.PrintCompilerLogHandler


    StringReader isr = new StringReader(input.getSrcString());
    ArrayList<edu.umn.cs.melt.copper.runtime.auxiliary.Pair<String,Reader>> inp = new ArrayList<>();
    inp.add(new Pair<String, Reader>("TSL grammar", isr));


    CompilerLogger logger = new CompilerLogger(new PrintCompilerLogHandler(System.out) {
      @Override
      public void handleMessage(CompilerLogMessage message) {
        if (message instanceof GrammarSyntaxError)
          throw new CopperGrammarException((GrammarSyntaxError)message);
        super.handleMessage(message);
View Full Code Here


    ParserBean extension;
    try (InputStream is = new FileInputStream(extensionGrammar)) {
      ArrayList<Pair<String,Reader>> files = new ArrayList<>();
      files.add(new Pair<String, Reader>(extensionGrammar.getName(), new InputStreamReader(is)));
      XMLSkinParser xmlSkinParser = new XMLSkinParser(files,
          new CompilerLogger(new PrintCompilerLogHandler(new PrintStream(new OutputStream() {
            public void write(int b) {
              //Nothing - suppress all messages
            }
          }))));
      xmlSkinParser.parse();
      Field parserField = xmlSkinParser.getClass().getDeclaredField("currentParser");
      parserField.setAccessible(true);
      extension = (ParserBean)parserField.get(xmlSkinParser);
    } catch (Exception e) {
      throw new BuildException(e);
    }

    try {
      CopperElementName grammarName = CopperElementName.newName("_" + hostGrammarName);
      ((ExtendedParserBean)extension).setHostGrammar(host.getGrammar(grammarName));
      Field grammarField = extension.getClass().getSuperclass().getDeclaredField("grammars");
      grammarField.setAccessible(true);
      Hashtable<CopperElementName,Grammar> grammars =
          (Hashtable<CopperElementName, Grammar>) grammarField.get(extension);
      grammars.put(grammarName,host.getGrammar(grammarName));
    } catch (Exception e) {
      throw new BuildException(e);
    }

    extension.setParserClassAuxCode(host.getParserClassAuxCode());
    extension.setParserInitCode(host.getParserInitCode());

    Function<CopperElementReference, String> nameGetter = cen -> cen.getGrammarName() +"$"+cen.getName();

    Stream<Stream<GrammarElement>> elements = host.getGrammars().stream().map(host::getGrammar)
        .map(grammar -> grammar.getGrammarElements().stream().map(grammar::getGrammarElement));

    List<DisambiguationFunction> dfl = elements
        .map(ielements -> ielements.filter(el -> el instanceof DisambiguationFunction))
        .flatMap(e->e.map(el->(DisambiguationFunction)el)).collect(Collectors.toList());
    dfl.stream().forEach(df ->
        df.setCode(df.getMembers().stream()
            .map(cen -> "\t\t\tfinal int " + cen.getName() + " = " + nameGetter.apply(cen) + ";")
            .reduce((l, r) -> l + "\n" + r).orElseGet(() -> "") + "\n" + df.getCode()));



    host.getGrammars().stream().map(host::getGrammar)
        .map(grammar -> grammar.getGrammarElements().stream().map(grammar::getGrammarElement))
        .flatMap(els -> els.filter(el -> el instanceof Production).map(el -> (Production) el))
        .forEach(this::rewriteTerminals);

    host.getGrammars().stream().map(host::getGrammar)
        .map(grammar -> grammar.getGrammarElements().stream().map(grammar::getGrammarElement))
        .flatMap(els -> els.filter(el -> el instanceof Terminal).map(el -> (Terminal) el))
        .forEach(this::rewriteTerminals);
    try {
      CompilerLogger logger = new CompilerLogger(new PrintCompilerLogHandler(System.out));
      ParserSpecProcessor.normalizeParser(extension, logger);
    } catch (CopperException e) {
      throw new BuildException(e);
    }
    ParserCompilerParameters pcp = new ParserCompilerParameters();
View Full Code Here

TOP

Related Classes of edu.umn.cs.melt.copper.compiletime.logging.PrintCompilerLogHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.