parseerr.h 3.1 KB

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