~registry/gcalctool/trunk

« back to all changes in this revision

Viewing changes to src/prelexer.h

  • Committer: Robert Ancell
  • Date: 2012-10-14 03:31:40 UTC
  • Revision ID: git-v1:12ba2c81b0a81bb3ac776d1034a3c41b3173196a
Port to Vala

https://bugzilla.gnome.org/show_bug.cgi?id=640685

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef PRE_LEXER_H
2
 
#define PRE_LEXER_H
3
 
 
4
 
#include <glib.h>
5
 
 
6
 
/* Structure to store lexer state. */
7
 
typedef struct
8
 
{
9
 
    gchar* stream;              /* Pointer to the local copy of input string. */
10
 
    guint length;               /* Length of input string; stored to reduce calls to strlen(). */
11
 
    guint next_index;           /* Index of next (to be read) character from input. */
12
 
    guint mark_index;           /* Location, last marked. Useful for getting substrings as part of highlighting */
13
 
} PreLexerState;
14
 
 
15
 
/* Enum for tokens generated by pre-lexer and lexer. */
16
 
typedef enum
17
 
{
18
 
    T_UNKNOWN=0,                //Unknown
19
 
 
20
 
    /* These are all Pre-Lexer tokens, returned by pre-lexer */
21
 
    PL_DECIMAL,                 //Decimal saperator
22
 
    PL_DIGIT,                   //Decimal digit
23
 
    PL_HEX,                     //A-F of Hex digits
24
 
    PL_SUPER_DIGIT,             //Super digits
25
 
    PL_SUPER_MINUS,             //Super minus
26
 
    PL_SUB_DIGIT,               //Sub digits
27
 
    PL_FRACTION,                //Fractions
28
 
    PL_DEGREE,                  //Degree
29
 
    PL_MINUTE,                  //Minutes
30
 
    PL_SECOND,          //10    //Seconds
31
 
    PL_LETTER,                  //Alphabets
32
 
    PL_EOS,                     //End of stream. Yay!!
33
 
    PL_SKIP,                    //Skip this symbol (whitespace or newline).
34
 
 
35
 
    /* These are all tokens, returned by Lexer. */
36
 
    T_ADD,                      //Plus
37
 
    T_SUBTRACT,                 //Minus
38
 
    T_MULTIPLY,                 //Multiply
39
 
    T_DIV,                      //Divide (note can't use T_DIVIDE as it is defined in *BSD as an "integer divide fault" trap type value)
40
 
    T_MOD,                      //Modulus
41
 
    T_L_FLOOR,                  //Floor ( Left )
42
 
    T_R_FLOOR,          //20    //Floor ( Right )
43
 
    T_L_CEILING,                //Ceiling ( Left )
44
 
    T_R_CEILING,                //Ceiling ( Right )
45
 
    T_ROOT,                     //Square root
46
 
    T_ROOT_3,                   //Cube root
47
 
    T_ROOT_4,                   //Fourth root
48
 
    T_NOT,                      //Bitwise NOT
49
 
    T_AND,                      //Bitwise AND
50
 
    T_OR,                       //Bitwise OR
51
 
    T_XOR,                      //Bitwise XOR
52
 
    T_IN,               //30    //IN ( for converter )
53
 
    T_NUMBER,                   //Number
54
 
    T_SUP_NUMBER,               //Super Number
55
 
    T_NSUP_NUMBER,              //Negative Super Number
56
 
    T_SUB_NUMBER,               //Sub Number
57
 
    T_FUNCTION,                 //Function
58
 
    T_VARIABLE,                 //Variable name
59
 
    T_ASSIGN,                   //=
60
 
    T_L_R_BRACKET,      //40    //(
61
 
    T_R_R_BRACKET,              //)
62
 
    T_L_S_BRACKET,              //[
63
 
    T_R_S_BRACKET,              //]
64
 
    T_L_C_BRACKET,              //{
65
 
    T_R_C_BRACKET,              //}
66
 
    T_ABS,                      //|
67
 
    T_POWER,                    //^
68
 
    T_FACTORIAL,                //!
69
 
    T_PERCENTAGE        //49    //%
70
 
} LexerTokenType;
71
 
 
72
 
/* Creates a scanner state. Useful when multiple scanners are in action. */
73
 
PreLexerState* pl_create_scanner(const gchar*);
74
 
 
75
 
/* Destroy and free memory used by LexerState object. */
76
 
void pl_destroy_scanner(PreLexerState*);
77
 
 
78
 
/* Roll back last scanned unichar. */
79
 
void pl_roll_back(PreLexerState*);
80
 
 
81
 
/* Get validated gunichar from input stream. */
82
 
gunichar pl_get_next_gunichar(PreLexerState*);
83
 
 
84
 
/* Set marker index. To be used for highlighting and error reporting. */
85
 
void pl_set_marker(PreLexerState*);
86
 
 
87
 
/* Get marked substring. To be used for error reporting. */
88
 
gchar* pl_get_marked_substring(const PreLexerState*);
89
 
 
90
 
/* Get next Pre-Lexer token from stream. */
91
 
LexerTokenType pl_get_next_token(PreLexerState*);
92
 
 
93
 
#endif /* PRE_LEXER_H */