Template:Prelude/general.a68: Difference between revisions

m
lang -> syntaxhighlight
m (add prefix white space)
m (lang -> syntaxhighlight)
 
(4 intermediate revisions by one other user not shown)
Line 1:
<syntaxhighlight lang="algol68"># -*- coding: utf-8 -*- #
COMMENT
 
This is an ALGOL 68 prelude file called prelude/general.
COMMENT
It contains small routine that are not part of any standard,
This is an ALGOL 68 prelude file called prelude/general.
but are none the less useful and widely used.
It contains small routine that are not part of any standard,
USAGE
but are none the less useful and widely used.
PR READ "prelude/general.a68" PR
USAGE
END COMMENT
PR READ "prelude/general.a68" PR
##########################################
END COMMENT
# Define some general routines and MODES #
 
##########################################
##########################################
MODE UTFCHAR = STRING;
# Define some general routines and MODES #
MODE UTF=FLEX[0]UTFCHAR;
##########################################
MODE SIMPLEOUT = [0]UNION(INT, CHAR, STRING, []STRING);
PRIO MIN=8, MAX=8;
MODE MOID = VOID; # Use in cases where the OP should really return a MODE #
OP MIN = (INT a,b)INT: (a<b|a|b),
MAX = (INT a,b)INT: (a>b|a|b);
PROC raise exception = (STRING type, SIMPLEOUT argv)VOID:(
OP MIN = (REAL a,b)REAL: (a<b|a|b),
BOOL exception = FALSE;
MAX = (REAL a,b)REAL: (a>b|a|b);
putf(stand error, ($g$, "Exception"," ",type, ": ", argv, $l$));
 
ASSERT (exception)
MODE IUR = UNION(INT, REAL);
);
OP R = (IUR x)REAL: (x|(REAL r):r, (INT i):REAL(i));
 
PROC raise undefined = (SIMPLEOUT argv)VOID:
MODE IURUC = UNION(INT, REAL, COMPL);
raise exception("Undefined", argv);
OP C = (IURUC x)COMPL: (x|(COMPL c): c, (REAL r):COMPL(r), (INT i):COMPL(i));
 
PROC raise value error = (SIMPLEOUT argv)VOID:
MODE SIMPLEOUTCUCCUS = [0]UNION(INTCHAR, #[]CHAR,# STRING, []STRING);
raise exception("Value Error",argv);
OP S = (CUCCUS x)STRING: (x|(STRING s):s, ([]CHAR cc): STRING(cc), (CHAR c):STRING(c));
 
MODE
UCHAR = STRING, LONGCHAR = UCHAR, USTRING=FLEX[0]LONGCHAR,
LBITS = UNION(SHORT SHORT BITS, SHORT BITS, BITS, LONG BITS, LONG LONG BITS),
LBYTES = UNION(SHORT SHORT BYTES, SHORT BYTES, BYTES, LONG BYTES, LONG LONG BYTES),
LINT = UNION(SHORT SHORT INT, SHORT INT, INT, LONG INT, LONG LONG INT),
LREAL = UNION(SHORT SHORT REAL, SHORT REAL, REAL, LONG REAL, LONG LONG REAL),
LCOMPL = UNION(SHORT SHORT COMPL, SHORT COMPL, COMPL, LONG COMPL, LONG LONG COMPL);
MODE SIMPLEOUT = [0]UNION(BOOL, CHAR, STRING, USTRING, LBITS, # LBYTES,# LINT, LREAL, LCOMPL);
MODE SIMPLEOUTF = [0]UNION(FORMAT, SIMPLEOUT);
MODE USIMPLEOUT = SIMPLEOUT # UNION(SIMPLEOUT, SIMPLEOUTF) #;
 
PRIO REPR = 8;
 
# Use MOID with "*:=" OPerators who's where the returned MODE is often VOIDed for convenience #
MODE MOID = VOID;
 
PROC raise exception = (STRING type, SIMPLEOUTUSIMPLEOUT argv)VOID:(
BOOL exception = FALSE;
putf(stand error, ($g$, "Exception"," ",type, ": ", argv, $l$));
#CASE argv IN#
# (SIMPLEOUSTRING argv):putf(stand error, argv),#
PROC raise undefined# = (SIMPLEOUT argv)VOID:#
putf(stand error, ($g" "$, argv))
#ESAC#;
putf(stand error, $l$);
ASSERT (exception)
);
 
# Python style exceptions #
PROC raise undefined = (USIMPLEOUT argv)VOID: raise exception("Undefined", argv);
PROC raise unimplemented=(USIMPLEOUT argv)VOID: raise exception("Unimplemented", argv);
PROC raise value error = (SIMPLEOUTUSIMPLEOUT argv)VOID: raise exception("Value Error",argv);
PROC raise index error = (USIMPLEOUT argv)VOID: raise exception("ValueIndex Error",argv);
PROC raise type error = (USIMPLEOUT argv)VOID: raise exception("Type Error",argv);
 
BOOL debug := FALSE, trace := FALSE;
 
PRIO INKEYS = 5, INVALUES = 5, NOTINKEYS = 5, NOTINVALUES = 5;
 
# Algol68G specific declarations #
INT match=0, no match=1, out of memory error=2, other error=3; # for RegEx searches #</syntaxhighlight>
<noinclude>{{template}}</noinclude>
3,026

edits