-
-
Notifications
You must be signed in to change notification settings - Fork 422
Add support for arbitrary expressions as default values in documentation #1323
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -620,6 +620,82 @@ static void doc_type_params(docgen_t* docgen, docgen_opt_t* docgen_opt, | |
fprintf(docgen->type_file, "]"); | ||
} | ||
|
||
// Write the expression to the current type file. | ||
void doc_expression(docgen_t* docgen, docgen_opt_t* docgen_opt, ast_t* ast) | ||
{ | ||
FILE* fp = docgen->type_file; | ||
ast_t* child = ast_child(ast); | ||
token_id token = ast_id(ast); | ||
|
||
switch(token) | ||
{ | ||
case TK_CALL: | ||
case TK_CHAIN: | ||
case TK_DOT: | ||
case TK_SEQ: | ||
while(child != NULL) | ||
{ | ||
doc_expression(docgen, docgen_opt, child); | ||
child = ast_sibling(child); | ||
if (child != NULL) { | ||
if (token == TK_CHAIN) | ||
fprintf(fp, ".>"); | ||
|
||
if (token == TK_DOT) | ||
fprintf(fp, "."); | ||
|
||
if (token == TK_SEQ) | ||
fprintf(fp, "; "); | ||
} | ||
} | ||
if (token == TK_CALL) | ||
fprintf(fp, "()"); | ||
break; | ||
|
||
case TK_REFERENCE: | ||
doc_expression(docgen, docgen_opt, child); | ||
break; | ||
|
||
case TK_TYPE: | ||
case TK_INTERFACE: | ||
case TK_TRAIT: | ||
case TK_PRIMITIVE: | ||
case TK_STRUCT: | ||
case TK_CLASS: | ||
case TK_ACTOR: | ||
doc_type(docgen, docgen_opt, ast, false, false); | ||
break; | ||
|
||
case TK_NONE: | ||
break; | ||
|
||
case TK_STRING: | ||
{ | ||
char* escaped = ast_string_escape(ast); | ||
fprintf(fp, "\"%s\"", escaped); | ||
ponyint_pool_free_size(strlen(escaped) + 1, escaped); | ||
break; | ||
} | ||
|
||
case TK_RECOVER: | ||
fprintf(fp, "recover"); | ||
while(child != NULL) | ||
{ | ||
if (ast_id(child) != TK_NONE) { | ||
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 seems like the wrong way to tackle this. there could be other types later that we would be special casing for. that said, i dont immediately have an idea for a better way to address. |
||
fprintf(fp, " "); | ||
doc_expression(docgen, docgen_opt, child); | ||
} | ||
child = ast_sibling(child); | ||
} | ||
fprintf(fp, " end"); | ||
break; | ||
|
||
default: | ||
fprintf(fp, "%s", ast_get_print(ast)); | ||
break; | ||
} | ||
} | ||
|
||
// Write the given list of parameters to the current type file, with | ||
// surrounding (). If the given list is empty () is still written. | ||
static void code_block_doc_params(docgen_t* docgen, docgen_opt_t* docgen_opt, | ||
|
@@ -647,18 +723,9 @@ static void code_block_doc_params(docgen_t* docgen, docgen_opt_t* docgen_opt, | |
doc_type(docgen, docgen_opt, type, false, true); | ||
|
||
// if we have a default value, add it to the documentation | ||
if(ast_id(def_val) != TK_NONE) | ||
{ | ||
switch(ast_id(def_val)) | ||
{ | ||
case TK_STRING: | ||
fprintf(docgen->type_file, "= \"%s\"", ast_get_print(def_val)); | ||
break; | ||
|
||
default: | ||
fprintf(docgen->type_file, " = %s", ast_get_print(def_val)); | ||
break; | ||
} | ||
if(ast_id(def_val) != TK_NONE) { | ||
fprintf(docgen->type_file, " = "); | ||
doc_expression(docgen, docgen_opt, def_val); | ||
} | ||
} | ||
|
||
|
@@ -689,18 +756,9 @@ static void list_doc_params(docgen_t* docgen, docgen_opt_t* docgen_opt, | |
doc_type(docgen, docgen_opt, type, true, true); | ||
|
||
// if we have a default value, add it to the documentation | ||
if(ast_id(def_val) != TK_NONE) | ||
{ | ||
switch(ast_id(def_val)) | ||
{ | ||
case TK_STRING: | ||
fprintf(docgen->type_file, "= \"%s\"", ast_get_print(def_val)); | ||
break; | ||
|
||
default: | ||
fprintf(docgen->type_file, " = %s", ast_get_print(def_val)); | ||
break; | ||
} | ||
if(ast_id(def_val) != TK_NONE) { | ||
fprintf(docgen->type_file, " = "); | ||
doc_expression(docgen, docgen_opt, def_val); | ||
} | ||
|
||
fprintf(docgen->type_file, "\n"); | ||
|
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.
Where are call arguments handled?