1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
/* (C) Copyright 2005, 2006, 2007, 2008, 2009 Stijn van Dongen
*
* This file is part of tingea. You can redistribute and/or modify tingea
* under the terms of the GNU General Public License; either version 3 of the
* License or (at your option) any later version. You should have received a
* copy of the GPL along with tingea, in the file COPYING.
*/
#ifndef tingea_tok
#define tingea_tok
#include <string.h>
#include "inttypes.h"
#include "types.h"
#include "list.h"
#include "ting.h"
/* This is a first sketchy attempt at some parse/tokenize routines.
* The scope is not very well defined yet. Should it do basic constructs
* only, or aim for more power, possibly aided by callbacks, and
* god forbid, a state description?
*
* TODO
* quoted strings not yet implemented!
* SGML not yet implemented!
*
* unify with mcxIOExpect, possibly stuff from ding.h
* wide chars?
*/
#define MCX_TOK_MODE_UNIX 1 /* Unix escapes, including esc newlines */
#define MCX_TOK_MODE_QUOTED 2 /* Quotes delimit tokens, hide brackets */
#define MCX_TOK_MODE_PLAIN 4
#define MCX_TOK_MODE_SGML 8 /* &code; other? */
#define MCX_TOK_DEL_WS 16 /* only delimiting whitespace */
/* Returns first character not matching fbool, NULL if none.
*/
char* mcxTokSkip
( const char* offset
, int (*fbool)(int c)
, ofs len
) ;
/*
* Accounts for nesting.
* Will do '}', ')', ']', '>', assuming one of several conventions.
*/
mcxstatus mcxTokMatch
( const char* offset
, char** end
, mcxbits mode
, ofs len /* considered if >= 0 */
) ;
/*
* Find some token, skipping over expressions.
* Either *pos == NULL and retval == STATUS_FAIL
* or *pos != NULL and retval == STATUS_OK
* or *pos != NULL and retval == STATUS_DONE
*/
mcxstatus mcxTokFind
( const char* offset
, char* tok /* Only tok[0] considered for now! */
, char** pos
, mcxbits mode
, ofs len /* considered if >= 0 */
) ;
/* fixme.
- document;
- add free routine.
- then perhaps optify.
*/
mcxLink* mcxTokArgs
( const char* str
, long str_len
, int* n_args
, mcxbits opts
) ;
typedef struct
{ mcxTing* key
; mcxLink* args
; mcxbits opts
;
} mcxTokFunc ;
void mcxTokFuncFree
( mcxTokFunc* tf
) ;
mcxstatus mcxTokExpectFunc
( mcxTokFunc* tf
, const char* str
, dim str_len
, char** z
, int n_min
, int n_max
, int *n_args
) ;
#endif
|