parseerr.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. **********************************************************************
  3. * Copyright (C) 1999-2005, International Business Machines
  4. * Corporation and others. All Rights Reserved.
  5. **********************************************************************
  6. * Date Name Description
  7. * 03/14/00 aliu Creation.
  8. * 06/27/00 aliu Change from C++ class to C struct
  9. **********************************************************************
  10. */
  11. #ifndef PARSEERR_H
  12. #define PARSEERR_H
  13. #include "unicode/utypes.h"
  14. /**
  15. * \file
  16. * \brief C API: Parse Error Information
  17. */
  18. /**
  19. * The capacity of the context strings in UParseError.
  20. * @stable ICU 2.0
  21. */
  22. enum { U_PARSE_CONTEXT_LEN = 16 };
  23. /**
  24. * A UParseError struct is used to returned detailed information about
  25. * parsing errors. It is used by ICU parsing engines that parse long
  26. * rules, patterns, or programs, where the text being parsed is long
  27. * enough that more information than a UErrorCode is needed to
  28. * localize the error.
  29. *
  30. * <p>The line, offset, and context fields are optional; parsing
  31. * engines may choose not to use to use them.
  32. *
  33. * <p>The preContext and postContext strings include some part of the
  34. * context surrounding the error. If the source text is "let for=7"
  35. * and "for" is the error (e.g., because it is a reserved word), then
  36. * some examples of what a parser might produce are the following:
  37. *
  38. * <pre>
  39. * preContext postContext
  40. * "" "" The parser does not support context
  41. * "let " "=7" Pre- and post-context only
  42. * "let " "for=7" Pre- and post-context and error text
  43. * "" "for" Error text only
  44. * </pre>
  45. *
  46. * <p>Examples of engines which use UParseError (or may use it in the
  47. * future) are Transliterator, RuleBasedBreakIterator, and
  48. * RegexPattern.
  49. *
  50. * @stable ICU 2.0
  51. */
  52. typedef struct UParseError {
  53. /**
  54. * The line on which the error occured. If the parser uses this
  55. * field, it sets it to the line number of the source text line on
  56. * which the error appears, which will be be a value >= 1. If the
  57. * parse does not support line numbers, the value will be <= 0.
  58. * @stable ICU 2.0
  59. */
  60. int32_t line;
  61. /**
  62. * The character offset to the error. If the line field is >= 1,
  63. * then this is the offset from the start of the line. Otherwise,
  64. * this is the offset from the start of the text. If the parser
  65. * does not support this field, it will have a value < 0.
  66. * @stable ICU 2.0
  67. */
  68. int32_t offset;
  69. /**
  70. * Textual context before the error. Null-terminated. The empty
  71. * string if not supported by parser.
  72. * @stable ICU 2.0
  73. */
  74. UChar preContext[U_PARSE_CONTEXT_LEN];
  75. /**
  76. * The error itself and/or textual context after the error.
  77. * Null-terminated. The empty string if not supported by parser.
  78. * @stable ICU 2.0
  79. */
  80. UChar postContext[U_PARSE_CONTEXT_LEN];
  81. } UParseError;
  82. #endif