online
  B   	ˆl–Ãa¾”ji?u@?pÜŠbÑ¿Á„ ¿_†I|¥�+a–Ðz¾””ÔD¨ 	Å ‚nàS�ÿÆ '    	/*
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * See the COPYRIGHT file distributed with this work for additional
 * information regarding copyright ownership.
 */

#ifndef ISC_LEX_H
#define ISC_LEX_H 1

/*****
***** Module Info
*****/

/*! \file isc/lex.h
 * \brief The "lex" module provides a lightweight tokenizer.  It can operate
 * on files or buffers, and can handle "include".  It is designed for
 * parsing of DNS master files and the BIND configuration file, but
 * should be general enough to tokenize other things, e.g. HTTP.
 *
 * \li MP:
 *	No synchronization is provided.  Clients must ensure exclusive
 *	access.
 *
 * \li Reliability:
 *	No anticipated impact.
 *
 * \li Resources:
 *	TBS
 *
 * \li Security:
 *	No anticipated impact.
 *
 * \li Standards:
 * 	None.
 */

/***
 *** Imports
 ***/

#include <stdbool.h>
#include <stdio.h>

#include <isc/lang.h>
#include <isc/region.h>
#include <isc/types.h>

ISC_LANG_BEGINDECLS

/***
 *** Options
 ***/

/*@{*/
/*!
 * Various options for isc_lex_gettoken().
 */

#define ISC_LEXOPT_EOL	     0x0001 /*%< Want end-of-line token. */
#define ISC_LEXOPT_EOF	     0x0002 /*%< Want end-of-file token. */
#define ISC_LEXOPT_INITIALWS 0x0004 /*%< Want initial whitespace. */
#define ISC_LEXOPT_NUMBER    0x0008 /*%< Recognize numbers. */
#define ISC_LEXOPT_QSTRING   0x0010 /*%< Recognize qstrings. */
/*@}*/

/*@{*/
/*!
 * The ISC_LEXOPT_DNSMULTILINE option handles the processing of '(' and ')' in
 * the DNS master file format.  If this option is set, then the
 * ISC_LEXOPT_INITIALWS and ISC_LEXOPT_EOL options will be ignored when
 * the paren count is > 0.  To use this option, '(' and ')' must be special
 * characters.
 */
#define ISC_LEXOPT_DNSMULTILINE 0x0020 /*%< Handle '(' and ')'. */
#define ISC_LEXOPT_NOMORE	0x0040 /*%< Want "no more" token. */

#define ISC_LEXOPT_CNUMBER	    0x0080 /*%< Recognize octal and hex. */
#define ISC_LEXOPT_ESCAPE	    0x0100 /*%< Recognize escapes. */
#define ISC_LEXOPT_QSTRINGMULTILINE 0x0200 /*%< Allow multiline "" strings */
#define ISC_LEXOPT_OCTAL	    0x0400 /*%< Expect a octal number. */
#define ISC_LEXOPT_BTEXT	    0x0800 /*%< Bracketed text. */
#define ISC_LEXOPT_VPAIR	    0x1000 /*%< Recognize value pair. */
#define ISC_LEXOPT_QVPAIR	    0x2000 /*%< Recognize quoted value pair. */
/*@}*/
/*@{*/
/*!
 * Various commenting styles, which may be changed at any time with
 * isc_lex_setcomments().
 */

#define ISC_LEXCOMMENT_C	     0x01
#define ISC_LEXCOMMENT_CPLUSPLUS     0x02
#define ISC_LEXCOMMENT_SHELL	     0x04
#define ISC_LEXCOMMENT_DNSMASTERFILE 0x08
/*@}*/

/***
 *** Types
 ***/

/*! Lex */

typedef char isc_lexspecials_t[256];

/* Tokens */

typedef enum {
	isc_tokentype_unknown = 0,
	isc_tokentype_string = 1,
	isc_tokentype_number = 2,
	isc_tokentype_qstring = 3,
	isc_tokentype_eol = 4,
	isc_tokentype_eof = 5,
	isc_tokentype_initialws = 6,
	isc_tokentype_special = 7,
	isc_tokentype_nomore = 8,
	isc_tokentype_btext = 9,
	isc_tokentype_vpair = 10,
	isc_tokentype_qvpair = 11,
} isc_tokentype_t;

typedef union {
	char		 as_char;
	unsigned long	 as_ulong;
	isc_region_t	 as_region;
	isc_textregion_t as_textregion;
	void	     *as_pointer;
} isc_tokenvalue_t;

typedef struct isc_token {
	isc_tokentype_t	 type;
	isc_tokenvalue_t value;
} isc_token_t;

/***
 *** Functions
 ***/

isc_result_t
isc_lex_create(isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp);
/*%<
 * Create a lexer.
 *
 * 'max_token' is a hint of the number of bytes in the largest token.
 *
 * Requires:
 *\li	'*lexp' is a valid lexer.
 *
 * Ensures:
 *\li	On success, *lexp is attached to the newly created lexer.
 *
 * Returns:
 *\li	#ISC_R_SUCCESS
 *\li	#ISC_R_NOMEMORY
 */

void
isc_lex_destroy(isc_lex_t **lexp);
/*%<
 * Destroy the lexer.
 *
 * Requires:
 *\li	'*lexp' is a 