-
Notifications
You must be signed in to change notification settings - Fork 0
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
Support nested categories #22
Merged
sungshik
merged 16 commits into
main
from
ignore-category-production-inside-category-production
Oct 22, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6300754
Simplify `isRecursive` to check if a symbol/production is recursive
sungshik ad9a60d
Simplify interface (type `Predicate`) to query dependency graphs
sungshik 350a015
Add function to query ancestors of a node in a dependency graph
sungshik a6d8bae
Fix issue to compute the length of labeled literals
sungshik d93eb34
Add analysis to convert only productions with an *active* category
sungshik 2298d07
Merge branch 'convert-semantic-token-types-to-textmate-scopes' into i…
sungshik 9ac4db3
Merge branch 'main' into ignore-category-production-inside-category-p…
sungshik 4a209dd
Add a new module to analyse categories
sungshik 52297f1
Add a new function to get the parents of a symbol in a grammar
sungshik eb9b78a
Add the new analysis of categories to the converter
sungshik 67dff03
Update tests
sungshik 0b35f6d
Add tests for nested categories
sungshik 562dc55
Clean up obsolete code
sungshik c1ededb
Rename function `lookup` to make its name more consistent with anothe…
sungshik a866514
Simplify boolean expression
sungshik 10284f9
Add editor config
sungshik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Editor configuration, see http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
max_line_length = 80 | ||
|
||
[*.sh] | ||
end_of_line = lf | ||
|
||
[*.java] | ||
indent_size = 4 | ||
max_line_length = 120 | ||
|
||
[*.rsc] | ||
indent_size = 4 | ||
max_line_length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
target | ||
node_modules | ||
node_modules | ||
|
||
src/main/rascal/Scratch.rsc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
rascal-textmate-core/src/main/rascal/lang/rascal/grammar/analyze/Categories.rsc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module lang::rascal::grammar::analyze::Categories | ||
|
||
import Grammar; | ||
import ParseTree; | ||
|
||
import lang::rascal::grammar::Util; | ||
|
||
@synopsis{ | ||
Special value to indicate that a production has no category | ||
} | ||
|
||
public str NO_CATEGORY = ""; | ||
|
||
@synopsis{ | ||
Gets a set of categories such that, for each category, there exists a string | ||
with that category produced by production `p`, as part of a string produced | ||
by a start production of grammar `g` | ||
} | ||
|
||
set[str] getCategories(Grammar g, Production p) | ||
= getCategoriesByProduction(g)[p]; | ||
|
||
@memo | ||
private map[Production, set[str]] getCategoriesByProduction(Grammar g) { | ||
map[Production, set[str]] ret = (p: {} | /p: prod(_, _, _) := g); | ||
|
||
void doGet(Production p, set[str] parentCategories) { | ||
set[str] categories = {c | /\tag("category"(str c)) := p}; | ||
|
||
set[str] old = ret[p]; | ||
set[str] new = _ <- categories ? categories : old + parentCategories; | ||
ret[p] = new; | ||
|
||
// If the new categories of `p` are different from the old ones, then | ||
// propagate these changes to the children of `p` | ||
for (old != new, /Symbol s := p.symbols, child <- prodsOf(g, delabel(s))) { | ||
doGet(child, new); | ||
} | ||
} | ||
|
||
// Propagate categories from the roots of the grammar | ||
for (root: prod(\start(_), _, _) <- ret) { | ||
doGet(root, {NO_CATEGORY}); | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a refactoring to make the code simpler (no more nested functions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
it can also be written as: