1 31 package org.jruby.ast; 32 33 import java.util.List ; 34 import java.util.regex.Pattern ; 35 36 import org.jruby.RegexpTranslator; 37 import org.jruby.ast.types.ILiteralNode; 38 import org.jruby.ast.visitor.NodeVisitor; 39 import org.jruby.evaluator.Instruction; 40 import org.jruby.lexer.yacc.ISourcePosition; 41 import org.jruby.util.ByteList; 42 43 47 public class RegexpNode extends Node implements ILiteralNode { 48 static final long serialVersionUID = -1566813018564622077L; 49 50 private static final RegexpTranslator translator = new RegexpTranslator(); 51 52 private Pattern pattern; 53 private final ByteList value; 54 private final int options; 55 56 public RegexpNode(ISourcePosition position, ByteList value, int options) { 57 super(position, NodeTypes.REGEXPNODE); 58 59 this.value = value; 60 this.options = options; 61 } 62 63 public Instruction accept(NodeVisitor iVisitor) { 64 return iVisitor.visitRegexpNode(this); 65 } 66 67 71 public int getOptions() { 72 return options; 73 } 74 75 79 public ByteList getValue() { 80 return value; 81 } 82 83 public Pattern getPattern() throws java.util.regex.PatternSyntaxException { 84 if (pattern == null) { 85 pattern = translator.translate(value.toString(), options, Pattern.UNIX_LINES); 86 } 87 return pattern; 88 } 89 90 public List childNodes() { 91 return EMPTY_LIST; 92 } 93 94 } 95 | Popular Tags |