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

procedure definition rules are lagging function definition rules #578

Closed
imd1 opened this issue Apr 30, 2021 · 40 comments
Closed

procedure definition rules are lagging function definition rules #578

imd1 opened this issue Apr 30, 2021 · 40 comments

Comments

@imd1
Copy link
Contributor

imd1 commented Apr 30, 2021

Comparison of rules shows there are some useful function definition rules that have no equivalent for procedure definitions

@imd1
Copy link
Contributor Author

imd1 commented Jun 2, 2021

I'll make a start on this....

@imd1
Copy link
Contributor Author

imd1 commented Jun 2, 2021

Let's start with creating a function equivalent to procedure_006, as suggested by #595

@imd1
Copy link
Contributor Author

imd1 commented Jun 2, 2021

will work on branch issue-578 in my fork...

@imd1
Copy link
Contributor Author

imd1 commented Jun 2, 2021

Creating function_300 as equivalent to procedure_006....

@jeremiah-c-leary
Copy link
Owner

I looked at your changes on your branch and it looks good. The rest should hopefully be just about as easy.

@imd1
Copy link
Contributor Author

imd1 commented Jun 2, 2021

Some function rules that have no procedure equivalent (part 1)

  • function_002 (space after function keyword)
  • function_003 (space between function name and opening bracket)
    • for procedures, the opening bracket may not exist?
  • function_004 (case of begin)
  • function_005 (function keyword case)

@imd1
Copy link
Contributor Author

imd1 commented Jun 2, 2021

creating procedure_100 as equivalent to function_002...

@imd1
Copy link
Contributor Author

imd1 commented Jun 3, 2021

creating procedure_101 as equivalent to function_003....

@imd1
Copy link
Contributor Author

imd1 commented Jun 3, 2021

@jeremiah-c-leary : is there a rule that deals with procedure proc1 is and procedure proc1; in terms of whitespace after proc1?

@jeremiah-c-leary
Copy link
Owner

so a space between proc1 and is, while removing whitespace between proc1 and ;?

@jeremiah-c-leary
Copy link
Owner

for the first case you could use single_space_between_tokens
for the second case you could use remove_tokens_bounded_by_tokens_and_remove_trailing_whitespace or remove_spaces_before_token_rule.

To find a corresponding rule that uses the base rules, I use this command: find . -name -exec grep -iH single_space_between_tokens {} \;

Then copy one of those rules to the new one.

@jeremiah-c-leary
Copy link
Owner

If you wanted, you could write a remove_whitespace_between_tokens rule.

@imd1
Copy link
Contributor Author

imd1 commented Jun 4, 2021

just realised that the suggestion of looking at the block rules is relevant for procedures, so it is looking like scrapping procedure_101 and making procedure_100 more like block_100....

@imd1
Copy link
Contributor Author

imd1 commented Jun 4, 2021

Propose to create a procedure_101 that follows the idea of block_101, for consistency

@imd1
Copy link
Contributor Author

imd1 commented Jun 4, 2021

Now move onto case rules procedure_5xx inspired by block_5xx...

  • 500 = case of procedure
  • 501 = case of procedure name
  • 502 = case of is
  • 503 = case of begin
  • 504 = case of end
  • 505 = case of procedure
  • 506 = case of procedure name

@imd1
Copy link
Contributor Author

imd1 commented Jun 4, 2021

Creating procedure_200 equivalent to function_006....

@imd1
Copy link
Contributor Author

imd1 commented Jun 5, 2021

Continuing populating procedure_2xx inspired by block_2xx...

  • 201 = blank line below procedure (make that is instead)
  • 202 = blank line above begin
  • 203 = blank line below begin
  • 204 = blank line or comments above end
  • 205 = blank line below ; (equiv to function_007)

@imd1
Copy link
Contributor Author

imd1 commented Jun 5, 2021

Note: will need to go though the docs sections and add links from configuration pages back to rules, the link the other way is natural...

@imd1
Copy link
Contributor Author

imd1 commented Jun 5, 2021

function_012 does not seem to have a matching procedure rule?

  • procedure_401

@imd1
Copy link
Contributor Author

imd1 commented Jun 5, 2021

function_009 and 010 do not seem to have procedure equivalents....

  • creating procedure_011 as equivalent to function_009
  • creating procedure_507 as equivalent to function_010

@imd1
Copy link
Contributor Author

imd1 commented Jun 7, 2021

Reached a point where there are two things left...

  • examine procedure rules added that go beyond function rules, and bring functions up to date so both are roughly equivalent
  • tidy up docs as suggested above

@jeremiah-c-leary
Copy link
Owner

examine procedure rules added that go beyond function rules

If you look at the LRM:

subprogram_declaration ::=
    subprogram_specification ;

subprogram_specification ::=
    procedure_specification | function_specification

procedure_specification ::=
    procedure designator
        subprogram_header
        [ [ parameter ] ( formal_parameter_list ) ]

function_specification ::=
    [ pure | impure ] function designator
        subprogram_header
        [ [ parameter ] ( formal_parameter_list ) ] return type_mark

subprogram_body ::=
    subprogram_specification is
        subprogram_declarative_part
    begin
        subprogram_statement_part
    end [ subprogram_kind ] [ designator ] ;

You could add these rules:

  1. case of is keyword
  2. begin keyword on it's own line
  3. end keyword on it's own line
  4. is keyword not on it's own line
  5. case of parameter keyword
  6. case of return keyword
  7. return keyword not on it's own line
  8. optional existence of subprogram_kind
  9. optional existence of designator in the subprogram body
  10. semicolon not on it's own line.
  11. single space between end keyword and subprogram_kind
  12. single space between subprogram_kind and designator
  13. case of pure keyword
  14. case of impure keyword
  15. single space after pure keyword
  16. single space after impure keyword
  17. single space after parameter keyword
  18. single space before return keyword
  19. type_mark not on it's own line
  20. single space between return keyword and type_mark
  21. no code after is keyword
  22. no code after begin keyword

It seems there is a never ending list of possible rules.

@imd1
Copy link
Contributor Author

imd1 commented Jun 16, 2021

examine procedure rules added that go beyond function rules

If you look at the LRM:

subprogram_declaration ::=
    subprogram_specification ;

subprogram_specification ::=
    procedure_specification | function_specification

procedure_specification ::=
    procedure designator
        subprogram_header
        [ [ parameter ] ( formal_parameter_list ) ]

function_specification ::=
    [ pure | impure ] function designator
        subprogram_header
        [ [ parameter ] ( formal_parameter_list ) ] return type_mark

subprogram_body ::=
    subprogram_specification is
        subprogram_declarative_part
    begin
        subprogram_statement_part
    end [ subprogram_kind ] [ designator ] ;

You could add these rules:

  1. case of is keyword
  2. begin keyword on it's own line
  3. end keyword on it's own line
  4. is keyword not on it's own line
  5. case of parameter keyword
  6. case of return keyword
  7. return keyword not on it's own line
  8. optional existence of subprogram_kind
  9. optional existence of designator in the subprogram body
  10. semicolon not on it's own line.
  11. single space between end keyword and subprogram_kind
  12. single space between subprogram_kind and designator
  13. case of pure keyword
  14. case of impure keyword
  15. single space after pure keyword
  16. single space after impure keyword
  17. single space after parameter keyword
  18. single space before return keyword
  19. type_mark not on it's own line
  20. single space between return keyword and type_mark
  21. no code after is keyword
  22. no code after begin keyword

It seems there is a never ending list of possible rules.

I think this goes beyond the scope of the ticket :-)

@imd1
Copy link
Contributor Author

imd1 commented Jun 17, 2021

Let's look at procedure rules > 99 to look for rules added there for which there are missing function rules....

@imd1
Copy link
Contributor Author

imd1 commented Jun 17, 2021

  • we could add function equivalents to procedure 100 and 101
  • however 100 overlaps (and extends) function rules 002 and 003, so not sure how proceed with this
    • if we add 100 and make it default to disabled?
    • can we make 002 and 003 depreciated?
      @jeremiah-c-leary : what is your view on this?

@imd1
Copy link
Contributor Author

imd1 commented Jun 17, 2021

Looked at procedure_2xx:

  • 200 is equivalent to function 006
  • 205 is equivalent to function 007
  • 201, 202, 203 and 204 have no function equivalents, so we could add some rules under function_2xx for these

@imd1
Copy link
Contributor Author

imd1 commented Jun 17, 2021

Looked at procedure_4xx:

  • 401 is derived from an existing function rule, so nothing to do

@imd1
Copy link
Contributor Author

imd1 commented Jun 17, 2021

Looked at procedure_5xx:

  • only 502 and 506 do not have equivalent function rules, so we could add some rules under function_5xx

@imd1
Copy link
Contributor Author

imd1 commented Jun 17, 2021

So we can work on function rules:

  • 201, 202, 203, 204
  • 502, 506
  • 101 and possibly 100

@jeremiah-c-leary
Copy link
Owner

jeremiah-c-leary commented Jun 18, 2021

  • we could add function equivalents to procedure 100 and 101

  • however 100 overlaps (and extends) function rules 002 and 003, so not sure how proceed with this

    • if we add 100 and make it default to disabled?
    • can we make 002 and 003 depreciated?
      @jeremiah-c-leary : what is your view on this?

With functions and procedures being nearly identical, I would opt for depricating 002 and 003 and making function_100 equivalent to procedure_100. Also, when I originally started this I just made up rules as I ran into issues in my code instead of having a solid plan for defining the rules. So if we could make the rules more coherent between function and procedure I am all for it.

I did add a method to depricate rules. If you look at instantiation_030:

1
2 from vsg.depricated_rule import Depricated
3
4
5 class rule_030(Depricated):
6
7     def __init__(self):
8         Depricated.__init__(self, 'instantiation', '030')
9         self.message.append('Rule ' + self.unique_id + ' has been renamed to generic_map_007.')

you would just copy that rule to procedure_002, change 030 to 002 and update the message on line 9.
If someone has an existing configuration that attempts to configure procedure_002, they will get an error and the message will be printed out.

Maybe something like: Rule function_002 has been merged into rule function_100.

I can not really think of a reason not to combine all of the single space checks into the single rule.

@jeremiah-c-leary
Copy link
Owner

Looked at procedure_2xx:

  • 200 is equivalent to function 006
  • 205 is equivalent to function 007
  • 201, 202, 203 and 204 have no function equivalents, so we could add some rules under function_2xx for these

Agree. Ideally with the same number to reduce confusion. I think it would be fine to skip function_200. Or we take this opportunity to align all the rules. That may be too much change though. Do you have an opinion?

@jeremiah-c-leary
Copy link
Owner

Looked at procedure_4xx:

  • 401 is derived from an existing function rule, so nothing to do

Agree

@jeremiah-c-leary
Copy link
Owner

Looked at procedure_5xx:

  • only 502 and 506 do not have equivalent function rules, so we could add some rules under function_5xx

Agree

@imd1
Copy link
Contributor Author

imd1 commented Jun 18, 2021

Looked at procedure_2xx:

  • 200 is equivalent to function 006
  • 205 is equivalent to function 007
  • 201, 202, 203 and 204 have no function equivalents, so we could add some rules under function_2xx for these

Agree. Ideally with the same number to reduce confusion. I think it would be fine to skip function_200. Or we take this opportunity to align all the rules. That may be too much change though. Do you have an opinion?

Too much change, leave for the future....

@imd1
Copy link
Contributor Author

imd1 commented Jun 18, 2021

Working on function_201,202,203,204....

@imd1
Copy link
Contributor Author

imd1 commented Jun 18, 2021

Working on function 502, 506

@imd1
Copy link
Contributor Author

imd1 commented Jun 20, 2021

Working on rule 101

@imd1
Copy link
Contributor Author

imd1 commented Jun 20, 2021

Working on rule 100

@imd1
Copy link
Contributor Author

imd1 commented Jun 20, 2021

working on depricating function_002/003

@imd1
Copy link
Contributor Author

imd1 commented Jun 20, 2021

done, PR raised

@jeremiah-c-leary jeremiah-c-leary added this to To do in Release 3.3.0 via automation Sep 26, 2021
@jeremiah-c-leary jeremiah-c-leary moved this from To do to Done in Release 3.3.0 Sep 26, 2021
jeremiah-c-leary added a commit that referenced this issue Sep 28, 2021
Updating jcl style tests to accomidate additional function fules.

  1)  Updated fixed versions of two files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants