Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package logic;
  2.  
  3. import ru.lanwen.verbalregex.VerbalExpression;
  4.  
  5. public class Parser {
  6.     public Parser(String in) {
  7.         VerbalExpression replaceV = VerbalExpression.regex()
  8.                 .startOfLine()
  9.                 .then("ch")
  10.                 .then(" ")
  11.                 .capture()
  12.                 .anything()
  13.                 .endCapture()
  14.                 .then(":")
  15.                 .capture()
  16.                 .anything()
  17.                 .endCapture()
  18.                 .endOfLine()
  19.                 .build();
  20.  
  21.         VerbalExpression newV = VerbalExpression.regex()
  22.                 .startOfLine()
  23.                 .then("new")
  24.                 .then(" ")
  25.                 .capture()
  26.                 .anything()
  27.                 .endCapture()
  28.                 .endOfLine()
  29.                 .build();
  30.         VerbalExpression removeV = VerbalExpression.regex()
  31.                 .startOfLine()
  32.                 .then("rm")
  33.                 .then(" ")
  34.                 .capture()
  35.                 .anything()
  36.                 .endCapture()
  37.                 .endOfLine()
  38.                 .build();
  39.  
  40.         if (newV.test(in)) {
  41.             System.out.println("new command");
  42.         } else if (replaceV.test(in)) {
  43.             System.out.println("replace command");
  44.         } else if (removeV.test(in)) {
  45.             System.out.println("remove command");
  46.         } else {
  47.             System.out.println("invalid command");
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement