/* ------------------------------------------------------------------------ */ /* */ /* [scn_base.h] Basic Token Separation */ /* */ /* Copyright (c) 1993 by D\olle, Manns */ /* ------------------------------------------------------------------------ */ /* File generated by 'ctoh'. Don't change manually. */ #ifndef scn_base_INCL #define scn_base_INCL #include "symbols.h" #include "scn_io.h" #ifdef __cplusplus extern "C" { #endif /*
The module [scn_base] implements the scan stream interface based on a given STYX-konform scanner definition. ( see [scn_gen] )
The scan stream is reentrant and allows multiple scan operations at a time.
*/
/* ------------------------ Macros ---------------------------------------- */
/*
Token definition flags ( see Scn_dfnToken ) */ #define SCN_FLG_IgnoreToken 1 /* token has to be ignored */ #define SCN_FLG_IgnoreCase 2 /* case insensitive token */ #define SCN_FLG_EofToken 4 /* eof token in embedded language */ #define SCN_FLG_SwitchToken 8 /* switch to/from embedded language */ #define SCN_FLG_CfgToken 16 /* embedded language token */ #define SCN_FLG_IndentToken 32 /* (de)indent token */ /*
Token preprocessing result values
*/
#define SCN_FLG_RescanNone 0
#define SCN_FLG_RescanString 1
#define SCN_FLG_RescanBString 2
#define SCN_FLG_RescanFile 3
#define SCN_FLG_RescanBFile 4
#define SCN_FLG_RescanExtFile 5
#define SCN_FLG_RescanExtBFile 6
#define SCN_FLG_RescanChar 7
#define SCN_FLG_RescanChrItr 8
#define SCN_FLG_RescanBChrItr 9
/* ------------------------- Stream of tokens ----------------------------- */
AbstractType( Scn_Stream ); /* Stream onto a scanner */
AbstractType( Scn_Stream_Itr ) /* Character iterator onto a scan stream */
;
/*
Type of token preprocessing function
RC = SCN_FLG_RescanChrItr & valid cMacVal --> rescan character iterator cMacVal
( frees character iterator )
RC = SCN_FLG_RescanBChrItr & valid cMacVal --> rescan binary char iterator cMacVal
( frees character iterator )
RC = SCN_FLG_RescanString & valid cMacVal --> rescan string cMacVal
RC = SCN_FLG_RescanBString & valid cMacVal --> rescan binary string cMacVal
RC = SCN_FLG_RescanBFile & valid cMacVal --> rescan binary file cMacVal
RC = SCN_FLG_RescanExtFile & valid cMacVal --> rescan file cMacVal,
with main stream read function
RC = SCN_FLG_RescanExtBFile & valid cMacVal --> rescan binary file cMacVal,
with main stream read function
RC = SCN_FLG_RescanChar & valid cMacVal --> rescan character cMacVal
( single byte or ucs4 )
RC = SCN_FLG_RescanNone & valid cMacVal --> replace cTokVal with cMacVal
( single byte or utf-8 )
ELSE --> ignore cTokVal
*/
typedef int (*Scn_PreMacFun)
(
Scn_Stream pStream, c_string cTokNam,
c_string cTokVal, symbol* cMacVal
);
/*
Type of the embedded language token constructor
*/
typedef Any_T (*Scn_eTerm)
(
Abs_T CurPTCfg, c_string language, c_string StartSymbol
);
/*
Type of the embedded language accept token recognizer
*/
typedef c_bool (*Scn_eAccept)(Abs_T CurPTCfg);
/* ------------------- Accessing scanner definition ----------------------- */
c_string Scn_id(Scn_T scn)
/* name of the scanner (group) 'scn'; allocs memory
*/
;
short Scn_check_Token(Scn_T scn, c_string s)
/* whether string 's' is a token in scanner 'scn';
result = token number ( > 0 ) or 0
assertion: Scn_groups(scn) = 0
*/
;
short Scn_check_WCToken(Scn_T scn, wc_string s)
/* whether wide string 's' is a token in scanner 'scn';
result = token number ( > 0 ) or 0
assertion: Scn_groups(scn) = 0
*/
;
int Scn_tokens(Scn_T scn)
/* number of tokens defined in scanner ( group ) 'scn' */
;
c_string Scn_tokid(Scn_T scn, int i)
/* name of the i-th token definied in scanner 'scn'; allocs memory
assertion: Scn_groups(scn) = 0
*/
;
c_byte Scn_tokFlags(Scn_T scn, int i)
/* flags of the i-th token definied in scanner 'scn'
assertion: Scn_groups(scn) = 0
*/
;
int Scn_dycks(Scn_T scn)
/* number of dyck token defined in scanner ( group ) 'scn' */
;
Scn_T Scn_dyck(Scn_T scn, int i)
/* i-th dyck scanner definied in scanner group 'scn'
assertion: Scn_dycks(scn) > 0
*/
;
int Scn_dycktoken(Scn_T scn, int i)
/* i-th dyck token definied in scanner group 'scn'
assertion: Scn_dycks(scn) > 0
*/
;
int Scn_groups(Scn_T scn)
/* number of groups defined in scanner ( group ) 'scn' */
;
Scn_T Scn_group(Scn_T scn, int i)
/* i-th scanner definied in scanner group 'scn'
assertion: Scn_groups(scn) > 0
*/
;
int Scn_SwitchGroup(Scn_T scn, int i)
/* switch group of the i-th token definied in scanner group 'scn' or -1
assertion: Scn_groups(scn) = 0
*/
;
long Scn_check_GroupToken(Scn_T scn, c_string s)
/* whether string 's' is a token in scanner group 'scn';
result: high = group index , low = token number ( > 0 ) or 0
assertion: Scn_groups(scn) > 0
*/
;
long Scn_check_GroupWCToken(Scn_T scn, wc_string s)
/* whether wide string 's' is a token in scanner group 'scn';
result: high = group index , low = token number ( > 0 ) or 0
assertion: Scn_groups(scn) > 0
*/
;
/* ------------------- Character iterator definition ---------------------- */
Scn_Stream_Itr Stream_Itr_new
(
int f_getc (StdCPtr file),
void f_close(StdCPtr file),
c_string f_wc2mb(wc_string wc),
LONG_INT f_seek (StdCPtr file, long offset, int origin),
StdCPtr file,
c_string fileid
)
/* creates and initializes a character iterator
onto the open character source 'file'
'f_getc' : next character
'f_close': closes character source
'f_wc2mb': converts wide to multibyte character
'f_seek' : positions character source
'fileid' : character source identifier
*/
;
void Stream_Itr_free(Scn_Stream_Itr itr); /* frees character iterator 'itr' */
/* ------------------------ Scan stream definition ------------------------ */
Scn_Stream Stream_bgn(Scn_T scn, Scn_Stream_Itr itr)
/* creates and initializes a scan stream
onto scanner 'scn' and character iterator 'itr'
*/
;
void Stream_close(Scn_Stream t)
/* closes character source i.e. file of scan stream 't' */
;
void Stream_free(Scn_Stream t); /* frees scan stream 't' */
void Stream_reset(Scn_Stream t)
/* re-initializes scan process in current scan stream 't' */
;
void Stream_premac_set(Scn_Stream t, Scn_PreMacFun cPreMac)
/* adds 'cPreMac' to scan stream 't'
for token preprocessing & macro expansion
*/
;
void Stream_eterm_set
(
Scn_Stream t, Abs_T CurPTCfg, Scn_eTerm eTerm, Scn_eAccept eAccept
)
/* adds 'eTerm', 'eAccept' and 'CurPTCfg' to scan stream 't'
for embedded language token construction
( deactivates other token concatenation )
*/
;
void Stream_add_ctxval(Scn_Stream t, Any_T id, Any_T val)
/* adds the context pair 'id' |--> 'val' to scan stream 't';
updates existing entries
*/
;
void Stream_concat_other(Scn_Stream t)
/* activates other token concatenation in scan stream 't' */
;
void Stream_skip_character(Scn_Stream t, int cC)
/* skips character 'cC' ( but tracks position ) */
;
void Stream_binmode_set(Scn_Stream t)
/* activates binary mode in scan stream 't'
( deactivates other token concatenation )
*/
;
Scn_Stream Stream_line
(
Scn_T scn, StdCPtr line, int (*cGet)(StdCPtr line), c_string id
)
#define STREAM_STDIN(scn) \
Stream_line(scn,stdin,(int (*)(StdCPtr f))fgetc,"