/* -----------------------------------------------------------------------------

 TeX parser ©1996 BURGHARD Eric
    ScanLib ©1996 Dietmar Eiler

 GoldED syntax parser library (uses a syntax cache).
 Highlight TeX instructions, comments, arguments, options, spell errors

 Standard header
 -------------------------------------------------------------------------------
*/

#ifndef FUNCS_H
#define FUNCS_H

// library functions
Prototype LibCall struct ParserData     *MountScanner(void);
Prototype LibCall ULONG                  StartScanner(register __a0 struct GlobalConfig *, register __a1 struct EditConfig *, register __d0 struct SyntaxChunk *);
Prototype LibCall ULONG                  CloseScanner(register __d0 ULONG);
Prototype LibCall void                   FlushScanner(register __d0 ULONG);
Prototype LibCall void                   SetupScanner(register __a0 struct GlobalConfig *);
Prototype LibCall struct RefreshRequest *BriefScanner(register __d0 ULONG, register __a0 struct ScannerNotify *);
Prototype LibCall struct SyntaxChunk    *ParseLine   (register __d0 ULONG, register __a0 struct LineNode *, register __d1 ULONG);
Prototype LibCall void                   UnparseLines(register __a0 struct LineNode *, register __d0 ULONG);
Prototype LibCall void                   ParseSection(register __d0 ULONG, register __a0 struct LineNode *, register __d1 ULONG);

// Locale function
Prototype LibCall STRPTR GetString(register __a0 struct LocaleInfo *, register __d0 LONG);

// ARexx function
Prototype ULONG *SendRexxCommand(UBYTE *, UBYTE *, struct MsgPort *, UBYTE *);

// Test tab
extern BYTE const words[256];

// Buffer handles are allocated for each text buffer to keep track of ressources:
struct BufferHandle {
    struct EditConfig     *bh_EditConfig;            // pointer to text data
    struct GlobalConfig   *bh_GlobalConfig;          // editor configuration
    struct SyntaxChunk    *bh_SyntaxStack;           // parser output
    struct RefreshRequest  bh_RefreshRequest;        // display refresh request
    struct MsgPort        *bh_ReplyPort;
    BOOL                   bh_ISpellCheck;           // is ISpell running ?
    UBYTE                  bh_Command[4096];         // ISpell command buffer
    UBYTE                  bh_Results[4096];         // ISpell result buffer
};

#define EMPTY_STACK ((struct SyntaxChunk *)~0)       // empty stack flag

// States of syntaxic analyser
#define INT  0
#define CHK  1
#define INS  2
#define INSD 3
#define INSH 4
#define ARG  5
#define ARGD 6
#define NBH  7
#define NBHD 8
#define NBO  9
#define NBOD 10
#define ASC  11
#define SIG 12
#define NBR  13
#define DEC  14
#define DECD 15
#define ASCD 16
#define END  17

// Number of syntaxic groups
#define CHKNBR 14
// Syntaxic groups
#define STDT 0      // Standard text
#define INTL 1      // Long instructions
#define INTS 2      // Short instructions
#define INTH 3      // Hidden instructions
#define GRPE 4      // Groups {}
#define OPTI 5      // Options []
#define NBRE 6      // Numbers
#define DIME 7      // Dimensions
#define COMM 8      // Comments
#define MATH 9      // Math mode
#define MTHS 10     // Lower - Exponent
#define INSC 11     // Uncutable car
#define MACA 12     // Macro arguments
#define ISPE 13     // ISpell error

// Macro for octal number test
#define isodigit(x) ((x <= '7') && (x >= '0'))
#define isword(x) (words[x])
#endif
