PageRenderTime 41ms CodeModel.GetById 25ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist170907/src/edu/vub/at/objects/ATText.java

http://ambienttalk.googlecode.com/
Java | 168 lines | 16 code | 13 blank | 139 comment | 0 complexity | 08e028b43555de58f5f44663a93e87ed MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * ATText.java created on 26-jul-2006 at 15:18:43
  4 * (c) Programming Technology Lab, 2006 - 2007
  5 * Authors: Tom Van Cutsem & Stijn Mostinckx
  6 * 
  7 * Permission is hereby granted, free of charge, to any person
  8 * obtaining a copy of this software and associated documentation
  9 * files (the "Software"), to deal in the Software without
 10 * restriction, including without limitation the rights to use,
 11 * copy, modify, merge, publish, distribute, sublicense, and/or
 12 * sell copies of the Software, and to permit persons to whom the
 13 * Software is furnished to do so, subject to the following
 14 * conditions:
 15 *
 16 * The above copyright notice and this permission notice shall be
 17 * included in all copies or substantial portions of the Software.
 18 *
 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 26 * OTHER DEALINGS IN THE SOFTWARE.
 27 */
 28package edu.vub.at.objects;
 29
 30import edu.vub.at.exceptions.InterpreterException;
 31import edu.vub.at.objects.grammar.ATExpression;
 32
 33/**
 34 * ATText is the public interface to a native AmbientTalk string (a string of characters).
 35 * Extends the ATExpression interface since a Text can also be output by the parser as a literal.
 36 * 
 37 * @author tvc
 38 */
 39public interface ATText extends ATExpression {
 40
 41	// base-level interface
 42	/**
 43	 * Explodes a text into a table of constituent characters.
 44	 * <p>
 45	 * Usage example:
 46	 * <code>"ambienttalk".explode()</code> returns <code> [a, m, b, i, e, n, t, t, a, l, k]</code>
 47	 * 
 48	 * @return an {@link ATTable} resulting of exploding the receiver text into a table of constituent characters.
 49	 */
 50	public ATTable base_explode() throws InterpreterException;
 51	
 52	/**
 53	 * Splits a text according to the given regular expression.
 54	 * <p>
 55	 * For regular expression syntax, see the Java regular-expression constructs in java.util.regex.Pattern.
 56	 * <p>
 57	 * Usage example:
 58	 * <code>"one, two, three".split(", ")</code> returns <code>[ "one", "two", "three" ]</code>
 59	 * 
 60	 * @param regexpr a text representing the regular expression to apply in the split.
 61	 * @return an {@link ATTable} resulting of splitting the receiver text into a table according to the given regular expression.
 62	 * @throws XIllegalArgument if regular expression's syntax is invalid. 
 63	 */
 64	public ATTable base_split(ATText regexpr) throws InterpreterException;
 65	
 66	/**
 67	 * Evaluates a given closure on those elements of this text that match a given regular expression.
 68	 * <p>
 69	 * For regular expression syntax, see the Java regular-expression constructs in java.util.regex.Pattern.
 70	 * <p>
 71	 * Usage example:
 72	 * <code>"ambienttalk".find: "[aeiou]" do: { |vowel| buff << vowel; nil }</code> returns <code>buff = "aiea"</code>
 73	 * 
 74	 * @param regexp a text representing the regular expression to be found in the text.
 75	 * @param consumer the closure code that is applied each time the regular expression is matched in the text.
 76	 * @return nil
 77	 * @throws XIllegalArgument if regular expression's syntax is invalid. 
 78	 * @throws InterpreterException if raised inside the code closure.
 79	 */
 80	public ATNil base_find_do_(ATText regexp, ATClosure consumer) throws InterpreterException;
 81	
 82	/**
 83	 * Returns a new text replacing those elements of this text that match a given regular expression with the
 84	 * value resulting of the evaluation of a given closure.
 85	 * <p>
 86	 * Usage example:
 87	 * <code>"ambienttalk".replace: "[aeiou]" by: { |vowel| vowel.toUpperCase() }</code> returns <code>AmbIEnttAlk</code>
 88	 * 
 89	 * @param regexp a text representing the regular expression to be found in the text.
 90	 * @param transformer the closure code that is applied each time the regular expression matches.
 91	 * @return {@link ATText} replacing those elements of the table that match the regexpr pattern with the value resulting of the evaluation of the transformer closure.
 92	 * @throws XIllegalArgument if regular expression's syntax is invalid. 
 93	 * @throws InterpreterException if raised inside the code closure.
 94	 */
 95	public ATText base_replace_by_(ATText regexp, ATClosure transformer) throws InterpreterException;
 96	
 97	/**
 98	 * Converts all of the characters in this text to upper case.
 99	 * 
100	 * @return the {@link ATText} resulting of the conversion.
101	 */
102	public ATText base_toUpperCase() throws InterpreterException;
103	
104	/**
105	 * Converts all of the characters in this text to lower case.
106	 * 
107	 * @return the {@link ATText} resulting of the conversion.
108	 */
109	public ATText base_toLowerCase() throws InterpreterException;
110	
111	/**
112	 * Returns the length of this text.
113	 * 
114	 * @return the {@link ATNumber} representing the length of the sequence of characters of this text.
115	 */
116	public ATNumber base_length() throws InterpreterException;
117	
118	/**
119	 * Concatenation infix operator. Returns the concatenation of the this text and the text representing a given object.
120	 * <p>
121	 * Usage example:
122	 * <code>"ambient" + "talk"</code> returns <code>"ambienttalk"</code>
123	 * 
124	 * @param other an object whose text representation is concatenated to the receiver text.
125	 * @return an ATText containing the elements of the receiver text and then the elements of text representing the other object.
126	 */
127	public ATText base__oppls_(ATObject other) throws InterpreterException;
128	
129	/**
130	 * Returns the value of evaluating the generalized equality between this text and a given one.
131	 * <p>
132	 * The generalized equality returns:
133	 * <ul>
134	 * <li>-1 if the receiver is numerically greater than the text passed as argument.
135	 * <li>1 if the receiver is numerically smaller than the text passed as argument.
136	 * <li>0 if the receiver is numerically equal to the the text passed as argument.
137	 * </ul>
138	 * <p>
139	 * Usage example:
140	 * <code>"ambienttalk" <=> "ambienttalk"</code> returns <code>0</code>
141	 * 
142	 * @param other a text.
143	 * @return a {@link ATNumber} resulting of applying the generalized equality between the receiver and other. 
144	 */
145	public ATNumber base__opltx__opeql__opgtx_(ATText other) throws InterpreterException;
146	
147	/**
148	 * Attempts to match this text against a given regular expression.
149	 * <p>
150	 * For regular expression syntax, see the Java regular-expression constructs in java.util.regex.Pattern.
151	 * <p>
152	 * Usage example:
153	 * <code>"ambienttalk" ~= ".*tt.*"</code> returns <code>true</code>
154	 * 
155	 * @param other a text representing the regular expression to be found in the text.
156	 * @return true if and only if, the receiver text matches completely the other text pattern.
157	 * @throws XIllegalArgument if regular expression's syntax is invalid. 
158	 */
159	public ATBoolean base__optil__opeql_(ATText other) throws InterpreterException;
160	
161	/**
162	 * Tries to convert the text into a numeric object (a number or a fraction).
163	 * Example: <code>"1.0".parseNumeric() => 1.0</code>
164	 * @return the numeric object denoted by this text
165	 * @throws XIllegalArgument if the text cannot be converted into a number or a fraction
166	 */
167	public ATNumeric base_parseNumeric() throws InterpreterException;
168}