Back to index

texmacs  1.0.7.15
packrat_grammar.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : packrat_grammar.hpp
00004 * DESCRIPTION: packrat grammars
00005 * COPYRIGHT  : (C) 2010  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef PACKRAT_GRAMMAR_H
00013 #define PACKRAT_GRAMMAR_H
00014 #include "packrat.hpp"
00015 #include "array.hpp"
00016 #include "hashmap.hpp"
00017 #include "resource.hpp"
00018 
00019 #ifdef HAVE_STDINT_H
00020 #include <stdint.h>
00021 #define C int32_t
00022 #define D int64_t
00023 #else
00024 #define C int
00025 #define D long long int
00026 #endif
00027 
00028 RESOURCE(packrat_grammar);
00029 
00030 /******************************************************************************
00031 * Important constants
00032 ******************************************************************************/
00033 
00034 #define PACKRAT_TOKENS      ((C)         0)
00035 #define PACKRAT_OR          ((C) 100000000)
00036 #define PACKRAT_CONCAT      ((C) 100000001)
00037 #define PACKRAT_WHILE       ((C) 100000002)
00038 #define PACKRAT_REPEAT      ((C) 100000003)
00039 #define PACKRAT_RANGE       ((C) 100000004)
00040 #define PACKRAT_NOT         ((C) 100000005)
00041 #define PACKRAT_EXCEPT      ((C) 100000006)
00042 #define PACKRAT_PARTIAL     ((C) 100000007)
00043 #define PACKRAT_TM_OPEN     ((C) 100000010)
00044 #define PACKRAT_TM_ANY      ((C) 100000011)
00045 #define PACKRAT_TM_ARGS     ((C) 100000012)
00046 #define PACKRAT_TM_LEAF     ((C) 100000013)
00047 #define PACKRAT_TM_CHAR     ((C) 100000014)
00048 #define PACKRAT_TM_CURSOR   ((C) 100000015)
00049 #define PACKRAT_TM_FAIL     ((C) 100000016)
00050 #define PACKRAT_SYMBOLS     ((C) 100000020)
00051 
00052 /******************************************************************************
00053 * Encoding of tokens and symbols
00054 ******************************************************************************/
00055 
00056 extern int               packrat_nr_tokens;
00057 extern int               packrat_nr_symbols;
00058 extern hashmap<string,C> packrat_tokens;
00059 extern hashmap<tree,C>   packrat_symbols;
00060 extern hashmap<C,tree>   packrat_decode;
00061 extern tree              packrat_uninit;
00062 
00063 C        encode_token  (string s);
00064 array<C> encode_tokens (string s);
00065 C        encode_symbol (tree t);
00066 
00067 /******************************************************************************
00068 * The packrat_grammar resource
00069 ******************************************************************************/
00070 
00071 struct packrat_grammar_rep: rep<packrat_grammar> {
00072   string                 lan_name;  // name of the packrat_grammar
00073   hashmap<C,array<C> >   grammar;
00074   hashmap<C,tree>        productions;
00075   hashmap<D,string>      properties;
00076 
00077   packrat_grammar_rep (string s);
00078 
00079   void accelerate (array<C>& def);
00080   array<C> define (tree t);
00081   void define (string s, tree t);  
00082   void set_property (string s, string var, string val);
00083   bool has_property (string s, string var);
00084   string get_property (string s, string var);
00085 
00086   string decode_as_string (C sym);
00087   array<string> decode_as_array_string (C sym);
00088   array<string> members (string s);
00089 };
00090 
00091 packrat_grammar find_packrat_grammar (string s);
00092 
00093 #endif // PACKRAT_GRAMMAR_H