4
4
import java .io .Serializable ;
5
5
import java .io .StringWriter ;
6
6
import java .util .Collection ;
7
+ import java .util .HashSet ;
8
+ import java .util .Iterator ;
7
9
import java .util .List ;
8
10
import java .util .Locale ;
9
11
import java .util .Map ;
12
+ import java .util .Set ;
10
13
import java .util .function .Function ;
14
+ import java .util .function .Predicate ;
11
15
import org .matheclipse .core .basic .Config ;
12
16
import org .matheclipse .core .builtin .AttributeFunctions ;
13
17
import org .matheclipse .core .convert .AST2Expr ;
@@ -268,6 +272,53 @@ public IAST definition() {
268
272
return result ;
269
273
}
270
274
275
+ /** {@inheritDoc} */
276
+ @ Override
277
+ public IAST fullDefinition () {
278
+ Set <ISymbol > symbolSet = new HashSet <ISymbol >();
279
+ IAST rules = definition ();
280
+ for (int i = 1 ; i < rules .size (); i ++) {
281
+ IExpr rule = rules .get (i );
282
+ collectSymbolsRecursive (rule , symbolSet , x -> x .isSymbol () && !(x .isProtected ()));
283
+ }
284
+ if (symbolSet .size () > 0 ) {
285
+ IASTAppendable fullDefinition = F .ListAlloc (rules .size () + symbolSet .size ());
286
+ Iterator <ISymbol > iterator = symbolSet .iterator ();
287
+ while (iterator .hasNext ()) {
288
+ ISymbol symbol = iterator .next ();
289
+ IAST subRules = symbol .definition ();
290
+ fullDefinition .appendArgs (subRules );
291
+ }
292
+ return fullDefinition ;
293
+ }
294
+ return F .NIL ;
295
+ }
296
+
297
+ private static void collectSymbolsRecursive (IExpr expr , Set <ISymbol > symbolSet ,
298
+ Predicate <ISymbol > predicate ) {
299
+ if (expr .isAST ()) {
300
+ IAST list = (IAST ) expr ;
301
+ IExpr head = expr .head ();
302
+ if (head .isSymbol ()) {
303
+ if (predicate .test ((ISymbol ) head )) {
304
+ symbolSet .add ((ISymbol ) head );
305
+ }
306
+ } else {
307
+ collectSymbolsRecursive (head , symbolSet , x -> x .isSymbol ());
308
+ }
309
+ for (int i = 1 ; i < list .size (); i ++) {
310
+ IExpr arg = list .getRule (i );
311
+ collectSymbolsRecursive (arg , symbolSet , predicate );
312
+ }
313
+ } else {
314
+ if (expr .isSymbol ()) {
315
+ if (predicate .test ((ISymbol ) expr )) {
316
+ symbolSet .add ((ISymbol ) expr );
317
+ }
318
+ }
319
+ }
320
+ }
321
+
271
322
/** {@inheritDoc} */
272
323
@ Override
273
324
public String definitionToString () {
@@ -278,18 +329,37 @@ public String definitionToString() {
278
329
buf .append (this .toString ());
279
330
buf .append (")=" );
280
331
buf .append (attributesList .toString ());
281
- buf .append ("\n " );
332
+ buf .append ("\n \n " );
282
333
}
283
334
284
335
OutputFormFactory off = OutputFormFactory .get (EvalEngine .get ().isRelaxedSyntax ());
285
336
off .setIgnoreNewLine (true );
286
337
IAST list = definition ();
287
338
for (int i = 1 ; i < list .size (); i ++) {
288
- if (!off .convert (buf , list .get (i ))) {
339
+ if (!off .convert (buf , list .getRule (i ))) {
289
340
return "ERROR-IN-OUTPUTFORM" ;
290
341
}
291
342
if (i < list .size () - 1 ) {
292
- buf .append ("\n " );
343
+ buf .append ("\n \n " );
344
+ off .setColumnCounter (0 );
345
+ }
346
+ }
347
+ return buf .toString ();
348
+ }
349
+
350
+ /** {@inheritDoc} */
351
+ @ Override
352
+ public String fullDefinitionToString () {
353
+ IAST fullDefinition = fullDefinition ();
354
+ OutputFormFactory off = OutputFormFactory .get (EvalEngine .get ().isRelaxedSyntax ());
355
+ off .setIgnoreNewLine (true );
356
+ StringWriter buf = new StringWriter ();
357
+ for (int i = 1 ; i < fullDefinition .size (); i ++) {
358
+ if (!off .convert (buf , fullDefinition .getRule (i ))) {
359
+ return "ERROR-IN-OUTPUTFORM" ;
360
+ }
361
+ if (i < fullDefinition .size () - 1 ) {
362
+ buf .append ("\n \n " );
293
363
off .setColumnCounter (0 );
294
364
}
295
365
}
0 commit comments