View Javadoc

1   package io.github.reggert.reb4j;
2   
3   import io.github.reggert.reb4j.Quantified.Mode;
4   import fj.data.LazyString;
5   
6   /**
7    * Class representing special pre-defined expressions.
8    */
9   public class Entity extends Raw implements Quantifiable
10  {
11  	private static final long serialVersionUID = 1L;
12  
13  	private Entity(final String rawExpression)
14  	{super(LazyString.str(rawExpression));}
15  	
16  	@Override
17  	public final Quantified.AnyTimes anyTimes(final Mode mode)
18  	{return new Quantified.AnyTimes(this, mode);}
19  	
20  	@Override
21  	public final Quantified.AnyTimes anyTimes()
22  	{return anyTimes(Mode.GREEDY);}
23  
24  	@Override
25  	@Deprecated
26  	public final Quantified.AnyTimes anyTimesReluctantly()
27  	{return Quantified.anyTimesReluctantly(this);}
28  
29  	@Override
30  	@Deprecated
31  	public final Quantified.AnyTimes anyTimesPossessively()
32  	{return Quantified.anyTimesPossessively(this);}
33  
34  	@Override
35  	public final Quantified.AtLeastOnce atLeastOnce(final Mode mode)
36  	{return new Quantified.AtLeastOnce(this, mode);}
37  	
38  	@Override
39  	public final Quantified.AtLeastOnce atLeastOnce()
40  	{return atLeastOnce(Mode.GREEDY);}
41  
42  	@Override
43  	@Deprecated
44  	public final Quantified.AtLeastOnce atLeastOnceReluctantly()
45  	{return atLeastOnce(Mode.RELUCTANT);}
46  
47  	@Override
48  	@Deprecated
49  	public final Quantified.AtLeastOnce atLeastOncePossessively()
50  	{return atLeastOnce(Mode.POSSESSIVE);}
51  
52  	@Override
53  	public final Quantified.Optional optional(final Mode mode)
54  	{return new Quantified.Optional(this, mode);}
55  	
56  	@Override
57  	public final Quantified.Optional optional()
58  	{return optional(Mode.GREEDY);}
59  
60  	@Override
61  	@Deprecated
62  	public final Quantified.Optional optionalReluctantly()
63  	{return optional(Mode.RELUCTANT);}
64  
65  	@Override
66  	@Deprecated
67  	public final Quantified.Optional optionalPossessively()
68  	{return optional(Mode.POSSESSIVE);}
69  
70  	@Override
71  	public final Quantified.RepeatExactly repeat(final int n, final Mode mode)
72  	{return new Quantified.RepeatExactly(this, n, mode);}
73  	
74  	@Override
75  	public final Quantified.RepeatExactly repeat(final int n)
76  	{return repeat(n, Mode.GREEDY);}
77  
78  	@Override
79  	@Deprecated
80  	public final Quantified.RepeatExactly repeatReluctantly(final int n)
81  	{return repeat(n, Mode.RELUCTANT);}
82  
83  	@Override
84  	@Deprecated
85  	public final Quantified.RepeatExactly repeatPossessively(final int n)
86  	{return repeat(n, Mode.POSSESSIVE);}
87  
88  	@Override
89  	public final Quantified.RepeatRange repeat(final int min, final int max, final Mode mode)
90  	{return new Quantified.RepeatRange(this, min, max, mode);}
91  	
92  	@Override
93  	public final Quantified.RepeatRange repeat(final int min, final int max)
94  	{return repeat(min, max, Mode.GREEDY);}
95  
96  	@Override
97  	@Deprecated
98  	public final Quantified.RepeatRange repeatReluctantly(final int min, final int max)
99  	{return repeat(min, max, Mode.RELUCTANT);}
100 
101 	@Override
102 	@Deprecated
103 	public final Quantified.RepeatRange repeatPossessively(final int min, final int max)
104 	{return repeat(min, max, Mode.POSSESSIVE);}
105 
106 	@Override
107 	public final Quantified.RepeatRange atLeast(final int n, final Mode mode)
108 	{return new Quantified.RepeatRange(this, n, null, mode);}
109 	
110 	@Override
111 	public final Quantified.RepeatRange atLeast(final int n)
112 	{return atLeast(n, Mode.GREEDY);}
113 
114 	@Override
115 	@Deprecated
116 	public final Quantified.RepeatRange atLeastReluctantly(final int n)
117 	{return atLeast(n, Mode.RELUCTANT);}
118 
119 	@Override
120 	@Deprecated
121 	public final Quantified.RepeatRange atLeastPossessively(final int n)
122 	{return atLeast(n, Mode.POSSESSIVE);}
123 	
124 	@Override
125 	public final Integer boundedLength() 
126 	{
127 		return 1;
128 	}
129 	
130 	@Override 
131 	public final boolean repetitionInvalidatesBounds()  
132 	{
133 		return false;
134 	}
135 	
136 	@Override 
137 	public boolean possiblyZeroLength()
138 	{
139 		return true;
140 	}
141 	
142 	/**
143 	 * Matches any single character.
144 	 */
145 	public static final Entity ANY_CHAR = new Entity(".")
146 	{
147 		private static final long serialVersionUID = 1L;
148 
149 		@Override 
150 		public final boolean possiblyZeroLength()
151 		{
152 			return false;
153 		}
154 	};
155 
156 	/**
157 	 * Matches the beginning of a line.
158 	 */
159 	public static final Entity LINE_BEGIN = new Entity("^");
160 
161 	/**
162 	 * Matches the end of a line.
163 	 */
164 	public static final Entity LINE_END = new Entity("$");
165 
166 	/**
167 	 * Matches a word boundary.
168 	 */
169 	public static final Entity WORD_BOUNDARY = new Entity("\\b");
170 
171 	/**
172 	 * Matches a non-word-boundary.
173 	 */
174 	public static final Entity NONWORD_BOUNDARY = new Entity("\\B");
175 
176 	/**
177 	 * Matches the beginning of input.
178 	 */
179 	public static final Entity INPUT_BEGIN = new Entity("\\A");
180 
181 	/**
182 	 * Matches the end of the previous match.
183 	 */
184 	public static final Entity MATCH_END = new Entity("\\G");
185 
186 	/**
187 	 * Matches the end of input, skipping end-of-line markers.
188 	 */
189 	public static final Entity INPUT_END_SKIP_EOL = new Entity("\\Z");
190 
191 	/**
192 	 * Matches the end of input.
193 	 */
194 	public static final Entity INPUT_END = new Entity("\\z");
195 
196 }