Working out ANTLR grammar
This commit is contained in:
parent
c4f2b9ae65
commit
2633088303
|
|
@ -4,7 +4,7 @@ grammar Command;
|
|||
line: command param* where? retrn? ;
|
||||
command: CMD ;
|
||||
param: NAME ('=' text )? ;
|
||||
text: NO_SPACE | QUOTED ;
|
||||
text: (QUOTED|VALUE) ;
|
||||
where: 'where' expr ;
|
||||
expr: ( eqExpr | hasExpr | moreExpr | lessExpr ) binExpr? ;
|
||||
binExpr: andExpr | orExpr ;
|
||||
|
|
@ -17,7 +17,7 @@ orExpr: expr 'or' expr ;
|
|||
retrn: 'returns' NAME (',' NAME )* ;
|
||||
|
||||
NAME : ('a'..'z'|'A'..'Z'|'-')+ ;
|
||||
CMD_PART : ('/' NAME)+ ;
|
||||
CMD : CMD_PART+ ;
|
||||
NO_SPACE : [\\S]+ ;
|
||||
QUOTED : ('"' [.]* '"') ;
|
||||
CMD : (('/')(NAME))+ ;
|
||||
QUOTED : ('"')(.*?)('"') ;
|
||||
VALUE : (~[ \t\r\n="])+ ;
|
||||
WS: [ \n\t\r]+ -> skip;
|
||||
|
|
@ -7,7 +7,7 @@ package examples;
|
|||
public class Config {
|
||||
|
||||
|
||||
public static final String HOST = "10.0.1.3";
|
||||
public static final String HOST = "10.0.1.134";
|
||||
public static final String USERNAME = "admin";
|
||||
public static final String PASSWORD = "";
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ public class Example6 extends Example {
|
|||
}
|
||||
|
||||
private void test() throws MikrotikApiException, InterruptedException {
|
||||
con.execute("/interface/gre/add remote-address=10.0.1.1 name=gre1 keepalive=10");
|
||||
// con.execute("/interface/gre/add remote-address=1.2.3.4 name=gre1 keepalive=10 comment='test comment'");
|
||||
con.execute("/ip/firewall/filter/add action=drop chain=forward in-interface=gre1 protocol=udp dst-port=78,80");//,80,32");
|
||||
Thread.sleep(10000); // 10 seconds for the user to look on the router to see the interface with /interface gre print
|
||||
con.execute("/interface/gre/set remote-address=172.16.1.1 .id=gre1");
|
||||
// now look again and the IP has changed
|
||||
|
|
|
|||
|
|
@ -486,7 +486,7 @@ public final class ApiConnectionImpl extends ApiConnection {
|
|||
throw new ApiConnectionException(ex.getMessage(), ex);
|
||||
}
|
||||
if (err != null) {
|
||||
throw err;
|
||||
throw new MikrotikApiException(err.getMessage(), err);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
|
|
@ -44,8 +45,13 @@ class Parser {
|
|||
if (token == Token.EQUALS) {
|
||||
next();
|
||||
expect(Token.NAME);
|
||||
cmd.addParameter(new Parameter(name, text));
|
||||
String val = text;
|
||||
next();
|
||||
while (token == Token.COMMA) {
|
||||
next();
|
||||
val = val + "," + text;
|
||||
}
|
||||
cmd.addParameter(new Parameter(name, val));
|
||||
}
|
||||
else {
|
||||
cmd.addParameter(new Parameter(name));
|
||||
|
|
@ -173,9 +179,10 @@ class Parser {
|
|||
// System.out.printf("%s: %s\n", token, text);
|
||||
}
|
||||
|
||||
private Parser(String text) {
|
||||
text = text.trim();
|
||||
StringTokenizer st = new StringTokenizer(text, " \t,=", true);
|
||||
private Parser(String line) {
|
||||
line = line.trim();
|
||||
StringTokenizer st = new StringTokenizer(line, " \t,=", true);
|
||||
boolean quote = false;
|
||||
while (st.hasMoreElements()) {
|
||||
String t = st.nextToken().trim();
|
||||
if (!t.equals("")) {
|
||||
|
|
@ -183,6 +190,7 @@ class Parser {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final List<String> words = new LinkedList<String>();
|
||||
private String text;
|
||||
private Token token;
|
||||
|
|
|
|||
Loading…
Reference in New Issue