tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

auto-interpretation.js (1058B)


      1 import { readableText } from './codecs.js';
      2 export const interpretationLabels = {
      3     string: 'Text', number: 'Natural number', values: 'List · text / numbers',
      4     bool: 'Boolean', bytes: 'Bytes', tricu: 'tricu · t source', triangle: '△ source', dag: 'DAG · shared △', ternary: 'Ternary',
      5 };
      6 // A readability preference, not type inference. Empty text loses to natural zero;
      7 // valid-but-invisible Unicode/control sequences remain available via manual Text.
      8 export async function autoInterpretation(inspect, disposed) {
      9     for (const output of ['string', 'number', 'values', 'bool', 'bytes']) {
     10         try {
     11             const result = await inspect(output);
     12             if (result.type === 'string' && (typeof result.value !== 'string' || !readableText(result.value)))
     13                 continue;
     14             return result;
     15         }
     16         catch (error) {
     17             // A failed decoder is recoverable; a poisoned runtime is not another hint.
     18             if (disposed())
     19                 throw error;
     20         }
     21     }
     22     return inspect('tricu');
     23 }