-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1117 from aml-org/publish-beta-4
APIMF-3342: Publish beta 4
- Loading branch information
Showing
393 changed files
with
55,236 additions
and
108,936 deletions.
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
6 changes: 6 additions & 0 deletions
6
...tax/shared/src/main/scala/amf/antlr/client/scala/parse/document/AntlrParsedDocument.scala
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package amf.antlr.client.scala.parse.document | ||
|
||
import amf.core.client.scala.parse.document.ParsedDocument | ||
import org.mulesoft.antlrast.ast.AST | ||
|
||
case class AntlrParsedDocument(ast: AST, override val comment: Option[String] = None) extends ParsedDocument |
67 changes: 67 additions & 0 deletions
67
...ntax/shared/src/main/scala/amf/antlr/client/scala/parse/syntax/AntlrASTParserHelper.scala
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package amf.antlr.client.scala.parse.syntax | ||
|
||
import amf.apicontract.internal.validation.definitions.ParserSideValidations | ||
import amf.core.client.scala.parse.document.ParserContext | ||
import amf.core.internal.annotations.LexicalInformation | ||
import amf.core.internal.parser.domain.Annotations | ||
import org.mulesoft.antlrast.ast.{ASTElement, Node, Terminal} | ||
|
||
trait AntlrASTParserHelper { | ||
def find(node: Node, name: String): Seq[ASTElement] = node.children.filter(_.name == name) | ||
|
||
def collect(node: ASTElement, names: Seq[String]): Seq[ASTElement] = { | ||
if (names.isEmpty) { | ||
Seq(node) | ||
} else { | ||
val nextName = names.head | ||
node match { | ||
case n: Node => | ||
find(n, nextName).flatMap { nested => | ||
collect(nested, names.tail) | ||
} | ||
case _ => Nil | ||
} | ||
} | ||
} | ||
|
||
def path(node: ASTElement, names: Seq[String]): Option[ASTElement] = { | ||
if (names.isEmpty) { | ||
Some(node) | ||
} else { | ||
val nextName = names.head | ||
node match { | ||
case n: Node => | ||
find(n, nextName) match { | ||
case found: Seq[ASTElement] if found.length == 1 => | ||
path(found.head, names.tail) | ||
case _ => | ||
None | ||
} | ||
case _ => | ||
None | ||
} | ||
} | ||
} | ||
|
||
def withNode[T](element: ASTElement)(f: Node => T)(implicit ctx: ParserContext): T = element match { | ||
case node: Node => f(node) | ||
case _ => throw new Exception(s"Unexpected AST terminal token $element") | ||
} | ||
|
||
def withOptTerminal[T](element: ASTElement)(f: Option[Terminal] => T)(implicit ctx: ParserContext): T = element match { | ||
case node: Node if node.children.length == 1 && node.children.head.isInstanceOf[Terminal] => | ||
f(Some(node.children.head.asInstanceOf[Terminal])) | ||
case _ => | ||
f(None) | ||
} | ||
|
||
def toAnnotations(elem: ASTElement): Annotations = { | ||
val lexInfo = LexicalInformation(elem.start.line, elem.start.column, elem.end.line, elem.end.column) | ||
Annotations() ++= Set(lexInfo) | ||
} | ||
|
||
def astError(id: String, message: String, annotations: Annotations)(implicit ctx: ParserContext): Unit = { | ||
ctx.eh.violation(ParserSideValidations.InvalidAst, id, message, annotations) | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
...ntax/shared/src/main/scala/amf/antlr/internal/plugins/syntax/AntlrSyntaxParsePlugin.scala
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package amf.antlr.internal.plugins.syntax | ||
|
||
import amf.antlr.client.scala.parse.document.AntlrParsedDocument | ||
import amf.core.client.common.{HighPriority, PluginPriority} | ||
import amf.core.client.scala.parse.AMFSyntaxParsePlugin | ||
import amf.core.client.scala.parse.document.{ParsedDocument, ParserContext} | ||
import amf.core.internal.remote.Mimes.`application/x-protobuf` | ||
import amf.core.internal.remote.Syntax | ||
import org.mulesoft.antlrast.platform.PlatformProtobuf3Parser | ||
|
||
object AntlrSyntaxParsePlugin extends AMFSyntaxParsePlugin { | ||
|
||
override def parse(text: CharSequence, mediaType: String, ctx: ParserContext): ParsedDocument = { | ||
val input = text.toString | ||
val ast = new PlatformProtobuf3Parser().parse(ctx.rootContextDocument, input) | ||
AntlrParsedDocument(ast, None) | ||
} | ||
|
||
override def mediaTypes: Seq[String] = Syntax.proto3Mimes.toSeq ++ Syntax.graphQLMimes.toSeq | ||
|
||
override val id: String = "antlr-ast-parse" | ||
|
||
override def applies(element: CharSequence): Boolean = { | ||
val text = element.toString | ||
val isJSONObject = text.startsWith("{") && text.endsWith("}") | ||
val isJSONArray = text.startsWith("[") && text.endsWith("]") | ||
val isYamlHash = text.startsWith("#") | ||
val containsProto = text.contains("proto3") | ||
containsProto && !isJSONArray && !isJSONObject && !isYamlHash | ||
} | ||
|
||
override def priority: PluginPriority = HighPriority | ||
|
||
override def mainMediaType: String = `application/x-protobuf` | ||
} |
32 changes: 32 additions & 0 deletions
32
...tax/shared/src/main/scala/amf/antlr/internal/plugins/syntax/AntlrSyntaxRenderPlugin.scala
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package amf.antlr.internal.plugins.syntax | ||
|
||
import amf.antlr.client.scala.parse.document.AntlrParsedDocument | ||
import amf.core.client.common.{NormalPriority, PluginPriority} | ||
import amf.core.client.scala.parse.document.{ParsedDocument, StringParsedDocument} | ||
import amf.core.client.scala.render.AMFSyntaxRenderPlugin | ||
import amf.core.internal.remote.Syntax | ||
import org.mulesoft.common.io.Output | ||
import org.mulesoft.common.io.Output.OutputOps | ||
|
||
object AntlrSyntaxRenderPlugin extends AMFSyntaxRenderPlugin { | ||
|
||
override def emit[W: Output](mediaType: String, ast: ParsedDocument, writer: W): Option[W] = { | ||
ast match { | ||
case str: StringParsedDocument => | ||
writer.append(str.ast.builder.toString) | ||
Some(writer) | ||
case _ => None | ||
} | ||
} | ||
|
||
/** | ||
* media types which specifies vendors that are parsed by this plugin. | ||
*/ | ||
override def mediaTypes: Seq[String] = Syntax.proto3Mimes.toSeq ++ Syntax.graphQLMimes.toSeq | ||
|
||
override val id: String = "antlr-ast-render" | ||
|
||
override def applies(element: ParsedDocument): Boolean = element.isInstanceOf[StringParsedDocument] | ||
|
||
override def priority: PluginPriority = NormalPriority | ||
} |
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
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
Oops, something went wrong.