Recent

Author Topic: Am I did it wrong all the time?  (Read 5131 times)

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Am I did it wrong all the time?
« Reply #30 on: February 26, 2020, 03:11:20 pm »
Thank you MarkMLl.

Otto.
Kind regards.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Am I did it wrong all the time?
« Reply #31 on: February 27, 2020, 10:10:13 am »
{$mode WrongWay(PleaseDoNotDoThis(Begin))} {$mode WrongWay(PleaseDoNotDoThis(End))}
they would be intended to enable and disable the generation of warnings about the type of syntax used: if it were not of the desired type it would generate a warnings.
I believe that such a thing can be achieved by analyzing the code by a parser program, launched at the end of the compilation.
Of course, the use of these directives should not affect the program generated by the build in any way.

What use would that serve? If there is code that uses a formatting that you don't intend you either fix it directly or ask the author to fix it. Adding some "post processing directives" will only serve that nothing is changed or that these drift away over time just like comments more often than not do.
If you want to avoid code being committed that does not follow your intended formatting you might be better helped with a commit hook in your version control system that runs a source code formatter and complains if something had to be adjusted or something like that...

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Am I did it wrong all the time?
« Reply #32 on: February 27, 2020, 05:07:10 pm »
@ PascalDragon

Thank you for your concern.

If you want to avoid code being committed that does not follow your intended formatting you might be better helped with a commit hook in your version control system that runs a source code formatter and complains if something had to be adjusted or something like that...
Could you suggest to me, politely, some guidance where to delve into that topic? I have little practice in the area you have indicated.

Here is a summary description of where my question originates. (I apologize in advance if it becomes unclear.)
I was commissioned to convert source codes (codes are closed), written in an internal corporate language, to a modern language. At the same time, a change in hardware architecture will be made.
I chose to use FPC as the target language.
I have no problem converting, and where necessary to correct and optimize, sources written with the old language to the FPC.
The problem is that the codes must be validated on the old architecture used previously for which the codes were written. So after I translate them into FPC I have to convert them back into the old language. Fortunately, a converter had already been written from a Pascal dialect to the old corporate language. Pascal's dialect uses a syntax of the type described in my previous post.

I had asked about the existence of custom directives to the FPC compiler, to avoid having to write an additional parser.
The use of tongue-in-cheek phrases to the comments was due to the fact that I would have preferred that the validation phase had not been necessary.

Otto.
Kind regards.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Am I did it wrong all the time?
« Reply #33 on: February 27, 2020, 05:16:51 pm »
One possibility would be to mark features as "deprecated" etc. until you're happy with them.

https://www.freepascal.org/docs-html/ref/refse5.html

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Am I did it wrong all the time?
« Reply #34 on: February 27, 2020, 05:57:54 pm »
Thank you, Mark.

I think you're right. I'm going to study your suggestion.

Otto.
Kind regards.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Am I did it wrong all the time?
« Reply #35 on: February 28, 2020, 09:14:13 am »
If you want to avoid code being committed that does not follow your intended formatting you might be better helped with a commit hook in your version control system that runs a source code formatter and complains if something had to be adjusted or something like that...
Could you suggest to me, politely, some guidance where to delve into that topic? I have little practice in the area you have indicated.

I don't know whether that would help for your usecase. Also I've never worked with these commit hooks myself, I only know that they exist and that they can be used for such functionality. Though there won't be a ready made solution.

Here is a summary description of where my question originates. (I apologize in advance if it becomes unclear.)
I was commissioned to convert source codes (codes are closed), written in an internal corporate language, to a modern language. At the same time, a change in hardware architecture will be made.
I chose to use FPC as the target language.
I have no problem converting, and where necessary to correct and optimize, sources written with the old language to the FPC.
The problem is that the codes must be validated on the old architecture used previously for which the codes were written. So after I translate them into FPC I have to convert them back into the old language. Fortunately, a converter had already been written from a Pascal dialect to the old corporate language. Pascal's dialect uses a syntax of the type described in my previous post.

I had asked about the existence of custom directives to the FPC compiler, to avoid having to write an additional parser.
The use of tongue-in-cheek phrases to the comments was due to the fact that I would have preferred that the validation phase had not been necessary.

You say there is a converter from Pascal to the old language. What you could do is the following: set up a commit hook for your version control system (again, I've never used such hooks, so you'll have to look them up yourself) that runs the converter on the code that is to be committed. If an error occurs in the converter then you abort the commit. This way you'd have pristine code in the repository, but it wouldn't stop you from experimenting locally.

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Am I did it wrong all the time?
« Reply #36 on: February 29, 2020, 10:46:50 am »
Hello.
Thank you PascalDragon for your commitment.
What you are suggesting is a very interesting method and deserves me to go into it. I believe, however, that I cannot apply it to my case as all the work is done off-line.
It may be the case that a new thread on the subject will be opened, surely there will be other users interested (two are already there).

Otto.
« Last Edit: February 29, 2020, 10:56:21 am by Otto »
Kind regards.

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Am I did it wrong all the time?
« Reply #37 on: March 02, 2020, 09:50:35 pm »
Hello everyone.
For someone who has a syntax problem, similar to the one described by me earlier in this thread, I report a simple solution that helped me solve my case.

I used the "Jedi Code Formatter" after enabling:
“Source>>Jedi Code Formatter>>Format Setting>>Clarify>>Transform>>Add begin and end to single statements”

simply press "Ctrl-D" to switch from (e.g.)

Code: Pascal  [Select][+][-]
  1. if a = 5 then
  2.     inc(a)
  3.   else
  4.     dec(a)  
  5.  
to
Code: Pascal  [Select][+][-]
  1.  if a = 5 then
  2.   begin
  3.     Inc(a);
  4.   end
  5.   else
  6.   begin
  7.     Dec(a);
  8.   end;      
  9.  


I hope it helps someone.

Otto.
« Last Edit: March 02, 2020, 09:59:19 pm by Otto »
Kind regards.

 

TinyPortal © 2005-2018