-
-
Notifications
You must be signed in to change notification settings - Fork 388
Automatically generate the grammar overview #2135
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ All unknown options are passed to the compiler. | |
| args = args[0..pos].chain("-".only, args[pos..$].dropOne).array; | ||
|
|
||
| // transform and extend the ddoc page | ||
| text = genGrammar(text); | ||
| text = genHeader(text); | ||
|
|
||
| // inject custom, "dynamic" macros | ||
|
|
@@ -194,3 +195,61 @@ auto genHeader(string fileText) | |
| return updateDdocTag(fileText, ddocKey, newContent); | ||
| } | ||
|
|
||
| // parse the menu from the Ddoc file | ||
| auto specTocEntries() | ||
| { | ||
| alias Entry = Tuple!(string, "name", string, "title", string, "fileName"); | ||
| Entry[] entries; | ||
|
|
||
| static immutable specDir = __FILE_FULL_PATH__.dirName.buildNormalizedPath("spec"); | ||
| static immutable mainFile = specDir.buildPath("./spec.ddoc"); | ||
|
|
||
| auto specText = mainFile.readText; | ||
| if (!specText.findSkip("SUBMENU2")) | ||
| writeln("Menu file has an invalid format."); | ||
| foreach (line; specText.splitter("\n")) | ||
| { | ||
| enum ddocEntryStart = "$(ROOT_DIR)spec/"; | ||
| if (line.find!(not!isWhite).startsWith(ddocEntryStart)) | ||
| { | ||
| auto ps = line.splitter(ddocEntryStart).dropOne.front.splitter(","); | ||
| auto name = ps.front.stripExtension.withExtension(".dd").to!string; | ||
| auto fileName = specDir.buildPath(name); | ||
| auto title = ps.dropOne.front.idup.strip; | ||
| entries ~= Entry(name, title, fileName); | ||
| } | ||
| } | ||
| return entries; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is copied from the footer generation. I plan to move the footer generation to this script too, see e.g. #2061 (but that isn't a top priority as the footer already exists and we don't add new pages frequently). |
||
|
|
||
| // Automatically generate spec/grammar | ||
| auto genGrammar(string fileText) | ||
| { | ||
| import std.uni : toLower; | ||
|
|
||
| enum ddocKey = "$(GRAMMAR_SUMMARY"; | ||
| auto newContent = ddocKey ~ "\n"; | ||
|
|
||
| if (fileText.canFind(ddocKey)) | ||
| { | ||
| foreach (i, entry; specTocEntries) | ||
| { | ||
| if (entry.fileName.endsWith("grammar.dd", "lex.dd", "simd.dd")) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| continue; | ||
|
|
||
| enum grammarKey = "$(GRAMMAR"; | ||
| auto text = entry.fileName.readText.find(grammarKey); | ||
| if (text.length) | ||
| newContent ~= "$(H2 $(LNAME2 %s, %s))\n".format(entry.title.toLower, entry.title); | ||
| for (; text.length; text = text[ grammarKey.length .. $].find(grammarKey)) | ||
| { | ||
| newContent ~= grammarKey; | ||
| newContent ~= text.drop(grammarKey.length).untilClosingParentheses.to!string; | ||
| newContent ~= ")\n"; | ||
| } | ||
| } | ||
| return updateDdocTag(fileText, ddocKey, newContent); | ||
| } | ||
| return fileText; | ||
| } | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.
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.
I would love to have
shift-frontandpopFrontin one step.