Giter VIP home page Giter VIP logo

Comments (4)

dhalperi avatar dhalperi commented on June 15, 2024

Hi @songtianyi – the ANTLR4 grammars are compiled automatically as part of the build, using the antlr4-maven-plugin.

from batfish.

songtianyi avatar songtianyi commented on June 15, 2024

@dhalperi
The compilation failed

cd projects/batfish/
mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building batfish 0.28.1
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.batfish:batfish-common-protocol:jar:0.28.1 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.689 s
[INFO] Finished at: 2017-07-11T16:04:21+08:00
[INFO] Final Memory: 8M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project batfish: Could not resolve dependencies for project org.batfish:batfish:jar:0.28.1: Failure to find org.batfish:batfish-common-protocol:jar:0.28.1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

from batfish.

songtianyi avatar songtianyi commented on June 15, 2024

@dhalperi

cd projects/
mvn compile
mvn install
cp /Users/work/.m2/repository/org/batfish/allinone/0.28.1/allinone-0.28.1.jar $MYPROJECT/lib

This would be fine.

I want to use batfish grammar in my own project. But It couldn't recognize all network objects, just one showed.

Demo.java

import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;

import java.io.File;
import java.io.FileInputStream;

import org.batfish.grammar.cisco.*;

public class Demo {
    public static void main(String args[]) {
        try {
            File file = new File("/Users/work/dev/g4/cisco-host/test.txt");

            // create a CharStream that reads from standard input
            ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(file)); // create a lexer that feeds off of input CharStream
            CiscoLexer lexer = new CiscoLexer(input); // create a buffer of tokens pulled from the lexer
            CommonTokenStream tokens = new CommonTokenStream(lexer); // create a parser that feeds off the tokens buffer
            CiscoParser parser = new CiscoParser(tokens);
            ParseTree tree = parser.s_object(); // begin parsing at init rule

            ParseTreeWalker walker = new ParseTreeWalker();
            walker.walk(new Loader(), tree);

        }catch(Exception e) {
            System.out.println(e.toString());
        }

    }
}

Loader.java

import org.batfish.grammar.cisco.CiscoParser;
import org.batfish.grammar.cisco.CiscoParserBaseListener;

import java.util.*;

/**
 * Created by work on 2017/7/7.
 */
public class Loader extends CiscoParserBaseListener{
    public void enterS_object(CiscoParser.S_objectContext ctx) {
        System.out.println("new network object");
    }
}

test.txt

object network haha
 subnet 192.168.125.0 255.255.255.0
object network hasdfs
 host 192.168.125.125
object network asdfa
 range 192.168.125.2 192.168.125.124
object network asdfs
object network asdfas
 range 192.168.125.2 192.168.125.124
object network range
object network range
object network range
object network range
object network range
object network heeh1
object network sd1
object network range

output

new network object

from batfish.

songtianyi avatar songtianyi commented on June 15, 2024

I wrote a new rule to solve this.

objects
:
    (s_object)*
;

It works! Close!

from batfish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.