/src/lib/parse/parse_atom.e

http://github.com/tybor/Liberty · Specman e · 133 lines · 94 code · 11 blank · 28 comment · 2 complexity · 839a558486379c3a92120f39a9714241 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class PARSE_ATOM[C_ -> PARSE_CONTEXT]
  5. --
  6. -- A part of the PARSE_TABLE.
  7. --
  8. insert
  9. TRISTATE_VALUES
  10. PARSER_FACET
  11. feature {ANY}
  12. name: FIXED_STRING
  13. table: PARSE_TABLE[C_]
  14. is_coherent: BOOLEAN
  15. require
  16. table /= Void
  17. deferred
  18. ensure
  19. must_be_coherent: Result
  20. end
  21. pretty_print_on (stream: OUTPUT_STREAM)
  22. require
  23. stream.is_connected
  24. deferred
  25. end
  26. feature {PARSE_TABLE}
  27. set (a_name: ABSTRACT_STRING; a_table: like table)
  28. require
  29. name = Void
  30. table = Void
  31. not a_name.is_empty
  32. a_table /= Void
  33. do
  34. name := a_name.intern
  35. table := a_table
  36. ensure
  37. name = a_name.intern
  38. table = a_table
  39. end
  40. set_table (a_table: like table)
  41. require
  42. a_table /= Void
  43. do
  44. table := a_table
  45. ensure
  46. table = a_table
  47. end
  48. set_default_tree_builders (non_terminal_builder: PROCEDURE[TUPLE[FIXED_STRING, TRAVERSABLE[FIXED_STRING]]]; terminal_builder: PROCEDURE[TUPLE[FIXED_STRING, PARSER_IMAGE]])
  49. require
  50. is_coherent
  51. deferred
  52. end
  53. feature {PARSER_FACET}
  54. parse (context: C_): TRISTATE
  55. -- The Result is `yes' if the parsing succeeded, `no' if there was a syntax error, or `maybe' if the
  56. -- parse could complete with some more text.
  57. require
  58. context /= Void
  59. deferred
  60. ensure
  61. context.actions.count >= old context.actions.count
  62. ;(Result /= yes) implies context.buffer.current_index = old context.buffer.current_index and then context.actions.count = old context.actions.count
  63. end
  64. feature {}
  65. add_error_position (error: STRING; buffer: MINI_PARSER_BUFFER)
  66. local
  67. n, l, c: INTEGER
  68. do
  69. n := buffer.current_index
  70. from
  71. l := 1
  72. c := 1
  73. buffer.set_current_index(buffer.lower)
  74. until
  75. buffer.current_index = n
  76. loop
  77. if buffer.current_character = '%N' then
  78. l := l + 1
  79. c := 1
  80. else
  81. c := c + 1
  82. end
  83. buffer.next
  84. end
  85. if not error.is_empty then
  86. error.extend(' ')
  87. end
  88. error.append(once "at line ")
  89. l.append_in(error)
  90. error.append(once ", column ")
  91. c.append_in(error)
  92. end
  93. print_error_position (o: OUTPUT_STREAM; buffer: MINI_PARSER_BUFFER)
  94. local
  95. s: STRING
  96. do
  97. s := once ""
  98. s.clear_count
  99. add_error_position(s, buffer)
  100. o.put_string(s)
  101. end
  102. end -- class PARSE_ATOM
  103. --
  104. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  105. --
  106. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  107. -- of this software and associated documentation files (the "Software"), to deal
  108. -- in the Software without restriction, including without limitation the rights
  109. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  110. -- copies of the Software, and to permit persons to whom the Software is
  111. -- furnished to do so, subject to the following conditions:
  112. --
  113. -- The above copyright notice and this permission notice shall be included in
  114. -- all copies or substantial portions of the Software.
  115. --
  116. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  117. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  118. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  119. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  120. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  121. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  122. -- THE SOFTWARE.