michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1999-2005, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Date Name Description michael@0: * 03/14/00 aliu Creation. michael@0: * 06/27/00 aliu Change from C++ class to C struct michael@0: ********************************************************************** michael@0: */ michael@0: #ifndef PARSEERR_H michael@0: #define PARSEERR_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Parse Error Information michael@0: */ michael@0: /** michael@0: * The capacity of the context strings in UParseError. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: enum { U_PARSE_CONTEXT_LEN = 16 }; michael@0: michael@0: /** michael@0: * A UParseError struct is used to returned detailed information about michael@0: * parsing errors. It is used by ICU parsing engines that parse long michael@0: * rules, patterns, or programs, where the text being parsed is long michael@0: * enough that more information than a UErrorCode is needed to michael@0: * localize the error. michael@0: * michael@0: *

The line, offset, and context fields are optional; parsing michael@0: * engines may choose not to use to use them. michael@0: * michael@0: *

The preContext and postContext strings include some part of the michael@0: * context surrounding the error. If the source text is "let for=7" michael@0: * and "for" is the error (e.g., because it is a reserved word), then michael@0: * some examples of what a parser might produce are the following: michael@0: * michael@0: *

michael@0:  * preContext   postContext
michael@0:  * ""           ""            The parser does not support context
michael@0:  * "let "       "=7"          Pre- and post-context only
michael@0:  * "let "       "for=7"       Pre- and post-context and error text
michael@0:  * ""           "for"         Error text only
michael@0:  * 
michael@0: * michael@0: *

Examples of engines which use UParseError (or may use it in the michael@0: * future) are Transliterator, RuleBasedBreakIterator, and michael@0: * RegexPattern. michael@0: * michael@0: * @stable ICU 2.0 michael@0: */ michael@0: typedef struct UParseError { michael@0: michael@0: /** michael@0: * The line on which the error occured. If the parser uses this michael@0: * field, it sets it to the line number of the source text line on michael@0: * which the error appears, which will be be a value >= 1. If the michael@0: * parse does not support line numbers, the value will be <= 0. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t line; michael@0: michael@0: /** michael@0: * The character offset to the error. If the line field is >= 1, michael@0: * then this is the offset from the start of the line. Otherwise, michael@0: * this is the offset from the start of the text. If the parser michael@0: * does not support this field, it will have a value < 0. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t offset; michael@0: michael@0: /** michael@0: * Textual context before the error. Null-terminated. The empty michael@0: * string if not supported by parser. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UChar preContext[U_PARSE_CONTEXT_LEN]; michael@0: michael@0: /** michael@0: * The error itself and/or textual context after the error. michael@0: * Null-terminated. The empty string if not supported by parser. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UChar postContext[U_PARSE_CONTEXT_LEN]; michael@0: michael@0: } UParseError; michael@0: michael@0: #endif