plugins/include/textparse.inc
author David Anderson <dvander@alliedmods.net>
Fri Aug 15 05:22:26 2008 +0000 (2008-08-15)
changeset 2226 d10b38524be3
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Landed sourcepawn-1.2. The big changes:

1) JIT compilation/optimization now occurs per-function, and only when functions are first used. We're now officially a whole-method JIT rather than an AOT compiler (albiet, still a simple JIT). This has two implications: Functions are now much better abstracted internally, and loading a plugin is now much less expensive. If a function contains calls to other functions, THOSE functions are only compiled when they're invoked as well.

2) I've removed debug mode. We always show full backtraces now, as there was a very cheap way to implement this which really cleaned up everything. This is great for a number of reasons -- there's less code, the JIT is better designed, we don't need to relocate debug tables, and best of all we no longer have to tell users to enable debug mode at their own expense.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _textparse_included
    34  #endinput
    35 #endif
    36 #define _textparse_included
    37 
    38 
    39 /********************************
    40  * Everything below describes the SMC Parse, or "SourceMod Configuration" format.
    41  * This parser is entirely event based.  You must hook events to receive data.
    42  * The file format itself is nearly identical to Valve's KeyValues format.
    43  ********************************/
    44 
    45 /**
    46  * Parse result directive.
    47  */
    48 enum SMCResult
    49 {
    50 	SMCParse_Continue,			/**< Continue parsing */
    51 	SMCParse_Halt,				/**< Stop parsing here */
    52 	SMCParse_HaltFail			/**< Stop parsing and return failure */
    53 };
    54 
    55 /**
    56  * Parse error codes.
    57  */
    58 enum SMCError
    59 {
    60 	SMCError_Okay = 0,			/**< No error */
    61 	SMCError_StreamOpen,		/**< Stream failed to open */
    62 	SMCError_StreamError,		/**< The stream died... somehow */
    63 	SMCError_Custom,			/**< A custom handler threw an error */
    64 	SMCError_InvalidSection1,	/**< A section was declared without quotes, and had extra tokens */
    65 	SMCError_InvalidSection2,	/**< A section was declared without any header */
    66 	SMCError_InvalidSection3,	/**< A section ending was declared with too many unknown tokens */
    67 	SMCError_InvalidSection4,	/**< A section ending has no matching beginning */
    68 	SMCError_InvalidSection5,	/**< A section beginning has no matching ending */
    69 	SMCError_InvalidTokens,		/**< There were too many unidentifiable strings on one line */
    70 	SMCError_TokenOverflow,		/**< The token buffer overflowed */
    71 	SMCError_InvalidProperty1,	/**< A property was declared outside of any section */
    72 };
    73 
    74 /**
    75  * Creates a new SMC file format parser.  This is used to set parse hooks.
    76  *
    77  * @return			A new Handle to an SMC Parse structure.
    78  */
    79 native Handle:SMC_CreateParser();
    80 
    81 /**
    82  * Parses an SMC file.
    83  *
    84  * @param smc			A Handle to an SMC Parse structure.
    85  * @param file			A string containing the file path.
    86  * @param line			An optional by reference cell to store the last line number read.
    87  * @param col			An optional by reference cell to store the last column number read.
    88  * @return				An SMCParseError result.
    89  * @error				Invalid or corrupt Handle. 
    90  */
    91 native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0);
    92 
    93 /**
    94  * Gets an error string for an SMCError code.
    95  * @note SMCError_Okay returns false.
    96  * @note SMCError_Custom (which is thrown on SMCParse_HaltFail) returns false.
    97  *
    98  * @param error			The SMCParseError code.
    99  * @param buffer		A string buffer for the error (contents undefined on failure).
   100  * @param buf_max		The maximum size of the buffer.
   101  * @return				True on success, false otherwise.
   102  */
   103 native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max);
   104 
   105 /**
   106  * Called when parsing is started.
   107  *
   108  * @param smc			The SMC Parse Handle.
   109  * @noreturn
   110  */
   111 functag SMC_ParseStart public(Handle:smc);
   112 
   113 /**
   114  * Sets the SMC_ParseStart function of a parse Handle.
   115  *
   116  * @param smc			Handle to an SMC Parse.
   117  * @param func			SMC_ParseStart function.
   118  * @noreturn
   119  * @error				Invalid or corrupt Handle. 
   120  */
   121 native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func);
   122 
   123 /**
   124  * Called when parsing is halted.
   125  *
   126  * @param smc			The SMC Parse Handle.
   127  * @param halted		True if abnormally halted, false otherwise.
   128  * @param failed		True if parsing failed, false otherwise.
   129  * @noreturn
   130  */
   131 functag SMC_ParseEnd public(Handle:smc, bool:halted, bool:failed);
   132 
   133 /**
   134  * Sets the SMC_ParseEnd of a parse handle.
   135  *
   136  * @param smc			Handle to an SMC Parse.
   137  * @param func			SMC_ParseEnd function.
   138  * @noreturn
   139  * @error				Invalid or corrupt Handle. 
   140  */
   141 native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func);
   142 
   143 /**
   144  * Called when the parser is entering a new section or sub-section.
   145  * @note Enclosing quotes are always stripped.
   146  *
   147  * @param smc			The SMC Parse Handle.
   148  * @param name			String containing section name.
   149  * @param opt_quotes	True if the section name was quote-enclosed in the file.
   150  * @return				An SMCResult action to take.
   151  */
   152 functag SMC_NewSection SMCResult:public(Handle:smc, const String:name[], bool:opt_quotes);
   153 
   154 /**
   155  * Called when the parser finds a new key/value pair.
   156  * @note Enclosing quotes are always stripped.
   157  *
   158  * @param smc			The SMC Parse Handle.
   159  * @param key			String containing key name.
   160  * @param value			String containing value name.
   161  * @param key_quotes	Whether or not the key was enclosed in quotes.
   162  * @param value_quotes	Whether or not the value was enclosed in quotes.
   163  * @return				An SMCResult action to take.
   164  */
   165 functag SMC_KeyValue SMCResult:public(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes);
   166 
   167 /**
   168  * Called when the parser finds the end of the current section.
   169  *
   170  * @param smc			The SMC Parse Handle.
   171  * @return				An SMCResult action to take.
   172  */
   173 functag SMC_EndSection SMCResult:public(Handle:smc);
   174 
   175 /**
   176  * Sets the three main reader functions.
   177  *
   178  * @param smc			An SMC parse Handle.
   179  * @param ns			An SMC_NewSection function pointer.
   180  * @param kv			An SMC_KeyValue function pointer.
   181  * @param es			An SMC_EndSection function pointer.
   182  * @noreturn
   183  */
   184 native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es);
   185 
   186 /**
   187  * Called whenever a raw line is read.
   188  *
   189  * @param smc			The SMC Parse Handle.
   190  * @param line			A string containing the raw line from the file.
   191  * @param lineno		The line number it occurs on.
   192  * @return				An SMCResult action to take.
   193  */
   194 functag SMC_RawLine SMCResult:public(Handle:smc, const String:line[], lineno);
   195 
   196 /**
   197  * Sets a raw line reader on an SMC parser Handle.
   198  *
   199  * @param smc			Handle to an SMC Parse.
   200  * @param func			SMC_RawLine function.
   201  * @noreturn
   202  */
   203 native SMC_SetRawLine(Handle:smc, SMC_RawLine:func);