Compare commits
7 Commits
3bb3dc94ab
...
1d7e48e094
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 1d7e48e094 | |
Tristan B. Velloza Kildaire | 52f7e3a5ab | |
Tristan B. Velloza Kildaire | 992e96ce79 | |
Tristan B. Velloza Kildaire | df2e28da92 | |
Tristan B. Velloza Kildaire | d876eab69d | |
Tristan B. Velloza Kildaire | 48f9b2659f | |
Tristan B. Velloza Kildaire | ec143553cf |
|
@ -509,7 +509,7 @@ public final class BasicLexer : LexerInterface
|
|||
while (true) {
|
||||
if (!multiLine && currentChar == LS.NEWLINE) {
|
||||
flush();
|
||||
return advanceLine();
|
||||
return true;
|
||||
}
|
||||
if (multiLine && currentChar == LS.STAR && isForward() && sourceCode[position+1] == LS.FORWARD_SLASH) {
|
||||
buildAdvance();
|
||||
|
|
|
@ -2289,96 +2289,6 @@ public final class Parser
|
|||
WARN("parseComment(): Leave");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the handling of comments
|
||||
*/
|
||||
unittest
|
||||
{
|
||||
import tlang.compiler.lexer.kinds.arr : ArrLexer;
|
||||
|
||||
try
|
||||
{
|
||||
string sourceCode = `module myCommentModule;
|
||||
// Hello`;
|
||||
|
||||
File dummyFile;
|
||||
Compiler compiler = new Compiler(sourceCode, "legitidk.t", dummyFile);
|
||||
|
||||
compiler.doLex();
|
||||
compiler.doParse();
|
||||
|
||||
// FIXME: Re-enable when we we have
|
||||
// a way to extract comments from
|
||||
// AST nodes
|
||||
// assert(parser.hasCommentsOnStack());
|
||||
// assert(parser.getCommentCount() == 1);
|
||||
}
|
||||
catch(TError e)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
string sourceCode = `module myCommntedModule;
|
||||
/*Hello */
|
||||
|
||||
/* Hello*/`;
|
||||
|
||||
File dummyFile;
|
||||
Compiler compiler = new Compiler(sourceCode, "legitidk.t", dummyFile);
|
||||
|
||||
compiler.doLex();
|
||||
compiler.doParse();
|
||||
|
||||
// FIXME: Re-enable when we we have
|
||||
// a way to extract comments from
|
||||
// AST nodes
|
||||
// assert(parser.hasCommentsOnStack());
|
||||
// assert(parser.getCommentCount() == 1);
|
||||
}
|
||||
catch(TError e)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
string sourceCode = `module myCommentedModule;
|
||||
|
||||
void function()
|
||||
{
|
||||
/*Hello */
|
||||
/* Hello */
|
||||
// Hello
|
||||
//Hello
|
||||
}
|
||||
`;
|
||||
|
||||
File dummyFile;
|
||||
Compiler compiler = new Compiler(sourceCode, "legitidk.t", dummyFile);
|
||||
|
||||
compiler.doLex();
|
||||
compiler.doParse();
|
||||
|
||||
|
||||
// FIXME: Re-enable when we we have
|
||||
// a way to extract comments from
|
||||
// AST nodes
|
||||
// assert(parser.hasCommentsOnStack());
|
||||
// assert(parser.getCommentCount() == 1);
|
||||
// assert(parser.hasCommentsOnStack());
|
||||
// assert(parser.getCommentCount() == 4);
|
||||
}
|
||||
catch(TError e)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: We need to add `parseComment()`
|
||||
// support here (see issue #84)
|
||||
// TODO: This ic currently dead code and ought to be used/implemented
|
||||
|
@ -3748,4 +3658,104 @@ unittest
|
|||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comments tests
|
||||
*/
|
||||
unittest
|
||||
{
|
||||
string sourceCode = `
|
||||
module comments;
|
||||
|
||||
// Comment for no one
|
||||
|
||||
// Comment for Elise
|
||||
int p;
|
||||
|
||||
/**
|
||||
* This is a comment on a function
|
||||
*
|
||||
*
|
||||
* @param i This is the i
|
||||
* @param p This is the p
|
||||
* @throws Exception worst exception eva
|
||||
* @return Void, so nothing
|
||||
*/
|
||||
void function(int i, int p)
|
||||
{
|
||||
|
||||
}
|
||||
`;
|
||||
|
||||
File dummyFile;
|
||||
Compiler compiler = new Compiler(sourceCode, "legitidk.t", dummyFile);
|
||||
|
||||
try
|
||||
{
|
||||
compiler.doLex();
|
||||
assert(true);
|
||||
}
|
||||
catch(LexerException e)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
compiler.doParse();
|
||||
Program program = compiler.getProgram();
|
||||
|
||||
// There is only a single module in this program
|
||||
Module modulle = program.getModules()[0];
|
||||
|
||||
TypeChecker tc = new TypeChecker(compiler);
|
||||
|
||||
/* Find the variable named `p` and get its comment */
|
||||
Entity varEnt = tc.getResolver().resolveBest(modulle, "p");
|
||||
Variable var = cast(Variable)varEnt;
|
||||
Comment varComment = var.getComment();
|
||||
assert(varComment);
|
||||
assert(varComment.getContent() == "Comment for Elise");
|
||||
|
||||
/* Find the function named `function` and get its comment */
|
||||
Entity funcEnt = tc.getResolver().resolveBest(modulle, "function");
|
||||
Function func = cast(Function)funcEnt;
|
||||
Comment funcComment = func.getComment();
|
||||
assert(funcComment);
|
||||
|
||||
/* Ensure the comment is as we want */
|
||||
DEBUG(funcComment.getContent());
|
||||
assert(funcComment.getContent() == "This is a comment on a function ");
|
||||
|
||||
ParamDoc* iPDoc, pPDoc;
|
||||
ParamDoc[string] paramDocs = funcComment.getAllParamDocs();
|
||||
assert((iPDoc = "i" in paramDocs) !is null);
|
||||
assert((pPDoc = "p" in paramDocs) !is null);
|
||||
assert(iPDoc.getParam() == "i");
|
||||
assert(iPDoc.getDescription() == "This is the i");
|
||||
assert(pPDoc.getParam() == "p");
|
||||
assert(pPDoc.getDescription() == "This is the p");
|
||||
|
||||
ExceptionDoc eDoc;
|
||||
bool found;
|
||||
foreach(DocStr dc; funcComment.getDocStrings())
|
||||
{
|
||||
if((found = dc.getExceptionDoc(eDoc)) == true)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(found);
|
||||
assert(eDoc.getException() == "Exception");
|
||||
assert(eDoc.getDescription() == "worst exception eva");
|
||||
|
||||
ReturnsDoc retDoc;
|
||||
assert(funcComment.getReturnDoc(retDoc));
|
||||
assert(retDoc.getDescription() == "Void, so nothing");
|
||||
}
|
||||
catch(TError e)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import std.array : join;
|
|||
|
||||
import tlang.misc.logging;
|
||||
import std.string : format;
|
||||
import tlang.compiler.lexer.core.tokens : Token;
|
||||
|
||||
/**
|
||||
* The type of docstring
|
||||
|
@ -87,6 +88,11 @@ public struct ExceptionDoc
|
|||
private string exception;
|
||||
private string description;
|
||||
|
||||
public string getException()
|
||||
{
|
||||
return this.exception;
|
||||
}
|
||||
|
||||
public string getDescription()
|
||||
{
|
||||
return this.description;
|
||||
|
@ -519,8 +525,6 @@ unittest
|
|||
assert("Hello there" == comment.bdy);
|
||||
}
|
||||
|
||||
import tlang.compiler.lexer.core.tokens : Token;
|
||||
|
||||
/**
|
||||
* Represents a comment
|
||||
* which can be attached
|
||||
|
@ -532,7 +536,6 @@ public final class Comment
|
|||
|
||||
private this(CommentParts content)
|
||||
{
|
||||
// TODO: Parse the comment into text but annotated section
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module simple_comments;
|
||||
|
||||
// Lol
|
||||
|
||||
int i;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue