-
Notifications
You must be signed in to change notification settings - Fork 9
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
add :common
subpackage without libdparse
#54
Conversation
static Comment parse(string text, string[string] macros, bool removeUnknown, | ||
string delegate(string) highlightFn) | ||
out(retVal) | ||
{ | ||
assert(retVal.sections.length >= 2); | ||
} | ||
do | ||
{ | ||
import std.algorithm : find; | ||
import ddoc.macros : expand; | ||
|
||
auto sections = splitSections(text); | ||
string[string] sMacros = macros; | ||
auto m = sections.find!(p => p.name == "Macros"); | ||
const e = sections.find!(p => p.name == "Escapes"); | ||
auto p = sections.find!(p => p.name == "Params"); | ||
if (m.length) | ||
{ | ||
if (!doMapping(m[0])) | ||
throw new DdocParseException("Unable to parse Key/Value pairs", m[0].content); | ||
foreach (kv; m[0].mapping) | ||
sMacros[kv[0]] = kv[1]; | ||
} | ||
if (e.length) | ||
{ | ||
assert(0, "Escapes not handled yet"); | ||
} | ||
if (p.length) | ||
{ | ||
if (!doMapping(p[0])) | ||
throw new DdocParseException("Unable to parse Key/Value pairs", p[0].content); | ||
foreach (ref kv; p[0].mapping) | ||
kv[1] = expand(Lexer(highlightFn(kv[1])), sMacros, removeUnknown); | ||
} | ||
|
||
foreach (ref Section sec; sections) | ||
{ | ||
if (sec.name != "Macros" && sec.name != "Escapes" && sec.name != "Params") | ||
sec.content = expand(Lexer(highlightFn(sec.content)), sMacros, removeUnknown); | ||
} | ||
return Comment(sections); | ||
} | ||
} | ||
|
||
private: | ||
bool doMapping(ref Section s) | ||
{ | ||
import ddoc.macros : KeyValuePair, parseKeyValuePair; | ||
|
||
auto lex = Lexer(s.content); | ||
KeyValuePair[] pairs; | ||
if (parseKeyValuePair(lex, pairs)) | ||
{ | ||
foreach (idx, kv; pairs) | ||
s.mapping ~= kv; | ||
return true; | ||
} | ||
return false; | ||
} |
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 code is pure copy-paste from ddoc.comments, but changing the legacy parameter and making it more flexible with a callback.
* Copyright: © 2014 Economic Modeling Specialists, Intl. | ||
* Authors: Brian Schott, Mathias 'Geod24' Lang, Jan Jurzitza |
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 probably not accurate for a new file.
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.
most of the content is copy pasted, so I kept the authors
], | ||
"dependencies": { | ||
"libdparse": ">=0.13.0 <0.18.0" | ||
} | ||
"libdparse": ">=0.13.0 <1.0.0", |
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.
✅
adds ddoc.unhighlight and ddoc.types modules for more useful usage. Unhighlight can be used to emit embedded D code as-is, instead of parsing it and (potentially) causing issues as well as needing a dependency on libdparse. The ddoc.types module now contains the Comment struct that was in ddoc.comments and has a new parseUnexpanded call, which puts the split sections directly into the comment, without expanding, which is commonly used for example in D-Scanner to just check if a comment is `ditto` or contains some section with a given name.
Thank you for doing this! |
@WebFreak001 This seems to have broken something in libbdoc. I tried using the newest version of dscanner (that contains the version of libddoc with this PR), but ended up with an error [1]:
I think that the breakage comes from here:
Any ideas for a quick fix? |
hm no logic has changed though, all the old functions should still have the same execution. Do you know which file this happens on? |
yes, it is |
can't reproduce locally (issue with GC deallocating when memory is limited?) |
Have you tried running dscanner (commit: 2400d9c9e7763c264412048021d0bd8f977d7e0c) on phobos? (via make -f posix.mak dscanner). This fails on both my machine and the phobos testing pipeline |
oh I'll try that later, I tried |
I investigated this issue and this PR isn't the culprit. The issue might be with dscanner after all. |
It turns out dscanner starts failing phobos with the UTFException since: dlang-community/D-Scanner@a40492b . It looks like the libdparse upgrade introduced the regression. |
adds
ddoc.unhighlight
andddoc.types
modules for more useful usage. Unhighlight can be used to emit embedded D code as-is, instead of parsing it and (potentially) causing issues as well as needing adependency on libdparse.
The
ddoc.types
module now contains the Comment struct that was in ddoc.comments and has a newparseUnexpanded
andparse
call, which does what parseComment has done before, but with unhighlight, without expanding, which is commonly used for example in D-Scanner to just check if a comment isditto
or contains some section with a given name.With only minor modifications to D-Scanner just the
libddoc:common
subpackage can be used there, avoiding keeping libddoc libdparse up-to-date and synced.Makes the root libdparse version any version up to
<1.0.0
, because only tokenization is used and updates should not be needed that often. Having the separate common package makes it less likely that things will break for packages not needing libdparse, other packages will manually specify versions that will make ddoc use older versions if necessary.