All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dakusui.jcunit.regex.Printer Maven / Gradle / Ivy

There is a newer version: 0.8.17
Show newest version
package com.github.dakusui.jcunit.regex;

import java.io.PrintStream;

public class Printer implements Expr.Visitor {
  private final PrintStream ps;

  public Printer(PrintStream ps) {
    this.ps = ps;
  }

  @Override
  public void visit(Expr.Alt exp) {
    ps.print("(");
    try {
      boolean first = true;
      for (Expr each : exp.getChildren()) {
        if (!first) {
          ps.print("|");
        }
        each.accept(this);
        first = false;
      }
    } finally {
      ps.print(")");
    }
  }

  @Override
  public void visit(Expr.Cat exp) {
    boolean first = true;
    for (Expr each : exp.getChildren()) {
      if (!first) {
        ps.print(" ");
      }
      each.accept(this);
      first = false;
    }
  }

  @Override
  public void visit(Expr.Leaf leaf) {
    ps.print(leaf.value());
  }

  @Override
  public void visit(Expr.Empty empty) {
    ps.print(empty);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy