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

Error during parsing #207

Open
vickysharma0812 opened this issue Oct 2, 2021 · 15 comments
Open

Error during parsing #207

vickysharma0812 opened this issue Oct 2, 2021 · 15 comments

Comments

@vickysharma0812
Copy link

vickysharma0812 commented Oct 2, 2021

Thank you very much for FLS and its support in VS Code.
I am using FLS-v1.12.0

I use Fortran module in my project.

If the name of the module is IntVector_Method.F90
Then the name of submodules are IntVector_Method@submodule1.F90, IntVector_Method@submodule2.F90, and so on.

I receive following error from FLS.

Initialization failed for file "/home/vikassharma/Dropbox/easifem/easifem-base/src/submodules/IntVector/src/IntVector_Method@getMethod.F90": Error during parsing

How can remove this error?

Regards
Vikas

@gnikit
Copy link

gnikit commented Oct 2, 2021

Hi @vickysharma0812 could you provide a Minimal Working Example so that the issue can be replicated?

@vickysharma0812
Copy link
Author

Hello @gnikit
Sorry for the late response.

Please find the attached directory.
It also contains the screen shot of problem.

fls_vikas_issue.zip
Regards
Vikas

@vickysharma0812
Copy link
Author

@gnikit I want to ask whether FLS supports SUBMODULE feature of Modern Fortran?

Regards
Vikas

@gnikit
Copy link

gnikit commented Oct 4, 2021

So both the fortran language server and the Modern Fortran extension support submodules, as far as I know at least.
I had a look at your example and I am not entirely convinced that it is compilable code. Would you mind elaborating a bit how you compile and what are you trying to accomplish?

On a separate matter, fortls should not be failing catastrophically like it currently is. The traceback reads

Traceback (most recent call last):
  File "~/pip-dev/fortls/langserver.py", line 1264, in update_workspace_file
    ast_new = process_file(file_obj, True, pp_defs=self.pp_defs, include_dirs=self.include_dirs)
  File "~/pip-dev/fortls/parse_fortran.py", line 1538, in process_file
    new_smod = fortran_submodule(file_ast, line_number, obj_info.name, ancestor_name=obj_info.parent)
  File "~/pip-dev/fortls/objects.py", line 753, in __init__
    self.base_setup(file_ast, line_number, name)
  File "~/pip-dev/fortls/objects.py", line 538, in base_setup
    self.FQSN = self.name.lower()
AttributeError: 'NoneType' object has no attribute 'lower'

This is most definitely a bug which is triggered by using a space character between the base module's name and the right parenthesis in the submodule definition i.e.

This breaks

submodule(baseModule ) submodule1

This works

submodule(baseModule) submodule1

@vickysharma0812
Copy link
Author

vickysharma0812 commented Oct 4, 2021

So both the fortran language server and the Modern Fortran extension support submodules, as far as I know at least.

Yes, your are right here. I face no problem with Modern Fortran extension. I don't know much about FLS.

I had a look at your example and I am not entirely convinced that it is compilable code. Would you mind elaborating a bit how you compile and what are you trying to accomplish?

The process of compiling the code is given below.

Step-1: Compile foo_module.F90, it will create .mod and .smod files.

gfortran -c foo_module.F90
├── call_foo.F90
├── foo_module.F90
├── foo_module.mod   <--------
├── foo_module.o <------
├── foo_module.smod <-------
├── foo_module@submodule1.F90
├── foo_module_submodule2.F90
└── Screenshot from 2021-10-02 23-07-24.pngfg

Step-2: Compile submodules, it will create

gfortran -c foo_module@submodule1.F90
gfortran -c foo_module_submodule2.F90

Output:

├── call_foo.F90
├── foo_module.F90
├── foo_module.mod
├── foo_module.o
├── foo_module.smod
├── foo_module@submodule1.F90
├── foo_module@submodule1.o <---------------
├── foo_module@submodule1.smod <--------------
├── foo_module_submodule2.F90
├── foo_module@submodule2.smod <--------------
├── foo_module_submodule2.o <--------------
└── Screenshot from 2021-10-02 23-07-24.png

Step:3 compile call_Foo.F90

gfortran -c call_foo.F90 -I.

Output

.
├── call_foo.F90
├── call_foo.o <-----------
├── foo_module@display.smod
├── foo_module.F90
├── foo_module.mod
├── foo_module.o
├── foo_module.smod
├── foo_module@submodule1.F90
├── foo_module@submodule1.o
├── foo_module@submodule1.smod
├── foo_module_submodule2.F90
├── foo_module_submodule2.o
└── Screenshot from 2021-10-02 23-07-24.png

Linking:

gfortran -o test.out call_foo.o foo_module@submodule1.o foo_module_submodule2.o foo_module.o 

Executing:

./test.out

Output

testing :: hello::world
testing :: hello::world

@vickysharma0812
Copy link
Author

@gnikit thank you for responding.

Would you mind elaborating a bit how you compile and what are you trying to accomplish?

In my project I keep the header definition in modules and implementations in submodules.

  • It leads to better code management.
  • Compilation time decreases.
  • Modules can call each other.

Regards
Vikas

@gnikit
Copy link

gnikit commented Oct 4, 2021

@vickysharma0812 did you try removing the trailing whitespace between the base module foo_module and the closing parenthesis )?

@gnikit
Copy link

gnikit commented Oct 4, 2021

I am not sure what I was doing last night and I couldn't compile your MWE, thanks for the instructions all seems to work on my end. Try the fix I mentioned, for the time being at least. I will have a look when I get some time.

BTW as a general note you mind want to incorporate a formatter into your workflow findent and fprettify are good IMO and can be installed through Python's pip

@vickysharma0812
Copy link
Author

@gnikit
Thank you for your message.
Your trick works well 👍🏼 💯

I have installed findent and fprettify

Can I ask what do they do?

Regards
Vikas

@gnikit
Copy link

gnikit commented Oct 4, 2021

@vickysharma0812

Your trick works well 👍🏼
Glad to hear it

I have installed findent and fprettify
Can I ask what do they do?

They are formatters, so they make your code easier to read and look pretty findent and fprettify you only need one of the too. I simply mentioned them because the bug you stumbled upon was due to formatting.

@vickysharma0812
Copy link
Author

@gnikit Thanks, I have uninstall findent, and kept only fprettify.

gnikit referenced this issue in fortran-lang/fortls Dec 20, 2021
The regex for submodule parent names was too greedy only
matching patterns at the start of the string.
@gnikit
Copy link

gnikit commented Dec 20, 2021

@vickysharma0812 I have gone ahead and issued a fix for this under a dev version of fortls.

@JHenneberg
Copy link
Contributor

@gnikit: It seems you are frequently updating fortls on your side. Is there any chance that you are gonna release your own version over python? I guess you tried to communicate with hansec to merge your development? Sry for beeing offtopic.

@gnikit
Copy link

gnikit commented Dec 21, 2021

Hi @JHenneberg, I tried contacting hansec to update this repo instead of making a fork but I suspect that he is extremely busy with work that's why I went ahead and released the dev version of fortls under the name fortls in PyPi which you can install by pip install fortls. I think I updated the README on my fork yesterday with install instructions etc.

Given that it has been a while since all of this happened and a lot of changes have occured in the codebase, the fork has now diverged substantially from the main fortran-language-server repository which means it is unlikely I will be opening another PR in future to incorporate the changes from dev to master.

@JHenneberg
Copy link
Contributor

@gnikit I see. Great I will give your version a try. Overlooked the install instruction probably. Thanks for your effort.

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

3 participants