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

[Bug] import fail to parse dot syntax statement if it encounter a keyword #1639

Open
1 task
Naheulf opened this issue Apr 28, 2024 · 1 comment
Open
1 task
Labels
bug Something isn't working

Comments

@Naheulf
Copy link

Naheulf commented Apr 28, 2024

Operating System

Windows 10 x64

What's the issue you encountered?

Doing few refactor : tried to move a "match" related function to a dedicated file.
(Note: it's a Y part of a XY Problem, at first I tried to find a sugar way to be warned if an area with an unknown meaning have a new unseen value.

After moving the content to a new file and tried to import it I got that error.

E: error: Failed to resolve import: Could not find file tools
E: --> in D:\Users\Perso\Scripts\ImHex\includes\resident.pat:13:8
E: >> from :13:8
E: 13 | import tools.match;
E: ^^^^^
E: error: Expected ';' at end of statement, got Separator (.).
E: --> in D:\Users\Perso\Scripts\ImHex\includes\resident.pat:13:8
E: >> from :13:8
E: 13 | import tools.match;
E: ^^^^^
I: Evaluation took 0.129612s

How can the issue be reproduced?

Create a project.
Create the includes directory along the project file.
In that folder create a tools folder.
In the tool folder create a match.pat file (the file content does not matter, you can keep it empty)
In ImHex open any file or create an new one
In the pattern write import tools.match;
Click on the play button to evaluate the pattern.

ImHex Version

1.33.2

ImHex Build Type

  • Nightly or built from sources

Installation type

MSI

Additional context?

@Naheulf Naheulf added the bug Something isn't working label Apr 28, 2024
@paxcut
Copy link
Contributor

paxcut commented Apr 28, 2024

This is not a bug. When the import statement is tokenized each identifier separated by a dot becomes a token. Any token named 'match' must be a keyword token so tools.match cannot be resolved into the file match.pat located in the tools folder.

Note that in most languages (including c and c++) keywords cannot be used as identifiers either and pattern language is no exception. You can't use built-in type names as identifiers either. Valid identifiers must not be any of the keywords or built-in type names or named operators defined in the language and must start with a letter or '_' and can only contain alphanumeric chars and the '_' char.

Also note that

import "tools/match.pat";

is perfectly fine because the file name is a string so it is not broken into identifier tokens as the entire becomes a string token and string tokens can contain any char sequence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants