Skip to content

Commit

Permalink
Update description formatting/parsing based in the changes in the ref…
Browse files Browse the repository at this point in the history
…erence implementation. Also more comments are now parsed and rendered (trailing comments, for instance). Closes #155
  • Loading branch information
OlegIlyenko committed Aug 25, 2016
1 parent d3b56d1 commit 0d8263f
Show file tree
Hide file tree
Showing 24 changed files with 2,811 additions and 1,294 deletions.
30 changes: 20 additions & 10 deletions src/main/scala/sangria/ast/AstVisitor.scala
Expand Up @@ -19,25 +19,28 @@ object AstVisitor {

def loop(node: AstNode): Unit =
node match {
case n @ Document(defs, _, _)
case n @ Document(defs, trailingComments, _, _)
if (breakOrSkip(onEnter(n))) {
defs.foreach(d loop(d))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ FragmentDefinition(_, cond, dirs, sels, comment, _)
case n @ FragmentDefinition(_, cond, dirs, sels, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
loop(cond)
dirs.foreach(d loop(d))
sels.foreach(s loop(s))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ OperationDefinition(_, _, vars, dirs, sels, comment, _)
case n @ OperationDefinition(_, _, vars, dirs, sels, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
vars.foreach(d loop(d))
dirs.foreach(d loop(d))
sels.foreach(s loop(s))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ VariableDefinition(_, tpe, default, comment, _)
Expand All @@ -47,12 +50,13 @@ object AstVisitor {
comment.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ InlineFragment(cond, dirs, sels, comment, _)
case n @ InlineFragment(cond, dirs, sels, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
cond.foreach(c loop(c))
dirs.foreach(d loop(d))
sels.foreach(s loop(s))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ FragmentSpread(_, dirs, comment, _)
Expand All @@ -71,12 +75,13 @@ object AstVisitor {
loop(ofType)
breakOrSkip(onLeave(n))
}
case n @ Field(_, _, args, dirs, sels, comment, _)
case n @ Field(_, _, args, dirs, sels, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
args.foreach(d loop(d))
dirs.foreach(d loop(d))
sels.foreach(s loop(s))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ Argument(_, v, comment, _)
Expand Down Expand Up @@ -187,19 +192,21 @@ object AstVisitor {
comment.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ ObjectTypeDefinition(_, interfaces, fields, dirs, comment, _)
case n @ ObjectTypeDefinition(_, interfaces, fields, dirs, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
interfaces.foreach(d loop(d))
fields.foreach(d loop(d))
dirs.foreach(d loop(d))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ InterfaceTypeDefinition(_, fields, dirs, comment, _)
case n @ InterfaceTypeDefinition(_, fields, dirs, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
fields.foreach(d loop(d))
dirs.foreach(d loop(d))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ UnionTypeDefinition(_, types, dirs, comment, _)
Expand All @@ -209,11 +216,12 @@ object AstVisitor {
comment.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ EnumTypeDefinition(_, values, dirs, comment, _)
case n @ EnumTypeDefinition(_, values, dirs, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
values.foreach(d loop(d))
dirs.foreach(d loop(d))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ EnumValueDefinition(_, dirs, comment, _)
Expand All @@ -222,11 +230,12 @@ object AstVisitor {
comment.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ InputObjectTypeDefinition(_, fields, dirs, comment, _)
case n @ InputObjectTypeDefinition(_, fields, dirs, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
fields.foreach(d loop(d))
dirs.foreach(d loop(d))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ TypeExtensionDefinition(definition, comment, _)
Expand All @@ -247,11 +256,12 @@ object AstVisitor {
comment.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ SchemaDefinition(ops, dirs, comment, _)
case n @ SchemaDefinition(ops, dirs, comment, trailingComments, _)
if (breakOrSkip(onEnter(n))) {
ops.foreach(s loop(s))
dirs.foreach(s loop(s))
comment.foreach(s loop(s))
trailingComments.foreach(s loop(s))
breakOrSkip(onLeave(n))
}
case n @ OperationTypeDefinition(_, tpe, comment, _)
Expand Down

0 comments on commit 0d8263f

Please sign in to comment.