class BACKTRACKING_REGULAR_EXPRESSION
Summary
Matcher for regular expressions
Direct parents
Inherit list: BACKTRACKING, REGULAR_EXPRESSION
Insert list: REGULAR_EXPRESSION_STRING_SCANNER
Class invariant
Overview
Creation features
{ANY}
Features
common
{ANY}
creation
{ANY}
backtracked search
{}
context management
{REGULAR_EXPRESSION_ITEM}
group facilities
{REGULAR_EXPRESSION_ITEM}
advancing the scan
{REGULAR_EXPRESSION_ITEM}
advancing the scan
{REGULAR_EXPRESSION_ITEM}
matching facilities
{REGULAR_EXPRESSION_ITEM}
positional predicates
{REGULAR_EXPRESSION_ITEM}
{ANY}
internal
{}
Common client features
{ANY}
Control of the exploration
{ANY}
Internal
{}
Specific to sequences
{ABSTRACT_BACKTRACKING_SEQUENCE}
Specific to alternatives
{ABSTRACT_BACKTRACKING_ALTERNATIVE}
internal: allocation and collection
{}
{ANY}
the pools
{ANY}
matching capabilities
{ANY}
substitution capabilities
{ANY}
Error informations
{ANY}
{}
{}
basic
{ANY}
error management
{ANY}
scanning
{ANY}
set_scanned_string (string: ABSTRACT_STRING)
effective procedure
{ANY}
Set 'scanned_string' to 'string'.
ensure
  • match_reset: not last_match_succeeded
  • has_no_error: not has_error
  • definition: scanned_string = string
  • at_the_begin: position = scanned_string.lower
last_match_succeeded: BOOLEAN
writable attribute
{ANY}
True if the last match (match_first or match_next) operation was a success.
group_count: INTEGER_32
writable attribute
{ANY}
The count of groups
invalidate_last_match
effective procedure
{ANY}
Used to prevent 2 substitutions without intermediate matching.
require(
  • True
) or else (
    • last_match_succeeded
) ensure
  • not last_match_succeeded
  • not can_substitute
basic_match_first
effective procedure
{ANY}
Starts to match and try to find the first substring of 'scanned_string' that matches the regular expression.
require ensure
basic_match_next
effective procedure
{ANY}
Continues to match and try to find the next substring of 'scanned_string' that matches the regular expression.
require ensure
match_from (text: ABSTRACT_STRING, first_index: INTEGER_32): BOOLEAN
effective function
{ANY}
Returns True if Current regular_expression can match the text starting from first_index.
require
  • text /= Void
  • first_index.in_range(text.lower, text.upper + 1)
  • save_matching_text(text)
ensure
  • Result = last_match_succeeded
  • Result implies valid_substrings(text)
  • Result implies last_match_first_index >= first_index
  • Result implies last_match_first_index.in_range(text.lower, text.upper + 1)
  • Result implies last_match_first_index <= last_match_last_index + 1
matches_only_current_position: BOOLEAN
writable attribute
{ANY}
Does the matching occur only from current position?
If that flag is True then:
  * if match succeeds then position is advanced
  * if match fails the position remains
see also 'goto_position'
set_matches_only_current_position (value: BOOLEAN)
effective procedure
{ANY}
Sets 'matches_only_current_position' to 'value'.
ensure
make
effective procedure
{ANY}
Creation.
effective procedure
{ANY}
Set the matched pattern.
require
  • valid_pattern: pattern.is_valid
ensure
root_node: BACKTRACKING_NODE
writable attribute
{}
The regular expression to be matched.
do_match
effective procedure
{}
Main matching routine.
Starting at the current position it tries to match the current scanned_string against the current regular expression.
require
context_type_frame: INTEGER_32
is -1
constant attribute
context_frame_cut: INTEGER_32
is -2
constant attribute
writable attribute
context_top: INTEGER_32
writable attribute
context_clear
effective procedure
Clear any saved context.
Called by the features clear and search_first.
context_push
effective procedure
Push the current context.
Called each time that an alternative begins.
context_restore
effective procedure
Restore the context to the last saved one.
The saved context MUST remain available for future use. Called each time that a new alternative (of the previous alternative point) is starting.
context_restore_and_pop
effective procedure
Restore the context to the last saved one and drop it.
The saved context MUST be removed. Called each time that the last alternative (of the previous alternative point) is starting. Should be similar to context_restore followed by context_cut.
context_cut
effective procedure
Remove the last saved context.
Called by cut, cut_all or cut_until.
set_group_first_index (group: INTEGER_32)
effective procedure
Records the beginning of a group.
require
set_group_last_index (group: INTEGER_32)
effective procedure
Records the end of a group.
require
clear_group (group: INTEGER_32)
effective procedure
Set 'group' to empty string.
clear_all_groups
effective procedure
Set all groups to empty string.
saved_look_position: INTEGER_32
writable attribute
the saved position for look ahead or look behind
begin_look_ahead
effective procedure
Begins to look-ahead.
require ensure
end_look_ahead
effective procedure
Terminates to look-ahead.
require ensure
begin_look_behind
effective procedure
Begins to look-behind.
require ensure
end_look_behind
effective procedure
Terminates to look-behind.
require ensure
direction: INTEGER_32
writable attribute
direction to advance (normal is +1, inverse is -1)
advance
effective procedure
Goes to the next character
require
advance_end_of_line
effective procedure
Skips the end of line.
Must be at end of a line.
require
match_character (char: CHARACTER)
effective procedure
If the character 'char' matches then advance and continue else backtrack.
match_character_no_case (char: CHARACTER)
effective procedure
If the character 'char' matches then advance and continue else backtrack.
Case does not care.
require
  • is_upper_character: char = char.to_upper
match_string (text: STRING)
effective procedure
If the string 'text' matches then advance and continue else backtrack.
match_string_no_case (text: STRING)
effective procedure
If the string 'text' matches then advance and continue else backtrack.
Case does not care.
match_previous_group (group: INTEGER_32)
effective procedure
If the previous 'group' matches then advance and continue else backtrack.
match_previous_group_no_case (group: INTEGER_32)
effective procedure
If the previous 'group' matches then advance and continue else backtrack.
Case does not care.
is_begin_of_text: BOOLEAN
effective function
True if at begin of the text
ensure
is_end_of_text (really: BOOLEAN): BOOLEAN
effective function
True if at end of the text
ensure
is_begin_of_line: BOOLEAN
effective function
True if at begin of a line
is_end_of_line: BOOLEAN
effective function
True if at end of a line
is_begin_of_word: BOOLEAN
effective function
True if at begin of a word
is_end_of_word: BOOLEAN
effective function
True if at end of a word
set_current_node (node: BACKTRACKING_NODE)
effective procedure
{ANY}
Sets the next node of the BACKTRACKING_NODE graph to evaluate.
ensure
push_and (node: BACKTRACKING_NODE)
effective procedure
{ANY}
Pushes node in front of the continuation path.
require
  • node_not_void: node /= Void
push_and_list (list: BACKTRACKING_NODE_AND_LIST)
effective procedure
{ANY}
Pushes list in front of the continuation path.
require
  • list_not_void: list /= Void
push_or (node: BACKTRACKING_NODE)
effective procedure
{ANY}
Pushes node in front of the possible alternatives.
require
  • node_not_void: node /= Void
push_or_list (list: BACKTRACKING_NODE_OR_LIST)
effective procedure
{ANY}
Pushes list in front of the possible alternatives.
require
  • list_not_void: list /= Void
current_node: BACKTRACKING_NODE
writable attribute
{}
Current node of the BACKTRACKING_NODE graph to be evaluated.
evaluate_current_state
effective procedure
{}
That feature is called to evaluate the current state
search_first
effective procedure
{ANY}
Resets all and searches the first solution.
The current state must be set. It is the first state, the root of the search. When the feature returns, 'search_is_success' must be checked to know if a solution was found. When search_is_success=False, it means that there is no solution at all. Conversely, if search_is_success=True, then the first solution is found and 'search_next' can be called to get the next solution if it exists.
ensure
search_next
effective procedure
{ANY}
Searches the next solution.
When the feature returns, 'search_is_success' must be checked to know if a solution was found. When search_is_success=False at the end, it means that there is no more solution. Conversely, if search_is_success=True, then a solution is found and 'search_next' can be called again to get the next solution.
require ensure
search_is_success: BOOLEAN
writable attribute
{ANY}
True when search is successful
is_off: BOOLEAN
effective function
{ANY}
True when search is finished
ensure
clear
effective procedure
{ANY}
Clears the current state to nothing.
ensure
is_cleared: BOOLEAN
effective function
{ANY}
True if no partial data remain in the current state
ensure
  • no_solution_when_cleared: Result implies is_off
push_sequence (sequence: ABSTRACT_BACKTRACKING_SEQUENCE)
effective procedure
{ANY}
Pushes the sequence in front of the continuation path.
require
  • sequence_not_void: sequence /= Void
ensure
push_alternative (alternative: ABSTRACT_BACKTRACKING_ALTERNATIVE)
effective procedure
{ANY}
Pushes the alternative before the continuation path.
require
  • alternative_not_void: alternative /= Void
ensure
continue
effective procedure
{ANY}
Continues the exploration of the current path.
backtrack
effective procedure
{ANY}
Stops the exploration of the current path and tries to explore the next alternative path.
push_cut_point
effective procedure
{ANY}
Inserts a cut point into the continuation path.
The inserted cut point records the current top of the alternatives.
cut
effective procedure
{ANY}
Removes the alternatives until the one recorded by the next cut point in the continuation path.
cut_all
effective procedure
{ANY}
Cuts all alternatives.
stop_search_loop: BOOLEAN
writable attribute
{}
True if at the end of a search.
This occurs if either a solution is found (and then search_is_success=True) or no solution is found (and then search_is_success=False). That feature should be modified only by continue and backtrack.
search
effective procedure
{}
Common search loop to search_first and search_next
cut_until (alternative: ABSTRACT_BACKTRACKING_ALTERNATIVE)
effective procedure
{}
Cut all alternatives until 'alternative'.
To cut an alternative is currently to remove it.
ensure
Stack of sequences represented by its top (can be Void)
current_continuation: ABSTRACT_BACKTRACKING_SEQUENCE
writable attribute
The current continuation path
pop_sequence
effective procedure
Removes the current sequence and replace it by the next sequence in the continuation path.
require
Stack of alternatives represented by its top (can be Void)
continue_alternative
effective procedure
Returns to the alternative on the top of the stack and put its saved continuation path as the current continuation path.
require ensure
pop_alternative
effective procedure
Returns to the alternative on the top of the stack and put its saved continuation path as the current continuation path.
Remove the alternative from the stack of alternatives. Same as continue_alternative but also removes the alternative.
require ensure
remove_top_sequence
effective procedure
{}
Removes the top sequence.
require ensure
remove_top_alternative
effective procedure
{}
Removes the top alternative.
require ensure
once function
{ANY}
Bank of cut points
once function
{ANY}
pool_of_sequence_list: BACKTRACKING_POOL_OF_SEQUENCE_LIST
once function
{ANY}
pool_of_alternative: BACKTRACKING_POOL_OF_ALTERNATIVE
once function
{ANY}
pool_of_alternative_list: BACKTRACKING_POOL_OF_ALTERNATIVE_LIST
once function
{ANY}
match (text: ABSTRACT_STRING): BOOLEAN
effective function
{ANY}
Returns True if Current regular_expression can match the text.
require ensure
match_next (text: ABSTRACT_STRING): BOOLEAN
effective function
{ANY}
Returns True if Current regular_expression can match the same text one more time.
Must be called after a successful match or math_from or match_next using the same text.
See also match, match_from, last_match_succeeded.
require ensure
last_match_first_index: INTEGER_32
effective function
{ANY}
The starting position in the text where starts the sub-string who is matching the whole pattern.
See also match, match_from.
require ensure
  • Result > 0
last_match_last_index: INTEGER_32
effective function
{ANY}
The last position in the text where starts the sub-string who is matching the whole pattern.
See also match, match_from.
require ensure
last_match_count: INTEGER_32
effective function
{ANY}
Length of the string matching the whole pattern.
group_names: TRAVERSABLE[FIXED_STRING]
effective function
{ANY}
The names of the matched named group.
ensure
has_group_name (name: ABSTRACT_STRING): BOOLEAN
effective function
{ANY}
Is there a group names name?
require
  • name /= Void
ith_group_matched (i: INTEGER_32): BOOLEAN
effective function
{ANY}
Did the ith group match during last match?
named_group_matched (name: ABSTRACT_STRING): BOOLEAN
effective function
{ANY}
Did the group named name match during the last match?
require
ith_group_first_index (i: INTEGER_32): INTEGER_32
effective function
{ANY}
First index in the last matching text of the ith group.
See also group_count.
require ensure
named_group_first_index (name: ABSTRACT_STRING): INTEGER_32
effective function
{ANY}
First index in the last matching text of the group named name.
See also group_names.
require
ith_group_last_index (i: INTEGER_32): INTEGER_32
effective function
{ANY}
Last index in the last matching text of the ith group.
require ensure
named_group_last_index (name: ABSTRACT_STRING): INTEGER_32
effective function
{ANY}
Last index in the last matching text of the group named name.
ith_group_count (i: INTEGER_32): INTEGER_32
effective function
{ANY}
Length of the ith group of Current in the last matching.
named_group_count (name: ABSTRACT_STRING): INTEGER_32
effective function
{ANY}
Length of the group named name in the last matching.
require ensure
for_all_matched_named_groups (text: ABSTRACT_STRING, action: PROCEDURE[TUPLE 2[FIXED_STRING, STRING]])
effective procedure
{ANY}
Call the action for each group that matched during the last match.
The first action argument is the name of the group; the second is its content. The order of the action calls is the ascending order of the group definitions in the pattern.
Note: the same STRING objects may be reused, so be sure to copy them if you want to keep them.
require
append_heading_text (text: ABSTRACT_STRING, buffer: STRING)
effective procedure
{ANY}
Append in buffer the text before the matching area.
text is the same as used in last matching.
See also append_pattern_text, append_tailing_text, append_ith_group.
require ensure
append_pattern_text (text: ABSTRACT_STRING, buffer: STRING)
effective procedure
{ANY}
Append in buffer the text matching the pattern.
text is the same as used in last matching.
See also append_heading_text, append_tailing_text, append_ith_group.
require ensure
append_tailing_text (text: ABSTRACT_STRING, buffer: STRING)
effective procedure
{ANY}
Append in buffer the text after the matching area.
text is the same as used in last matching.
See also append_heading_text, append_pattern_text, append_ith_group.
require ensure
append_ith_group (text: ABSTRACT_STRING, buffer: STRING, i: INTEGER_32)
effective procedure
{ANY}
Append in buffer the text of the ith group.
text is the same as used in last matching.
See also append_pattern_text, group_count.
require ensure
append_named_group (text: ABSTRACT_STRING, buffer: STRING, name: ABSTRACT_STRING)
effective procedure
{ANY}
Append in buffer the text of the group named name.
text is the same as used in last matching.
See also append_pattern_text, group_name.
require ensure
named_group_value (text: ABSTRACT_STRING, name: ABSTRACT_STRING): STRING
effective function
{ANY}
Returns the text of the group named name (always the same STRING!)
text is the same as used in last matching.
See also append_named_group, group_name.
require
prepare_substitution (p: ABSTRACT_STRING)
effective procedure
{ANY}
Set pattern p for substitution.
If pattern p is not compatible with the Current regular expression, the pattern_error_message is updated as well as pattern_error_position.
See also substitute_in, substitute_for, substitute_all_in, substitute_all_for.
require
  • p /= Void
ensure
last_substitution: STRING
effective function
{ANY}
You need to copy this STRING if you want to keep it.
substitute_for (text: ABSTRACT_STRING)
effective procedure
{ANY}
This call has to be preceded by a successful matching on the same text.
Then the substitution is made on the matching part. The result is in last_substitution.
See also prepare_substitution, last_substitution, substitute_in.
require ensure
substitute_in (text: STRING)
effective procedure
{ANY}
This call has to be preceded by a successful matching on the same text.
Then the substitution is made in text on the matching part (text is modified).
See also prepare_substitution, substitute_for.
require ensure
substitute_all_for (text: ABSTRACT_STRING)
effective procedure
{ANY}
Every matching part is substituted.
No preliminary matching is required. The result is in last_substitution.
See also prepare_substitution, last_substitution, substitute_all_in.
require ensure
substitute_all_in (text: STRING)
effective procedure
{ANY}
Every matching part is substituted.
No preliminary matching is required. text is modified according to the substitutions is any.
See also prepare_substitution, last_substitution, substitute_all_for.
require ensure
can_substitute: BOOLEAN
effective function
{ANY}
Substitution is only allowed when some valid substitution pattern has been registered and after a successful pattern matching.
substitution_pattern_ready: BOOLEAN
writable attribute
{ANY}
True if some valid substitution pattern has been registered.
pattern_error_message: STRING
writable attribute
{ANY}
Error message for the substitution pattern.
pattern_error_position: INTEGER_32
writable attribute
{ANY}
Error position in the substitution pattern.
save_matching_text (text: ABSTRACT_STRING): BOOLEAN
effective function
{}
Used in assertion only.
Side-effect: save the text
ensure
  • Result
    Assertion only feature

valid_substrings (text: ABSTRACT_STRING): BOOLEAN
effective function
{}
Used in assertion only.
require ensure
  • Result
    Method for assertion only (error position is element item i)

valid_substitution: BOOLEAN
effective function
{}
Used in assertion only.
ensure
  • Result
    Method for assertion only

substitute_all_without_tail (text: ABSTRACT_STRING): INTEGER_32
effective function
{}
Substitute all matching parts from text.
The resulting text in last_substitution, except the end. The part of text from Result up to the end is not copied.
require ensure
substrings_first_indexes: ARRAY[INTEGER_32]
writable attribute
{}
Item(0) is the starting position in the text where starts the substring who is matching the whole pattern.
Next elements are the starting positions in the text of substrings matching sub-elements of the pattern.
Elements before item(0) refers to positions in the substitution_pattern. They are stored in reverse order, the first verbatim string being at index -1, the second one at index -2...
substrings_last_indexes: ARRAY[INTEGER_32]
writable attribute
{}
The ending position of the string starting at position found in matching_position at the same index.
writable attribute
{}
The names of the groups, if those names exist
group_names_memory: COLLECTION[FIXED_STRING]
writable attribute
{}
Cache for group_names
substitution_pattern: STRING
once function
{}
compiled_substitution_pattern: FAST_ARRAY[INTEGER_32]
writable attribute
{}
This array describe the substitution text as a suite of strings from substrings_first_indexes.
last_match_text: STRING
effective function
{}
For assertion only.
set_group_names_memory
effective procedure
{}
last_match_text_memory: STRING
writable attribute
{}
For assertion only.
last_substitution_memory: STRING
writable attribute
{}
_inline_agent38 (s: FIXED_STRING): BOOLEAN
frozen
effective function
{}
_inline_agent39 (s: FIXED_STRING): BOOLEAN
frozen
effective function
{}
_inline_agent40 (s: FIXED_STRING): BOOLEAN
frozen
effective function
{}
_inline_agent41 (i: INTEGER_32, s: FIXED_STRING): BOOLEAN
frozen
effective function
{}
scanned_string: ABSTRACT_STRING
writable attribute
{ANY}
The expression being currently build.
has_error: BOOLEAN
writable attribute
{ANY}
True when an error was encountered
clear_error
effective procedure
{ANY}
Remove the error flag
ensure
last_error: STRING
effective function
{ANY}
Returns a string recorded for the error.
require ensure
  • not_void: Result /= Void
set_error (message: STRING)
effective procedure
{ANY}
Set has_error and last_error.
The explaining error string 'last_error' is created as follow: "Error at position 'position': 'message'.".
require
  • message_not_void: message /= Void
  • has_no_error: not has_error
ensure
position: INTEGER_32
writable attribute
{ANY}
The scanned position.
It is the position of 'last_character'.
last_character: CHARACTER
writable attribute
{ANY}
The scanned character.
The last character read from 'scanned_string'.
valid_last_character: BOOLEAN
writable attribute
{ANY}
True when 'last_character' is valid.
Is like 'scanned_string.valid_index(position)'
valid_previous_character: BOOLEAN
effective function
{ANY}
True if the position-1 is a valid position.
require ensure
previous_character: CHARACTER
effective function
{ANY}
The character at position-1.
require ensure
valid_next_character: BOOLEAN
effective function
{ANY}
True if the position+1 is a valid position.
require ensure
next_character: CHARACTER
effective function
{ANY}
The character at position+1.
require ensure
end_of_input: BOOLEAN
effective function
{ANY}
True when all the characters of 'scanned_string' are scanned.
ensure
goto_position (pos: INTEGER_32)
effective procedure
{ANY}
Change the currently scanned position to 'pos'.
Updates 'last_character' and 'valid_last_character' to reflect the new position value.
require ensure
read_character
effective procedure
{ANY}
Reads the next character.
require ensure
read_integer
effective procedure
{ANY}
Reads an integer value beginning at the currently scanned position.
The read value is stored in 'last_integer'.
require ensure
saved_position: INTEGER_32
writable attribute
{ANY}
The saved position (only one is currently enough).
save_position
effective procedure
{ANY}
Saves the current scanning position.
require ensure
restore_saved_position
effective procedure
{ANY}
Restore the scanning position to the last saved one.
ensure
last_string: STRING
writable attribute
{ANY}
A string buffer.
last_integer: INTEGER_32
writable attribute
{ANY}
An integer buffer.