Port SMC parsing API to transitional syntax.
This commit is contained in:
+120
-77
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This file is part of the SourceMod/SourcePawn SDK.
|
||||
@@ -29,7 +29,7 @@
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
|
||||
#if defined _textparse_included
|
||||
#endinput
|
||||
#endif
|
||||
@@ -45,7 +45,7 @@
|
||||
/**
|
||||
* Parse result directive.
|
||||
*/
|
||||
enum SMCResult
|
||||
enum SMCResult:
|
||||
{
|
||||
SMCParse_Continue, /**< Continue parsing */
|
||||
SMCParse_Halt, /**< Stop parsing here */
|
||||
@@ -55,7 +55,7 @@ enum SMCResult
|
||||
/**
|
||||
* Parse error codes.
|
||||
*/
|
||||
enum SMCError
|
||||
enum SMCError:
|
||||
{
|
||||
SMCError_Okay = 0, /**< No error */
|
||||
SMCError_StreamOpen, /**< Stream failed to open */
|
||||
@@ -71,12 +71,117 @@ enum SMCError
|
||||
SMCError_InvalidProperty1, /**< A property was declared outside of any section */
|
||||
};
|
||||
|
||||
// Called when parsing is started.
|
||||
//
|
||||
// @param smc The SMC Parse Handle.
|
||||
typedef SMC_ParseStart = function void (SMCParser smc);
|
||||
|
||||
// Called when the parser is entering a new section or sub-section.
|
||||
//
|
||||
// Note: Enclosing quotes are always stripped.
|
||||
//
|
||||
// @param smc The SMC Parser.
|
||||
// @param name String containing section name.
|
||||
// @param opt_quotes True if the section name was quote-enclosed in the file.
|
||||
// @return An SMCResult action to take.
|
||||
typedef SMC_NewSection = function SMCResult (SMCParser smc, const char[] name, bool opt_quotes);
|
||||
|
||||
// Called when the parser finds a new key/value pair.
|
||||
//
|
||||
// Note: Enclosing quotes are always stripped.
|
||||
//
|
||||
// @param smc The SMCParser.
|
||||
// @param key String containing key name.
|
||||
// @param value String containing value name.
|
||||
// @param key_quotes Whether or not the key was enclosed in quotes.
|
||||
// @param value_quotes Whether or not the value was enclosed in quotes.
|
||||
// @return An SMCResult action to take.
|
||||
typedef SMC_KeyValue = function SMCResult (SMCParser smc, const char[] key, const char[] value, bool key_quotes, bool value_quotes);
|
||||
|
||||
// Called when the parser finds the end of the current section.
|
||||
//
|
||||
// @param smc The SMCParser.
|
||||
// @return An SMCResult action to take.
|
||||
typedef SMC_EndSection = function SMCResult (SMCParser smc);
|
||||
|
||||
// Called when parsing is halted.
|
||||
//
|
||||
// @param smc The SMCParser.
|
||||
// @param halted True if abnormally halted, false otherwise.
|
||||
// @param failed True if parsing failed, false otherwise.
|
||||
// @noreturn
|
||||
typedef SMC_ParseEnd = function void (SMCParser smc, bool halted, bool failed);
|
||||
|
||||
// Callback for whenever a new line of text is about to be parsed.
|
||||
//
|
||||
// @param smc The SMCParser.
|
||||
// @param line A string containing the raw line from the file.
|
||||
// @param lineno The line number it occurs on.
|
||||
// @return An SMCResult action to take.
|
||||
typedef SMC_RawLine = function SMCResult (SMCParser smc, const char[] line, int lineno);
|
||||
|
||||
// An SMCParser is a callback-driven parser for SourceMod configuration files.
|
||||
// SMC files are similar to Valve KeyValues format, with two key differences:
|
||||
// (1) SMC cannot handle single-item entries (that is, a key with no value).
|
||||
// (2) SMC files can have multi-line comment blocks, whereas KeyValues cannot.
|
||||
methodmap SMCParser < Handle
|
||||
{
|
||||
// Create a new SMC file format parser.
|
||||
public native SMCParser();
|
||||
|
||||
// Parses an SMC file.
|
||||
//
|
||||
// @param file A string containing the file path.
|
||||
// @param line An optional variable to store the last line number read.
|
||||
// @param col An optional variable to store the last column number read.
|
||||
// @return An SMCParseError result.
|
||||
public native SMCError ParseFile(const char[] file, int &line = 0, int &col = 0);
|
||||
|
||||
// Sets the callback for receiving SMC_ParseStart events.
|
||||
property SMC_ParseStart OnStart {
|
||||
public native set(SMC_ParseStart func);
|
||||
}
|
||||
|
||||
// Sets the callback for receiving SMC_ParseEnd events.
|
||||
property SMC_ParseEnd OnEnd {
|
||||
public native set(SMC_ParseEnd func);
|
||||
}
|
||||
|
||||
// Sets the callback for receiving SMC_NewSection events.
|
||||
property SMC_NewSection OnEnterSection {
|
||||
public native set(SMC_NewSection func);
|
||||
}
|
||||
|
||||
// Sets the callback for receiving SMC_EndSection events.
|
||||
property SMC_EndSection OnLeaveSection {
|
||||
public native set(SMC_EndSection func);
|
||||
}
|
||||
|
||||
// Sets the callback for receiving SMC_KeyValue events.
|
||||
property SMC_KeyValue OnKeyValue {
|
||||
public native set(SMC_KeyValue func);
|
||||
}
|
||||
|
||||
// Sets the callback for receiving SMC_RawLine events.
|
||||
property SMC_RawLine OnRawLine {
|
||||
public native set(SMC_RawLine func);
|
||||
}
|
||||
|
||||
// Gets an error string for an SMCError code.
|
||||
//
|
||||
// @param error The SMCParseError code.
|
||||
// @param buffer A string buffer for the error (contents undefined on failure).
|
||||
// @param buf_max The maximum size of the buffer.
|
||||
// @return The number of characters written to buffer.
|
||||
public native void GetErrorString(SMCError error, char[] buffer, int buf_max);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new SMC file format parser. This is used to set parse hooks.
|
||||
*
|
||||
* @return A new Handle to an SMC Parse structure.
|
||||
*/
|
||||
native Handle:SMC_CreateParser();
|
||||
native SMCParser SMC_CreateParser();
|
||||
|
||||
/**
|
||||
* Parses an SMC file.
|
||||
@@ -86,9 +191,9 @@ native Handle:SMC_CreateParser();
|
||||
* @param line An optional by reference cell to store the last line number read.
|
||||
* @param col An optional by reference cell to store the last column number read.
|
||||
* @return An SMCParseError result.
|
||||
* @error Invalid or corrupt Handle.
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0);
|
||||
native SMCError SMC_ParseFile(Handle smc, const char[] file, int &line=0, int &col=0);
|
||||
|
||||
/**
|
||||
* Gets an error string for an SMCError code.
|
||||
@@ -100,15 +205,7 @@ native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0);
|
||||
* @param buf_max The maximum size of the buffer.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max);
|
||||
|
||||
/**
|
||||
* Called when parsing is started.
|
||||
*
|
||||
* @param smc The SMC Parse Handle.
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SMC_ParseStart = function void (Handle smc);
|
||||
native bool SMC_GetErrorString(SMCError error, char[] buffer, int buf_max);
|
||||
|
||||
/**
|
||||
* Sets the SMC_ParseStart function of a parse Handle.
|
||||
@@ -116,19 +213,9 @@ typedef SMC_ParseStart = function void (Handle smc);
|
||||
* @param smc Handle to an SMC Parse.
|
||||
* @param func SMC_ParseStart function.
|
||||
* @noreturn
|
||||
* @error Invalid or corrupt Handle.
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func);
|
||||
|
||||
/**
|
||||
* Called when parsing is halted.
|
||||
*
|
||||
* @param smc The SMC Parse Handle.
|
||||
* @param halted True if abnormally halted, false otherwise.
|
||||
* @param failed True if parsing failed, false otherwise.
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SMC_ParseEnd = function void (Handle smc, bool halted, bool failed);
|
||||
native SMC_SetParseStart(Handle smc, SMC_ParseStart func);
|
||||
|
||||
/**
|
||||
* Sets the SMC_ParseEnd of a parse handle.
|
||||
@@ -136,41 +223,9 @@ typedef SMC_ParseEnd = function void (Handle smc, bool halted, bool failed);
|
||||
* @param smc Handle to an SMC Parse.
|
||||
* @param func SMC_ParseEnd function.
|
||||
* @noreturn
|
||||
* @error Invalid or corrupt Handle.
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func);
|
||||
|
||||
/**
|
||||
* Called when the parser is entering a new section or sub-section.
|
||||
* @note Enclosing quotes are always stripped.
|
||||
*
|
||||
* @param smc The SMC Parse Handle.
|
||||
* @param name String containing section name.
|
||||
* @param opt_quotes True if the section name was quote-enclosed in the file.
|
||||
* @return An SMCResult action to take.
|
||||
*/
|
||||
typedef SMC_NewSection = function SMCResult (Handle smc, const char[] name, bool opt_quotes);
|
||||
|
||||
/**
|
||||
* Called when the parser finds a new key/value pair.
|
||||
* @note Enclosing quotes are always stripped.
|
||||
*
|
||||
* @param smc The SMC Parse Handle.
|
||||
* @param key String containing key name.
|
||||
* @param value String containing value name.
|
||||
* @param key_quotes Whether or not the key was enclosed in quotes.
|
||||
* @param value_quotes Whether or not the value was enclosed in quotes.
|
||||
* @return An SMCResult action to take.
|
||||
*/
|
||||
typedef SMC_KeyValue = function SMCResult (Handle smc, const char[] key, const char[] value, bool key_quotes, bool value_quotes);
|
||||
|
||||
/**
|
||||
* Called when the parser finds the end of the current section.
|
||||
*
|
||||
* @param smc The SMC Parse Handle.
|
||||
* @return An SMCResult action to take.
|
||||
*/
|
||||
typedef SMC_EndSection = function SMCResult (Handle smc);
|
||||
native SMC_SetParseEnd(Handle smc, SMC_ParseEnd func);
|
||||
|
||||
/**
|
||||
* Sets the three main reader functions.
|
||||
@@ -179,25 +234,13 @@ typedef SMC_EndSection = function SMCResult (Handle smc);
|
||||
* @param ns An SMC_NewSection function pointer.
|
||||
* @param kv An SMC_KeyValue function pointer.
|
||||
* @param es An SMC_EndSection function pointer.
|
||||
* @noreturn
|
||||
*/
|
||||
native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es);
|
||||
|
||||
/**
|
||||
* Called whenever a raw line is read.
|
||||
*
|
||||
* @param smc The SMC Parse Handle.
|
||||
* @param line A string containing the raw line from the file.
|
||||
* @param lineno The line number it occurs on.
|
||||
* @return An SMCResult action to take.
|
||||
*/
|
||||
typedef SMC_RawLine = function SMCResult (Handle smc, const char[] line, int lineno);
|
||||
native void SMC_SetReaders(Handle smc, SMC_NewSection ns, SMC_KeyValue kv, SMC_EndSection es);
|
||||
|
||||
/**
|
||||
* Sets a raw line reader on an SMC parser Handle.
|
||||
*
|
||||
* @param smc Handle to an SMC Parse.
|
||||
* @param func SMC_RawLine function.
|
||||
* @noreturn
|
||||
*/
|
||||
native SMC_SetRawLine(Handle:smc, SMC_RawLine:func);
|
||||
native void SMC_SetRawLine(Handle smc, SMC_RawLine func);
|
||||
|
||||
Reference in New Issue
Block a user