Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recovery from bad input (syntax errors) #4

Closed
phreeplot opened this issue Sep 10, 2024 · 4 comments
Closed

Recovery from bad input (syntax errors) #4

phreeplot opened this issue Sep 10, 2024 · 4 comments

Comments

@phreeplot
Copy link

I've been testing forgex and so far it works well. My main issue is how it recovers from bad input. There are quite a few error_stops for bad input which is inconvenient when embedded in a larger program. I also found an infinite loop in syntax_tree_graph_m.F90 line 344-348 when an opening [ is not matched by a closing one ]. You also need to check something like self%tape%token_char.ne.'' to avoid this.

@ShinobuAmasaki
Copy link
Owner

I confirmed the infinite loop problem and would like to work on fixing this as soon as possible.

As for other bad patterns, I would like to consider a plan for error handling. Specifically, I thought of the following:

  • Provide an is_valid_regex function that determines whether a regular expression is valid or invalid, allowing for advance error handling.
  • For the .in. and .match. operators, return false for bad input patterns.
  • For the regex subroutine, add an optional argument to store the error code.

Here, we must be aware that these procedures are restricted by the pure attribute. Therefore, there is almost no way to communicate errors to the outside for these functions. Only the regex subroutine has the possibility of handling errors through arguments.

If you have any other ideas, I would be happy if you could share them.

@phreeplot
Copy link
Author

I think a PURE function can return a derived type. So you could make one something like

type match_result
logical :: match
integer :: start
integer :: end
logical :: error
character(:), allocatable :: error_message
end type match_result

@ShinobuAmasaki
Copy link
Owner

ShinobuAmasaki commented Sep 11, 2024

This idea is a good insight for me, but I prefer the simplicity of operators returning a logical type, so I would like to use it in the regex subroutine. This is because we cannot use a generic named procedure for functions that compose operators with the same type of arguments.

Furthermore, in a function that returns this derived type, I want to preserve the option to implement it with operator overloads for string operations (//, /=, ==, etc.) for the type.

@ShinobuAmasaki
Copy link
Owner

Recovery from bad input has been implemented slightly defferently than stated above. See release v4.0 and the latest README.md for details.

I consider this issue accomplished and will close it this week. Please let me know if you have any additional suggestions.

Thank you @phreeplot for your suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants