-
Notifications
You must be signed in to change notification settings - Fork 60
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
fix #158 - handle identifier list containing an indexing expression #159
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b0a76ab
fix #158 - handle identifier list containing an indexing expression
d50d46d
remove warn used to test the fix
5ee0195
add the TypeIdentifierList AST node to allow proper multi indexers
b5fd1ff
forgot to remove this after adding the new node type
b91c5be
- rename IdentifierList to DeclaratorIdentifierList so that TypeIdent…
57134b8
update the formatter
08b9460
test and fix using the formatter
e0e9749
fix BasicType2X broken
52b8c9d
fix leading dot broken
2ce9605
rename IdentifierList to TypeIdentifierChain
d45051b
remove writeln used to test
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
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 |
---|---|---|
|
@@ -7,6 +7,13 @@ import std.typetuple:TypeTuple; | |
|
||
import dparse.ast; | ||
import dparse.lexer; | ||
version (unittest) | ||
{ | ||
import dparse.parser; | ||
import dparse.rollback_allocator; | ||
import std.array : Appender; | ||
import std.algorithm : canFind; | ||
} | ||
|
||
//debug = verbose; | ||
|
||
|
@@ -121,7 +128,10 @@ class Formatter(Sink) | |
format(type); | ||
space(); | ||
} | ||
format(identifierList); | ||
if (declaratorIdentifierList) | ||
{ | ||
format(declaratorIdentifierList); | ||
} | ||
} | ||
put(";"); | ||
} | ||
|
@@ -1551,13 +1561,40 @@ class Formatter(Sink) | |
} | ||
} | ||
|
||
void format(const DeclaratorIdentifierList declaratorIdentifierList) | ||
{ | ||
debug(verbose) writeln("DeclaratorIdentifierList"); | ||
|
||
foreach(count, ident; declaratorIdentifierList.identifiers) | ||
{ | ||
if (count) | ||
put(", "); | ||
put(ident.text); | ||
} | ||
} | ||
|
||
void format(const IdentifierList identifierList) | ||
{ | ||
debug(verbose) writeln("IdentifierList"); | ||
foreach(count, ident; identifierList.identifiers) | ||
|
||
if (identifierList.dot) | ||
{ | ||
if (count) put(", "); | ||
put(ident.text); | ||
put("."); | ||
} | ||
if (identifierList.identifierOrTemplateInstance) | ||
{ | ||
format(identifierList.identifierOrTemplateInstance); | ||
} | ||
if (identifierList.indexer) | ||
{ | ||
put("["); | ||
format(identifierList.indexer); | ||
put("]"); | ||
} | ||
if (identifierList.identifierList) | ||
{ | ||
put("."); | ||
format(identifierList.identifierList); | ||
} | ||
} | ||
|
||
|
@@ -1970,10 +2007,10 @@ class Formatter(Sink) | |
if (linkageAttribute.hasPlusPlus) | ||
{ | ||
put("++"); | ||
if (linkageAttribute.identifierChain && linkageAttribute.identifierChain.identifiers.length > 0) | ||
if (linkageAttribute.identifierList) | ||
{ | ||
put(", "); | ||
format(linkageAttribute.identifierChain); | ||
format(linkageAttribute.identifierList); | ||
} | ||
else if (linkageAttribute.classOrStruct == tok!"class") | ||
put(", class"); | ||
|
@@ -3187,24 +3224,23 @@ class Formatter(Sink) | |
|
||
/** | ||
IdType builtinType; | ||
Symbol symbol; | ||
TypeofExpression typeofExpression; | ||
IdentifierOrTemplateChain identifierOrTemplateChain; | ||
IdentifierList identifierList; | ||
IdType typeConstructor; | ||
Type type; | ||
**/ | ||
|
||
if (type2.symbol !is null) | ||
if (type2.identifierList !is null) | ||
{ | ||
format(type2.symbol); | ||
format(type2.identifierList); | ||
} | ||
else if (type2.typeofExpression !is null) | ||
{ | ||
format(type2.typeofExpression); | ||
if (type2.identifierOrTemplateChain) | ||
if (type2.identifierList) | ||
{ | ||
put("."); | ||
format(type2.identifierOrTemplateChain); | ||
format(type2.identifierList); | ||
} | ||
return; | ||
} | ||
|
@@ -3218,10 +3254,10 @@ class Formatter(Sink) | |
else | ||
{ | ||
put(tokenRep(type2.builtinType)); | ||
if (type2.identifierOrTemplateChain !is null) | ||
if (type2.identifierList) | ||
{ | ||
put("."); | ||
format(type2.identifierOrTemplateChain); | ||
format(type2.identifierList); | ||
} | ||
} | ||
} | ||
|
@@ -3867,3 +3903,35 @@ protected: | |
"postblit" | ||
]; | ||
} | ||
|
||
version (unittest) | ||
void testFormatNode(Node)(string sourceCode) | ||
{ | ||
Appender!string fmt; | ||
ubyte[] code = cast(ubyte[]) sourceCode; | ||
|
||
class CatchInterestingStuff : ASTVisitor | ||
{ | ||
alias visit = ASTVisitor.visit; | ||
override void visit(const(Node) stuff) | ||
{ | ||
stuff.accept(this); | ||
format(&fmt, stuff); | ||
assert(fmt.data.canFind(code), fmt.data); | ||
writeln(fmt.data); | ||
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. gotta remove this writeln. |
||
} | ||
} | ||
|
||
LexerConfig config; | ||
StringCache cache = StringCache(32); | ||
RollbackAllocator rba; | ||
auto toks = getTokensForParser(code, config, &cache); | ||
Module mod = parseModule(toks, "stdin", &rba); | ||
(new CatchInterestingStuff).visit(mod); | ||
} | ||
|
||
unittest | ||
{ | ||
testFormatNode!(VariableDeclaration)("T[0].Y y;"); | ||
testFormatNode!(VariableDeclaration)(`.T!"oof" toof;`); | ||
} |
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.
use this new function to fix #135 and also problems in harbored-mod (which uses dparse formatter apparently...)