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

Added highlights.scm and slight changes to the grammar.js file #6

Merged
merged 6 commits into from
Oct 18, 2023
Merged

Added highlights.scm and slight changes to the grammar.js file #6

merged 6 commits into from
Oct 18, 2023

Conversation

osman362
Copy link
Contributor

Changes made to the grammar.js file

  • With Tree-Sitter you can create tests for the highlighting queries created
  • Tests are written as normal source code files that contain specially-formatted comments that make assertions about the surrounding syntax highlighting
  • The specially-formatted comments are line comments like the one in the grammar file but the function have to be named 'comment' to work correctly
  • Therefore the function name was changed to 'comment'
Block Comment
  • BLOCK_COMMENT was modified because the old version of the regex-code didn't work throughout different lines of code (only for one just like the line comment)
  • The new regex code for it was copied directly from MTillers 'comment' function inside his grammar.js file
Nodes
  • Underscores hide nodes inside a syntax tree were deleted to make highlight queries inside the highlight.scm file easier to write
  • Making parts of the syntax tree visible lead to adjusting the tests inside the test/corpus folder that were created to test the context-free grammar

Syntax Highlighting

  • Created the highlights.scm file
  • Added Queries to the file
  • The highlights query uses captures to assign arbitrary highlight names to different nodes in the tree.
  • Highlight names are assigned to each node

added the scope to modelica for tree-sitter to identify the language
added the file-type to ".mo" so that the grammar is used for files with
this ending
- Created highlights.scm file
- Added highglight queries
- Modified and sligth changes to the grammar.js file to make nodes
  such as 'expression' visible
- Therefore needed to adapt the tests in the corpus folder
- Renamed a2-3_Extends and a2-5_modifications in which .txt was added
  at the end to follow the tree-sitter conventions
Copy link
Member

@AnHeuermann AnHeuermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Can you add a few highlighting tests to test/highlight and describe how to use the syntax highlighting in the README.md?
Maybe you'll need to remove *.mo from .gitignore first, otherwise git doesn't want to add your Modelica tests.

@CLAassistant
Copy link

CLAassistant commented Oct 5, 2023

CLA assistant check
All committers have signed the CLA.

osman362 and others added 3 commits October 17, 2023 12:48
Created the example Modelica code SimpleMath to use for syntax
highlighting
Created the test files Resistor and SimpleEquation to show how the
highlighting is structured
Made equation list in If Equation and If Statement optional
@AnHeuermann AnHeuermann merged commit 643c481 into OpenModelica:master Oct 18, 2023
2 checks passed
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.

3 participants