Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

CHARSET

DEFINITION MODULE CHARSET [SetType];

(* CHAR based 128-bit Bitset *)

FROM FileIO IMPORT File; (* required for IO *)


(* CHARSET type *)

TYPE
    CHARSET = OPAQUE RECORD
        ARRAY 16 OF OCTET; (* 128 bits *)
    END; (* CHARSET *)


(* Literal assignment *)

PROCEDURE [:=] assign ( VAR assignTo : CHARSET;
                        elements     : VARIADIC OF CHAR );
(* Assigns a variadic list of values of type CHAR to CHARSET assignTo.
   This procedure is bound to the := operator for literal assignment. *)


(* accessor *)

PROCEDURE [.] isElement ( CONST set : CHARSET; ch : CHAR ) : BOOLEAN;
(* Returns TRUE if character ch is an element of CHARSET set, otherwise FALSE.
   This function is bound to the array operator [ ] and the IN operator
   for rvalues of type CHARSET. *)


(* mutator *)

PROCEDURE [!] storeValue ( CONST set : CHARSET;
                           element   : CHAR;
                           value     : BOOLEAN );
(* Includes character element in CHARSET set if value is TRUE, otherwise
   removes it from set. This procedure is bound to the array operator [ ]
   for lvalues of type CHARSET. *)


(* counter *)

PROCEDURE [COUNT] elementCount ( CONST set : CHARSET ) : CARDINAL;
(* Returns the number of elements in CHARSET set. This function is bound
   to pervasive function COUNT for type CHARSET. *)


(* Dyadic set operations *) 

PROCEDURE [+] union ( CONST set1, set2 : CHARSET ) : CHARSET;
(* Returns the union of CHARSET values set1 and set2.
   This function is bound to the + operator for type CHARSET. *)

PROCEDURE [-] diff ( CONST set1, set2 : CHARSET ) : CHARSET;
(* Returns the set difference of CHARSET values set1 and set2.
   This function is bound to the - operator for type CARD16. *)

PROCEDURE [*] intersection ( set1, set2 : CHARSET ) : CHARSET;
(* Returns the intersection of CHARSET values set1 and set2.
   This function it bound to the * operator for type CARD16. *)

PROCEDURE [/] symdiff ( set1, set2 : CHARSET ) : CHARSET;
(* Returns the symmetric set difference of CHARSET values set1 and set2.
   This function is bound to the / operator for type CHARSET. *)


(* Relational operations *)

PROCEDURE [=] isEqual ( set1, set2 : CHARSET ) : BOOLEAN;
(* Returns TRUE if CHARSET values set1 and set2 are equal, otherwise FALSE.
   This function is bound to operators = and # for type CHARSET. *)

PROCEDURE [<] isSubset ( set1, set2 : CHARSET ) : BOOLEAN;
(* Returns TRUE if CHARSET set1 is a true subset of set2, otherwise FALSE.
   This function is bound to operators < and >= for type CHARSET. *)

PROCEDURE [>] isSuperset ( set1, set2 : CARD16 ) : BOOLEAN;
(* Returns TRUE if CHARSET set1 is a true superset of set2, otherwise FALSE.
   This function is bound to operators > and <= for type CHARSET. *)


(* IO operations *)

(* EBNF of the textual representation of CHARSET values:
    charsetValue : simpleFormat | quotedCharFormat | mixedFormat ;
    simpleFormat : "{" ( codePoint  ( "," codePoint )* )? "}" ; 
    mnemonicFormat : "{" ( quotedChar ( "," quotedChar )* )? "}" ;
    mixedFormat : "{" ( codeOrChar ( "," codeOrChar )* )? "}" ;
    codePoint : "0" base16Digit base16Digit "C" ;
    quotedChar : mnemonic | '"' character '"' ;
    codeOrChar : codePoint | '"' character '"' ;
    mnemonic : "NUL" | "SOH" | "STX" | "ETX" | "EOT" | "ENQ" | "ACK" |
        "BEL" | "BS" | "HT" | "LF" | "VT" | "FF" | "CR" | "SO" | "SI" |
        "DLE" | "DC1" | "DC2" | "DC3" | "DC4" | "NAK" | "SYN" | "ETB" |
        "CAN" | "EM" | "SUB" | "ESC" | "FS" | "GS" | "RS" | "US" | "DEL" ;
    character : digit | letter |
        " " | "!" | "#" | "$" | "%" | "&" | "(" | ")" | "*" | "+" |
        "," | "-" | "." | "/" | ":" | ";" | "<" | "=" | ">" | "?" |
        "@" | "[" | "]" | "^" | "_" | "`" | "{" | "|" | "}" | "~" ;
    digit : "0" .. "9" ;
    letter : "A" .. "Z" | "a" .. "z" ;
    base16Digit : "0" .. "9" | "A" .. "F" ; *)

PROCEDURE Read ( infile : File; VAR set : CHARSET );
(* Reads the textual representation of a CHARSET value from stream infile
   - any leading whitespace is skipped
   - any remaining characters that are part of the value being read are
     removed from infile
   - the textual representation of the value read is assigned to set
   - the file status is set to any of:
     success, outOfRange, wrongFormat, endOfLine, or endOfInput. This
   procedure is substituted for invocations of READ with a CHARSET argument.*)

PROCEDURE Write ( outfile : File; CONST set : CHARSET );
(* Writes the value of CHARSET set in simple format to stream outfile. This
   procedure is substituted for invocations of WRITE with a CHARSET argument.*)

PROCEDURE WriteF ( outfile      : File;
                   CONST fmtStr : ARRAY OF CHAR;
                   items        : VARIADIC OF CONST CHARSET );
(* Writes a formatted textual representation of one or more CHARSET values to
   output stream outfile. The output format is determined by fmtStr. This
   procedure is substituted for invocations of WRITEF with one or more
   CHARSET arguments. *)

END CHARSET.