Skip to content

feat: semantic syntax highlights for pattern editor. #2214

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

Open
wants to merge 54 commits into
base: master
Choose a base branch
from

Conversation

paxcut
Copy link
Collaborator

@paxcut paxcut commented Apr 14, 2025

allows the ability to assign colors to global placed and non-placed variables, pattern, local and calculated pointer variables, template arguments, function variables and arguments, etc etc etc. It accomplishes this using the parser and the token sequence generated by the lexer. It still uses the original colorizing code but the underlying data holding the pattern has been updated to be easier to use and to debug. The changes are too numerous to cite here.It is a big but necessary step to bring the pattern editor to a somewhat useful state. There may be one commit in the pattern language repo needed to be able to run this code

paxcut and others added 30 commits September 29, 2024 20:20
If you set a breakpoint the first time you run the pattern it gets hit. After that subsequent runs will fail to hit the breakpoint.

fix: pressing F5 (start pattern execution ) while being in a breakpoint hangs ImHex.

The first bug was caused by two factors.
- When breakpoint hits evaluation stops before the line with the breakpoint is evaluated. In order to avoid hitting the breakpoint again when evaluation is continues the breakpoint needs to be disabled. Once the line is evaluated the breakpoint needs to be enabled again, but the previous code didn't do that.
- Detecting if the line was being evaluated used insufficient information to perform said detection. Because of the way AST nodes are assigned coordinates, Nodes that lie in other lines iof source code may and up sharing the same line number as the Nodes in the breakpoint. To tell them apart one must also use columns

The reason for hanging ImHex was that the shortcut procedure was not checking if the pattern was already running, and it attempted to start another one. This makes ImHex wait indefinitely for a lock to be released

To fix the first issue both problems were resolved. When evaluation of another line occurs the breakpoint is re-enabled. Note that at this point the full evaluation of the line may not have finish yet. This is of no concern as the second problem prevents triggering the breakpoint erroneously. By using the column of the position of the node we ensure that only valid evaluations of the node trigger the breakpoints.

To fix the hanging of ImHex we check the runtime for current evaluation and if detected we stop it. In all cases the evaluation is started again.
…hlights

# Conflicts:
#	plugins/builtin/source/content/views/view_pattern_editor.cpp
…ng cases were now broken and some cases that were not previously considered also didn't work. These changes aim mostly at fixing them.

Other changes include removing the color line encoding so that instead of writing the color and the length of the token it simply repeats the color the token length times. This helps to keep the char string and the color string synchronized as editing occurs using the line iterators which work on both strings simultaneously.

A new editing changes detection system ensures that lines that were colorized and didn't change  are not processed for coloring again in the text editor part of the coloring. When the text editor retrieves the colors for the identifiers ot compares it with the previous version and only makes changes if necessary.

The old system of changing only a few lines of the colors was broken because changes to syntax color can propagate and require changes more than a few lines away.

In order to avoid data races the pattern parsing and coloring wait fpr each other to finish before starting a new instance. A change in the editor raises a text changed event. The fast syntax coloring will occur simultaneously as the editor changes, but the semantic colors need to wait for the parser to finish so that it can use the resulting identifier types detected by the parser as a starting point to colorize the rest.

If more editing changes occur while the syntax highlighting code is running the new parsing task is not started until the colorizing is done so as not to corrupt the data that colorizing takes from the parser. Data races still occur so exception guards are in place to handle the ones that arise.

Old code that was commented out or not in use was removed. Changes for the parenthesis matching code is NOT included here but those changes do require these changes to be functional.
paxcut and others added 24 commits May 4, 2025 18:31
Also missing was some of the functionality added to master like printing strings with zeros in the console.
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

Successfully merging this pull request may close these issues.

1 participant