lib/TypedFeatureStructure.js
function prettyPrint0(fs, indent) {
    logger.debug('prettyPrint0: ' + fs);
    var result = '';

    if (fs) {
      if (Object.keys(fs.incoming).length > 1) {
        if (fs.printed) {
          // Return the label
          return (fs.getLabel());
        }
        else {
          // Print the label
          result += fs.getLabel() + space;
          indent += fs.getLabel().length + 1;
          // and continue to print the substructure
        }
      }
      // mark the current node as printed
      fs.printed = true;

      if (!Object.keys(fs.features).length) {
        logger.debug('prettyPrint0() ' + fs.type.name);
        result += (debug ? fs.getLabel() : '');
        if (fs.type === signature.typeLattice.string) {
          // Print the lexical string
          result += '\"' + fs.lexicalString + '\"';
        }
        else {
          if (fs.type === signature.typeLattice.list) {
            // Distinguish ordinary references from list of references
            if (fs.listOfCrossRefs) {
              // Print the list of cross references
              result += '<';
              fs.listOfCrossRefs.forEach(function (ref) {
                if (ref.printed) {
                  result += ref.getLabel() + ', ';
                }
                else { // Print the referred fs
                  result += prettyPrint0(ref, indent + 1) + ',\n';
                }
              });
              // Remove the last comma plus space, if necessary
              if (fs.listOfCrossRefs.length) {
                result = result.substr(0, result.length - 2);
              }
              result += '>';
            }
            else {
              // Print the type
              result += fs.type.prettyPrint();
            }
          }
          else {
            if (fs.type === signature.typeLattice.concatlist) {
              // Print concatenation of lists of cross referenced nodes
              if (fs.listOfCrossRefs) {
                result += '<';
                var nrPrinted = 0;
                fs.listOfCrossRefs.forEach(function (ref) {
                  if (ref.printed) {
                    result += ref.getLabel() + ' + ';
                  }
                  else {
                    result += prettyPrint0(ref, indent + 1) + ' +\n';
                  }
                  nrPrinted++;
                });
                // Remove the last comma plus space, if one or more elements
                // were printed
                if (nrPrinted) {
                  result = result.substr(0, result.length - 3);
                }
                result += '>';
              }
              else {
                // Print the type
                result += fs.type.prettyPrint();
              }
            }
            else {
              // Print the type
              result += fs.type.prettyPrint();
            }
          }
        }
      }
      else {
        // Print the substructure
        result += '[' + (debug ? fs.getLabel() : '');
        Object.keys(fs.features).forEach(function (feature, index) {
          if (index === 0) {
            // first print the type of the substructure
            logger.debug('prettyPrint0(): ' + fs.type.name);
            result += fs.type.prettyPrint() + '\n'; // + ' (incoming: ' +' +
            //' Object.keys(fs.incoming).length + ')' + '\n';
            result += space.repeat(indent + 1);
            result += feature + ':' + space;
            result += prettyPrint0(fs.features[feature], indent + feature.length + 3) + '\n';
          }
          else {
            result += space.repeat(indent + 1) + feature + ':' + space;
            result += prettyPrint0(fs.features[feature], indent + feature.length + 3) + '\n';
          }
        });
        result += space.repeat(indent) + ']';
      }
    }
    else {
      result += 'WARNING: empty fs\n';
    }
    return (result);
  }
function prettyPrint0(fs, indent) {
    logger.debug('prettyPrint0: ' + fs);
    var result = '';

    if (fs) {
      if (Object.keys(fs.incoming).length > 1) {
        if (fs.printed) {
          // Return the label
          return (fs.getLabel());
        }
        else {
          // Print the label
          result += fs.getLabel() + space;
          indent += fs.getLabel().length + 1;
          // and continue to print the substructure
        }
      }
      // mark the current node as printed
      fs.printed = true;

      if (!Object.keys(fs.features).length) {
        logger.debug('prettyPrint0() ' + fs.type.name);
        result += (debug ? fs.getLabel() : '');
        if (fs.type === signature.typeLattice.string) {
          // Print the lexical string
          result += '\"' + fs.lexicalString + '\"';
        }
        else {
          if (fs.type === signature.typeLattice.list) {
            // Distinguish ordinary references from list of references
            if (fs.listOfCrossRefs) {
              // Print the list of cross references
              result += '<';
              fs.listOfCrossRefs.forEach(function (ref) {
                if (ref.printed) {
                  result += ref.getLabel() + ', ';
                }
                else { // Print the referred fs
                  result += prettyPrint0(ref, indent + 1) + ',\n';
                }
              });
              // Remove the last comma plus space, if necessary
              if (fs.listOfCrossRefs.length) {
                result = result.substr(0, result.length - 2);
              }
              result += '>';
            }
            else {
              // Print the type
              result += fs.type.prettyPrint();
            }
          }
          else {
            if (fs.type === signature.typeLattice.concatlist) {
              // Print concatenation of lists of cross referenced nodes
              if (fs.listOfCrossRefs) {
                result += '<';
                var nrPrinted = 0;
                fs.listOfCrossRefs.forEach(function (ref) {
                  if (ref.printed) {
                    result += ref.getLabel() + ' + ';
                  }
                  else {
                    result += prettyPrint0(ref, indent + 1) + ' +\n';
                  }
                  nrPrinted++;
                });
                // Remove the last comma plus space, if one or more elements
                // were printed
                if (nrPrinted) {
                  result = result.substr(0, result.length - 3);
                }
                result += '>';
              }
              else {
                // Print the type
                result += fs.type.prettyPrint();
              }
            }
            else {
              // Print the type
              result += fs.type.prettyPrint();
            }
          }
        }
      }
      else {
        // Print the substructure
        result += '[' + (debug ? fs.getLabel() : '');
        Object.keys(fs.features).forEach(function (feature, index) {
          if (index === 0) {
            // first print the type of the substructure
            logger.debug('prettyPrint0(): ' + fs.type.name);
            result += fs.type.prettyPrint() + '\n'; // + ' (incoming: ' +' +
            //' Object.keys(fs.incoming).length + ')' + '\n';
            result += space.repeat(indent + 1);
            result += feature + ':' + space;
            result += prettyPrint0(fs.features[feature], indent + feature.length + 3) + '\n';
          }
          else {
            result += space.repeat(indent + 1) + feature + ':' + space;
            result += prettyPrint0(fs.features[feature], indent + feature.length + 3) + '\n';
          }
        });
        result += space.repeat(indent) + ']';
      }
    }
    else {
      result += 'WARNING: empty fs\n';
    }
    return (result);
  }
function prettyPrint0 ( fs , indent ) { logger . debug ( 'prettyPrint0: ' + fs ) ; var result = '' ; if ( fs ) { if ( Object . keys ( fs . incoming ) . length > 1 ) { if ( fs . printed ) { // Return the label return ( fs . getLabel ( ) ) ; } else { // Print the label result += fs . getLabel ( ) + space ; indent += fs . getLabel ( ) . length + 1 ; // and continue to print the substructure } } // mark the current node as printed fs . printed = true ; if ( ! Object . keys ( fs . features ) . length ) { logger . debug ( 'prettyPrint0() ' + fs . type . name ) ; result += ( debug ? fs . getLabel ( ) : '' ) ; if ( fs . type === signature . typeLattice . string ) { // Print the lexical string result += '\"' + fs . lexicalString + '\"' ; } else { if ( fs . type === signature . typeLattice . list ) { // Distinguish ordinary references from list of references if ( fs . listOfCrossRefs ) { // Print the list of cross references result += '<' ; fs . listOfCrossRefs . forEach ( function ( ref ) { if ( ref . printed ) { result += ref . getLabel ( ) + ', ' ; } else { // Print the referred fs result += prettyPrint0 ( ref , indent + 1 ) + ',\n' ; } } ) ; // Remove the last comma plus space, if necessary if ( fs . listOfCrossRefs . length ) { result = result . substr ( 0 , result . length - 2 ) ; } result += '>' ; } else { // Print the type result += fs . type . prettyPrint ( ) ; } } else { if ( fs . type === signature . typeLattice . concatlist ) { // Print concatenation of lists of cross referenced nodes if ( fs . listOfCrossRefs ) { result += '<' ; var nrPrinted = 0 ; fs . listOfCrossRefs . forEach ( function ( ref ) { if ( ref . printed ) { result += ref . getLabel ( ) + ' + ' ; } else { result += prettyPrint0 ( ref , indent + 1 ) + ' +\n' ; } nrPrinted ++ ; } ) ; // Remove the last comma plus space, if one or more elements // were printed if ( nrPrinted ) { result = result . substr ( 0 , result . length - 3 ) ; } result += '>' ; } else { // Print the type result += fs . type . prettyPrint ( ) ; } } else { // Print the type result += fs . type . prettyPrint ( ) ; } } } } else { // Print the substructure result += '[' + ( debug ? fs . getLabel ( ) : '' ) ; Object . keys ( fs . features ) . forEach ( function ( feature , index ) { if ( index === 0 ) { // first print the type of the substructure logger . debug ( 'prettyPrint0(): ' + fs . type . name ) ; result += fs . type . prettyPrint ( ) + '\n' ; // + ' (incoming: ' +' + //' Object.keys(fs.incoming).length + ')' + '\n'; result += space . repeat ( indent + 1 ) ; result += feature + ':' + space ; result += prettyPrint0 ( fs . features [ feature ] , indent + feature . length + 3 ) + '\n' ; } else { result += space . repeat ( indent + 1 ) + feature + ':' + space ; result += prettyPrint0 ( fs . features [ feature ] , indent + feature . length + 3 ) + '\n' ; } } ) ; result += space . repeat ( indent ) + ']' ; } } else { result += 'WARNING: empty fs\n' ; } return ( result ) ; }
Actual pretty printer
Actual pretty printer