diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml new file mode 100644 index 0000000..922e310 --- /dev/null +++ b/.github/workflows/scala.yml @@ -0,0 +1,18 @@ +name: Scala CI + +on: push + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + - name: Run tests + run: sbt "+ test" diff --git a/.gitignore b/.gitignore index 1ad9613..93364c1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ project/plugins/project/ .scala_dependencies .worksheet .idea/ + +.bsp diff --git a/build.sbt b/build.sbt index 770d43f..26675b1 100644 --- a/build.sbt +++ b/build.sbt @@ -1,16 +1,16 @@ -name := "xmlschema2shex" +ThisBuild / organization := "com.herminiogarcia" -organization := "es.weso" - -version := "0.1-SNAPSHOT" - -scalaVersion := "2.12.8" - -resolvers += "jitpack" at "https://jitpack.io" - -libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.2" % "test" -libraryDependencies += "com.github.herminiogg" % "ShExML" % "0.2.5" -libraryDependencies += "info.picocli" % "picocli" % "4.0.4" - -mainClass in (Compile, run) := Some("es.weso.xmlschema2shex.Main") \ No newline at end of file +lazy val xmlschema2shex = project + .in(file(".")) + .settings( + name := "xmlschema2shex", + version := "0.1.0", + scalaVersion := "3.2.0", + crossScalaVersions := Seq("2.12.17", "2.13.9", "3.2.0"), + libraryDependencies ++= Seq( + "org.scala-lang.modules" %% "scala-parser-combinators" % "2.3.0", + "org.scalatest" %% "scalatest" % "3.2.15" % "test", + "com.herminiogarcia" %% "shexml" % "0.4.2" exclude("io.gatling", "gatling-jsonpath"), + "info.picocli" % "picocli" % "4.7.3", + ) + ) \ No newline at end of file diff --git a/project/build.properties b/project/build.properties index d638b4f..ff6e0dd 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 0.13.8 \ No newline at end of file +sbt.version = 1.7.2 \ No newline at end of file diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/AttributeElement.scala b/src/main/scala-2.12/es/weso/xmlschema2shex/ast/AttributeElement.scala deleted file mode 100644 index 415446e..0000000 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/AttributeElement.scala +++ /dev/null @@ -1,5 +0,0 @@ -package es.weso.xmlschema2shex.ast - -/** - * Created by herminio on 4/10/16. - */ diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/parser/Parser.scala b/src/main/scala-2.12/es/weso/xmlschema2shex/parser/Parser.scala deleted file mode 100644 index ad5baa3..0000000 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/parser/Parser.scala +++ /dev/null @@ -1,83 +0,0 @@ -package es.weso.xmlschema2shex.parser - -import java.io.FileWriter - -import es.weso.xmlschema2shex.check.SemanticChecker -import es.weso.xmlschema2shex.decorator.{NameDecorator, TypeDecorator} -import es.weso.xmlschema2shex.generation.CodeGenerator - -/** - * Created by herminio on 4/10/16. - */ -object Parser extends XMLSchemaParser{ - def main(args: Array[String]): Unit = { - val xml = """ - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |""".stripMargin - - /**val output = XMLSchema2ShexParser().parse(xml, None) - val fw = new FileWriter("result.shex")*/ - val output = XMLSchema2ShexParser().convertToShExML(xml) - val fw = new FileWriter("result.shexml") - fw.write(output) - fw.close() - println(output) - } - -} \ No newline at end of file diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/Main.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/Main.scala similarity index 91% rename from src/main/scala-2.12/es/weso/xmlschema2shex/Main.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/Main.scala index cc11db0..8de388c 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/Main.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/Main.scala @@ -1,9 +1,8 @@ -package es.weso.xmlschema2shex +package com.herminiogarcia.xmlschema2shex +import com.herminiogarcia.xmlschema2shex.parser.XMLSchema2ShexParser import java.io.FileWriter import java.util.concurrent.Callable - -import es.weso.xmlschema2shex.parser.XMLSchema2ShexParser import picocli.CommandLine import picocli.CommandLine.{Command, Option} @@ -43,7 +42,7 @@ class Main extends Callable[Int] { fw.close() } println(result) - 0 + 1 } finally { fileHandler.close() } } diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Attributes.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Attributes.scala similarity index 69% rename from src/main/scala-2.12/es/weso/xmlschema2shex/ast/Attributes.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Attributes.scala index 9fe95dc..5cf6ef5 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Attributes.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Attributes.scala @@ -1,4 +1,4 @@ -package es.weso.xmlschema2shex.ast +package com.herminiogarcia.xmlschema2shex.ast /** * Created by herminio on 4/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/ElementsHolder.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/ElementsHolder.scala similarity index 89% rename from src/main/scala-2.12/es/weso/xmlschema2shex/ast/ElementsHolder.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/ast/ElementsHolder.scala index 80dfed7..ae75d88 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/ElementsHolder.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/ElementsHolder.scala @@ -1,4 +1,4 @@ -package es.weso.xmlschema2shex.ast +package com.herminiogarcia.xmlschema2shex.ast /** * Created by herminio on 4/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Restriction.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Restriction.scala similarity index 86% rename from src/main/scala-2.12/es/weso/xmlschema2shex/ast/Restriction.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Restriction.scala index 8469d36..3a6cea9 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Restriction.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Restriction.scala @@ -1,4 +1,4 @@ -package es.weso.xmlschema2shex.ast +package com.herminiogarcia.xmlschema2shex.ast /** * Created by herminio on 4/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/RestrictionModifier.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/RestrictionModifier.scala similarity index 94% rename from src/main/scala-2.12/es/weso/xmlschema2shex/ast/RestrictionModifier.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/ast/RestrictionModifier.scala index 058c0bc..62b3895 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/RestrictionModifier.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/RestrictionModifier.scala @@ -1,4 +1,4 @@ -package es.weso.xmlschema2shex.ast +package com.herminiogarcia.xmlschema2shex.ast /** * Created by herminio on 4/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Schema.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Schema.scala similarity index 74% rename from src/main/scala-2.12/es/weso/xmlschema2shex/ast/Schema.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Schema.scala index 46d3c37..3380a26 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Schema.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Schema.scala @@ -1,4 +1,4 @@ -package es.weso.xmlschema2shex.ast +package com.herminiogarcia.xmlschema2shex.ast /** * Created by herminio on 4/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Tag.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Tag.scala similarity index 99% rename from src/main/scala-2.12/es/weso/xmlschema2shex/ast/Tag.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Tag.scala index 60a30c5..6ad4e4f 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/ast/Tag.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/ast/Tag.scala @@ -1,4 +1,4 @@ -package es.weso.xmlschema2shex.ast +package com.herminiogarcia.xmlschema2shex.ast /** * Created by herminio on 4/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/check/SemanticChecker.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/check/SemanticChecker.scala similarity index 84% rename from src/main/scala-2.12/es/weso/xmlschema2shex/check/SemanticChecker.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/check/SemanticChecker.scala index b37782f..d9c8251 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/check/SemanticChecker.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/check/SemanticChecker.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.check +package com.herminiogarcia.xmlschema2shex.check -import es.weso.xmlschema2shex.ast._ +import com.herminiogarcia.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, Restriction, Schema, SimpleType, Tag, Type, Typeable} /** * Created by herminio on 5/10/16. @@ -44,7 +44,7 @@ class SemanticChecker(val schema: Schema) { } def checkRestriction(restriction: Restriction): Unit = { - restriction.restrictions.foreach(println(_)) + //restriction.restrictions.foreach(println(_)) } } diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/decorator/NameDecorator.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/decorator/NameDecorator.scala similarity index 93% rename from src/main/scala-2.12/es/weso/xmlschema2shex/decorator/NameDecorator.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/decorator/NameDecorator.scala index 12bf826..4f40ad6 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/decorator/NameDecorator.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/decorator/NameDecorator.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.decorator +package com.herminiogarcia.xmlschema2shex.decorator -import es.weso.xmlschema2shex.ast.{ComplexType, Schema, Element} +import com.herminiogarcia.xmlschema2shex.ast.{ComplexType, Schema} /** * Created by herminio on 6/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/decorator/TypeDecorator.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/decorator/TypeDecorator.scala similarity index 90% rename from src/main/scala-2.12/es/weso/xmlschema2shex/decorator/TypeDecorator.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/decorator/TypeDecorator.scala index 5218f6a..e722dc8 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/decorator/TypeDecorator.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/decorator/TypeDecorator.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.decorator +package com.herminiogarcia.xmlschema2shex.decorator -import es.weso.xmlschema2shex.ast._ +import com.herminiogarcia.xmlschema2shex.ast.{AttributeElement, Attributes, ComplexType, Element, Schema, SimpleType, Tag, Type, Typeable, XSDAnyURI, XSDBase64Binary, XSDBoolean, XSDByte, XSDDate, XSDDateTime, XSDDecimal, XSDDouble, XSDDuration, XSDENTITY, XSDGDay, XSDGMonth, XSDGMonthDay, XSDGYear, XSDGYearMonth, XSDHexBinary, XSDID, XSDIDREF, XSDIDREFS, XSDInt, XSDInteger, XSDLong, XSDNCName, XSDNMTokens, XSDName, XSDNegativeInteger, XSDNonPositiveInteger, XSDNotation, XSDPositiveInteger, XSDQName, XSDShort, XSDString, XSDTime, XSDType, XSDUnsignedByte, XSDUnsignedInt, XSDUnsignedLong, XSDUnsignedShort, XSNMToken} /** * Created by herminio on 6/10/16. diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/CodeGenerator.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/CodeGenerator.scala similarity index 94% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/CodeGenerator.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/CodeGenerator.scala index 0ad7b0d..862e7cf 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/CodeGenerator.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/CodeGenerator.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.xmlschema2shex.ast._ +import com.herminiogarcia.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, ElementsHolder, Schema, SimpleType, Typeable, XSDType, XSNMToken} /** * Created by herminio on 5/10/16. @@ -70,7 +70,7 @@ class CodeGenerator(schema: Schema) { case Some(theName) => ":" + theName case None => element.ref match { case Some(ref) => ":" + ref - case None => None + case None => "" } } val typeString = element.aType match { diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/CodeGeneratorShExML.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/CodeGeneratorShExML.scala similarity index 94% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/CodeGeneratorShExML.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/CodeGeneratorShExML.scala index 478a06a..b292b40 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/CodeGeneratorShExML.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/CodeGeneratorShExML.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.xmlschema2shex.ast._ +import com.herminiogarcia.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, ElementsHolder, Schema, SimpleType, Typeable, XSDType, XSNMToken} /** * Created by herminio on 5/10/16. @@ -70,7 +70,7 @@ class CodeGeneratorShExML(schema: Schema) { case Some(theName) => "FIELD " + theName + " <"+ theName +">" case None => element.ref match { case Some(ref) => ":" + ref - case None => None + case None => "" } } val typeString = element.aType match { diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/NameNormalizator.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/NameNormalizator.scala similarity index 84% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/NameNormalizator.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/NameNormalizator.scala index c14fa7d..d982863 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/NameNormalizator.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/NameNormalizator.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.xmlschema2shex.ast.Typeable +import com.herminiogarcia.xmlschema2shex.ast.Typeable trait NameNormalizator { diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/ShExMLPrinter.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/ShExMLPrinter.scala similarity index 81% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/ShExMLPrinter.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/ShExMLPrinter.scala index ac0bbc0..a653efa 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/ShExMLPrinter.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/ShExMLPrinter.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.shexml.ast.{AutoIncrement, DataType, DataTypeGeneration, DataTypeLiteral, Declaration, Expression, Field, Iterator, IteratorQuery, NestedIterator, ObjectElement, PredicateObject, Prefix, QueryClause, ShExML, Shape, ShapeLink, Source, URL, Var} +import com.herminiogarcia.shexml.ast.{Action, AutoIncrement, DataType, DataTypeGeneration, DataTypeLiteral, Declaration, Expression, Field, Iterator, IteratorQuery, LiteralSubject, NestedIterator, ObjectElement, PredicateObject, Prefix, QueryClause, ShExML, Shape, ShapeLink, ShapeVar, Source, URL, Var} class ShExMLPrinter { @@ -49,18 +49,26 @@ class ShExMLPrinter { def print(s: Shape, indentation: Int): String = { val shapeAction = s.action match { - case Var(action) => action + case Action(_, action, _) => action match { + case Var(name) => name + case _ => throw new Exception("Not supported") + } + case LiteralSubject(_, value) => value case _ => "" } + val shapePrefix = s.action match { + case Action(shapePrefix, _, _) => shapePrefix + case LiteralSubject(prefix, _) => prefix.name + } generateIndentation(indentation) + - s.shapeName.name + " " + s.shapePrefix + "[" + shapeAction + "] {\n" + + s.shapeName.name + " " + shapePrefix + "[" + shapeAction + "] {\n" + s.predicateObjects.map(po => print(po, indentation + 1)).mkString("") + "}\n" } def print(po: PredicateObject, indentation: Int): String = { val objectPart = po.objectOrShapeLink match { - case ObjectElement(prefix, action, literalValue, matcher, dataType, langTag, None) => literalValue match { + case ObjectElement(prefix, action, literalValue, matcher, None, dataType, langTag, None) => literalValue match { case Some(literal) => prefix + literal + printDatatype(dataType) case None => { val actionString = if(action.isDefined) action.get.asInstanceOf[Var].name else "" diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/VarTableBuilder.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/VarTableBuilder.scala similarity index 79% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/VarTableBuilder.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/VarTableBuilder.scala index 617292d..b41e5d4 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/VarTableBuilder.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/VarTableBuilder.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, Schema, SimpleType, Tag, Typeable} +import com.herminiogarcia.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, Schema, SimpleType, Tag, Typeable} import scala.collection.mutable diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShExMLDeclarationsConverter.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShExMLDeclarationsConverter.scala similarity index 87% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShExMLDeclarationsConverter.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShExMLDeclarationsConverter.scala index af9aeef..621b9c5 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShExMLDeclarationsConverter.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShExMLDeclarationsConverter.scala @@ -1,7 +1,7 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.shexml.ast.{AST, Declaration, DeclarationStatement, Expression, Field, FieldQuery, Iterator, IteratorQuery, NestedIterator, Prefix, QueryClause, ShExML, Source, URL, Var, XmlPath} -import es.weso.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, ElementsHolder, Schema, Sequence, SimpleType, Typeable} +import com.herminiogarcia.shexml.ast.{AST, Declaration, DeclarationStatement, Expression, Field, FieldQuery, Iterator, IteratorQuery, NestedIterator, Prefix, QueryClause, ShExML, Source, URL, Var, XmlPath} +import com.herminiogarcia.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, ElementsHolder, Schema, Sequence, SimpleType, Typeable} class XMLSchema2ShExMLDeclarationsConverter(schema: Schema, implicit val varTable: Map[String, Typeable]) extends NameNormalizator { diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShExMLShapesGeneration.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShExMLShapesGeneration.scala similarity index 85% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShExMLShapesGeneration.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShExMLShapesGeneration.scala index 7eaa497..d803417 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShExMLShapesGeneration.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShExMLShapesGeneration.scala @@ -1,7 +1,7 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.shexml.ast.{DataTypeLiteral, ExpOrVar, ObjectElement, Predicate, PredicateObject, ShExML, Shape, ShapeLink, ShapeVar, Var} -import es.weso.xmlschema2shex.ast._ +import com.herminiogarcia.shexml.ast.{Action, DataTypeLiteral, ExpOrVar, ObjectElement, Predicate, PredicateObject, ShExML, Shape, ShapeLink, ShapeVar, Var} +import com.herminiogarcia.xmlschema2shex.ast.{AttributeElement, ComplexType, Element, ElementsHolder, Schema, SimpleType, Typeable, XSDType, XSNMToken} /** * Created by herminio on 5/10/16. @@ -42,9 +42,9 @@ class XMLSchema2ShExMLShapesGeneration(schema: Schema) extends NameNormalizator && po.objectOrShapeLink.isInstanceOf[ObjectElement]) match { case Some(id) => id.objectOrShapeLink.asInstanceOf[ObjectElement].action.orNull case None => Var("subjectAutoincrementId") - } - val shape = Shape(shapeVar, prefix, action, predicateObjects, None) + val actionObject = Action(prefix, action, None) + val shape = Shape(shapeVar, actionObject, predicateObjects, None) for(element <- complexType.elementsHolder.elements) yield element.aType match { case Some(nestedType) => nestedType match { @@ -95,15 +95,15 @@ class XMLSchema2ShExMLShapesGeneration(schema: Schema) extends NameNormalizator s.restriction match { case Some(restriction) => restriction.base match { case Some(name) => - ObjectElement("", action, None, None, Some(DataTypeLiteral(normalizeName(name))), None, None) - case None => ObjectElement("", action, None, None, s.name.map(DataTypeLiteral), None, None) + ObjectElement("", action, None, None, None, Some(DataTypeLiteral(normalizeName(name))), None, None) + case None => ObjectElement("", action, None, None, None, s.name.map(DataTypeLiteral.apply), None, None) } - case None => ObjectElement("", action, None, None, s.name.map(DataTypeLiteral), None, None) + case None => ObjectElement("", action, None, None, None, s.name.map(DataTypeLiteral.apply), None, None) } } case x: XSDType => x match { - case p: XSNMToken => ObjectElement(getDefaultPrefix(), action, None, None, None, None, None) // that will be pattern but not supported right now in ShExML - case _ => ObjectElement("", action, None, None, Some(DataTypeLiteral(x.name)), None, None) + case p: XSNMToken => ObjectElement(getDefaultPrefix(), action, None, None, None, None, None, None) // that will be pattern but not supported right now in ShExML + case _ => ObjectElement("", action, None, None, None, Some(DataTypeLiteral(x.name)), None, None) } } } diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShexCompletionGenerator.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShexCompletionGenerator.scala similarity index 77% rename from src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShexCompletionGenerator.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShexCompletionGenerator.scala index 797cdce..a1b6963 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/generation/XMLSchema2ShexCompletionGenerator.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/generation/XMLSchema2ShexCompletionGenerator.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.generation +package com.herminiogarcia.xmlschema2shex.generation -import es.weso.shexml.ast.{AutoIncrement, Declaration, Prefix, Shape, URL, Var} +import com.herminiogarcia.shexml.ast.{Action, AutoIncrement, Declaration, Prefix, Shape, URL, Var} class XMLSchema2ShexCompletionGenerator(declarations: List[Declaration], shapes: List[Shape]) { @@ -23,7 +23,10 @@ class XMLSchema2ShexCompletionGenerator(declarations: List[Declaration], shapes: def completeAutoincrement(): Option[Declaration] = { val needForAutoincrementDeclaration = shapes.exists(s => s.action match { - case Var(name) => name == "subjectAutoincrementId" + case Action(_, action, _) => action match { + case Var(name) => name == "subjectAutoincrementId" + case _ => false + } case _ => false }) if(needForAutoincrementDeclaration) { diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/parser/XMLSchema2ShexParser.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/parser/XMLSchema2ShexParser.scala similarity index 73% rename from src/main/scala-2.12/es/weso/xmlschema2shex/parser/XMLSchema2ShexParser.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/parser/XMLSchema2ShexParser.scala index 0e08d75..907f132 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/parser/XMLSchema2ShexParser.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/parser/XMLSchema2ShexParser.scala @@ -1,10 +1,10 @@ -package es.weso.xmlschema2shex.parser +package com.herminiogarcia.xmlschema2shex.parser -import es.weso.shexml.ast.ShExML -import es.weso.xmlschema2shex.ast.Typeable -import es.weso.xmlschema2shex.check.SemanticChecker -import es.weso.xmlschema2shex.decorator.{NameDecorator, TypeDecorator} -import es.weso.xmlschema2shex.generation.{CodeGenerator, CodeGeneratorShExML, ShExMLPrinter, VarTableBuilder, XMLSchema2ShExMLDeclarationsConverter, XMLSchema2ShExMLShapesGeneration, XMLSchema2ShexCompletionGenerator} +import com.herminiogarcia.shexml.ast.ShExML +import com.herminiogarcia.xmlschema2shex.ast.Typeable +import com.herminiogarcia.xmlschema2shex.check.SemanticChecker +import com.herminiogarcia.xmlschema2shex.decorator.{NameDecorator, TypeDecorator} +import com.herminiogarcia.xmlschema2shex.generation.{CodeGenerator, CodeGeneratorShExML, ShExMLPrinter, VarTableBuilder, XMLSchema2ShExMLDeclarationsConverter, XMLSchema2ShExMLShapesGeneration, XMLSchema2ShexCompletionGenerator} import scala.collection.mutable diff --git a/src/main/scala-2.12/es/weso/xmlschema2shex/parser/XMLSchemaParser.scala b/src/main/scala/com/herminiogarcia/xmlschema2shex/parser/XMLSchemaParser.scala similarity index 85% rename from src/main/scala-2.12/es/weso/xmlschema2shex/parser/XMLSchemaParser.scala rename to src/main/scala/com/herminiogarcia/xmlschema2shex/parser/XMLSchemaParser.scala index d1ef431..1c7a063 100644 --- a/src/main/scala-2.12/es/weso/xmlschema2shex/parser/XMLSchemaParser.scala +++ b/src/main/scala/com/herminiogarcia/xmlschema2shex/parser/XMLSchemaParser.scala @@ -1,16 +1,17 @@ -package es.weso.xmlschema2shex.parser +package com.herminiogarcia.xmlschema2shex.parser /** * Created by herminio on 4/10/16. */ -import es.weso.xmlschema2shex.ast._ +import com.herminiogarcia.xmlschema2shex.ast +import com.herminiogarcia.xmlschema2shex.ast.{All, AttributeElement, Attributes, ComplexType, Element, ElementsHolder, Enumeration, MaxExclusive, MaxInclusive, MinExclusive, MinInclusive, Pattern, Restriction, RestrictionModifier, Schema, Sequence, SimpleType, Tag} import scala.util.parsing.combinator._ class XMLSchemaParser extends JavaTokenParsers { def root: Parser[Schema] = opt("")~openingTag("schema")~attributes~">"~rep(tags)~closingTag("schema") ^^ { - case _ ~ _ ~ attributes ~ _ ~ tags ~ _ => Schema(attributes, tags) + case _ ~ _ ~ attributes ~ _ ~ tags ~ _ => ast.Schema(attributes, tags) } def tags: Parser[Tag] = element | complexType | simpleType | attribute @@ -82,27 +83,27 @@ class XMLSchemaParser extends JavaTokenParsers { maxInclusiveRestriction | minInclusiveRestriction | patternRestriction | enumeration def maxExclusiveRestriction: Parser[MaxExclusive] = openingTag("maxExclusive")~attributes~"/>" ^^ { - case _ ~ attributes ~ _ => MaxExclusive(attributes) + case _ ~ attributes ~ _ => ast.MaxExclusive(attributes) } def minExclusiveRestriction: Parser[MinExclusive] = openingTag("minExclusive")~attributes~"/>" ^^ { - case _ ~ attributes ~ _ => MinExclusive(attributes) + case _ ~ attributes ~ _ => ast.MinExclusive(attributes) } def maxInclusiveRestriction: Parser[MaxInclusive] = openingTag("maxInclusive")~attributes~"/>" ^^ { - case _ ~ attributes ~ _ => MaxInclusive(attributes) + case _ ~ attributes ~ _ => ast.MaxInclusive(attributes) } def minInclusiveRestriction: Parser[MinInclusive] = openingTag("minInclusive")~attributes~"/>" ^^ { - case _ ~ attributes ~ _ => MinInclusive(attributes) + case _ ~ attributes ~ _ => ast.MinInclusive(attributes) } def patternRestriction: Parser[Pattern] = openingTag("pattern")~attributes~"/>" ^^ { - case _ ~ attributes ~ _ => Pattern(attributes) + case _ ~ attributes ~ _ => ast.Pattern(attributes) } def enumeration: Parser[Enumeration] = openingTag("enumeration")~attributes~"/>" ^^ { - case _ ~ attributes ~ _ => Enumeration(attributes) + case _ ~ attributes ~ _ => ast.Enumeration(attributes) } def annotation: Parser[Any] = openingTag("annotation")~"".r~closingTag("annotation") diff --git a/src/test/scala-2.12/es/weso/xmlschema2shex/inputoutputtests/ShExGenerationTests.scala b/src/test/scala/com/herminiogarcia/xmlschema2shex/inputoutputtests/ShExGenerationTests.scala similarity index 68% rename from src/test/scala-2.12/es/weso/xmlschema2shex/inputoutputtests/ShExGenerationTests.scala rename to src/test/scala/com/herminiogarcia/xmlschema2shex/inputoutputtests/ShExGenerationTests.scala index 869b7a4..ecf9505 100644 --- a/src/test/scala-2.12/es/weso/xmlschema2shex/inputoutputtests/ShExGenerationTests.scala +++ b/src/test/scala/com/herminiogarcia/xmlschema2shex/inputoutputtests/ShExGenerationTests.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.inputoutputtests +package com.herminiogarcia.xmlschema2shex.inputoutputtests -import es.weso.xmlschema2shex.parser.XMLSchema2ShexParser +import com.herminiogarcia.xmlschema2shex.parser.XMLSchema2ShexParser import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers @@ -13,93 +13,93 @@ class ShExGenerationTests extends AnyFunSuite with Matchers { test("XML Schema conversion from Microsoft example") { val xml = Source.fromResource("purchaseOrderFull.xsd").mkString - val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll(" |\n", "") - output should include (""" { + val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll("\\s", "") + assert(output.contains(""" { |:shipTo @ {1} ; |:billTo @ {1} ; |:comment xs:string ? ; |:items @ {1} ; |:orderDate xs:date {1} ; - |}""".stripMargin.replaceAll(" |\n", "")) - output should include (""" { + |}""".stripMargin.replaceAll("\\s", ""))) + assert(output.contains(""" { |:name xs:string {1} ; |:street xs:string {1} ; |:city xs:string {1} ; |:state xs:string {1} ; |:zip xs:decimal {1} ; |:country [US] {1} ; - |}""".stripMargin.replaceAll(" |\n", "")) - output should include (""" { + |}""".stripMargin.replaceAll("\\s", ""))) + assert(output.contains(""" { |:item @ * ; - |}""".stripMargin.replaceAll(" |\n", "")) - output should include (""" { + |}""".stripMargin.replaceAll("\\s", ""))) + assert(output.contains(""" { |:productName xs:string {1} ; |:quantity xs:positiveInteger {1, 99} ; |:USPrice xs:decimal {1} ; |:comment xs:string ? ; |:shipDate xs:date ? ; |:partNum xs:string {1} PATTERN \\d{3}-[A-Z]{2} ; - |}""".stripMargin.replaceAll(" |\n", "")) + |}""".stripMargin.replaceAll("\\s", ""))) } test("XML Schema conversion for addresses") { val xml = Source.fromResource("address.xsd").mkString - val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll(" |\n", "") - output should include(""" { + val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll("\\s", "") + assert(output.contains(""" { |:address @
+ ; - |}""".stripMargin.replaceAll(" |\n", "")) + |}""".stripMargin.replaceAll("\\s", ""))) - output should include("""
{ + assert(output.contains("""
{ |:name xs:string ? ; |:street xs:string ? ; - |}""".stripMargin.replaceAll(" |\n", "")) + |}""".stripMargin.replaceAll("\\s", ""))) } test("""Xml1 version""") { val xml = Source.fromResource("xml1version.xsd").mkString - val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll(" |\n", "") - output should include(""" { + val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll("\\s", "") + assert(output.contains(""" { |:orderperson xs:string {1} ; |:shipto @ {1} ; |:item @ + ; |:orderid xs:string {1} ; - |}""".stripMargin.replaceAll(" |\n", "")) - output should include(""" { + |}""".stripMargin.replaceAll("\\s", ""))) + assert(output.contains(""" { |:title xs:string {1} ; |:note xs:string ? ; |:quantity xs:positiveInteger {1} ; |:price xs:decimal {1} ; - |}""".stripMargin.replaceAll(" |\n", "")) - output should include(""" { + |}""".stripMargin.replaceAll("\\s", ""))) + assert(output.contains(""" { |:name xs:string {1} ; |:address xs:string {1} ; |:city xs:string {1} ; |:country xs:string {1} ; - |}""".stripMargin.replaceAll(" |\n", "")) + |}""".stripMargin.replaceAll("\\s", ""))) } test("""Xml2 version""") { val xml = Source.fromResource("xml2version.xsd").mkString - val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll(" |\n", "") - output should include(""" { + val output = XMLSchema2ShexParser().parse(xml, None).stripMargin.replaceAll("\\s", "") + assert(output.contains(""" { |:orderperson xs:string {1} ; |:shipto @ {1} ; |:item @ + ; |:orderid xs:string {1} PATTERN [0-9]{6} ; - |}""".stripMargin.replaceAll(" |\n", "")) - output should include(""" { + |}""".stripMargin.replaceAll("\\s", ""))) + assert(output.contains(""" { |:title xs:string {1} ; |:note xs:string ? ; |:quantity xs:positiveInteger {1} ; |:price xs:decimal {1} ; - |}""".stripMargin.replaceAll(" |\n", "")) - output should include(""" { + |}""".stripMargin.replaceAll("\\s", ""))) + assert(output.contains(""" { |:name xs:string {1} ; |:address xs:string {1} ; |:city xs:string {1} ; |:country xs:string {1} ; - |}""".stripMargin.replaceAll(" |\n", "")) + |}""".stripMargin.replaceAll("\\s", ""))) } diff --git a/src/test/scala-2.12/es/weso/xmlschema2shex/inputoutputtests/ShExMLGenerationTests.scala b/src/test/scala/com/herminiogarcia/xmlschema2shex/inputoutputtests/ShExMLGenerationTests.scala similarity index 91% rename from src/test/scala-2.12/es/weso/xmlschema2shex/inputoutputtests/ShExMLGenerationTests.scala rename to src/test/scala/com/herminiogarcia/xmlschema2shex/inputoutputtests/ShExMLGenerationTests.scala index 9455d9c..81b2dff 100644 --- a/src/test/scala-2.12/es/weso/xmlschema2shex/inputoutputtests/ShExMLGenerationTests.scala +++ b/src/test/scala/com/herminiogarcia/xmlschema2shex/inputoutputtests/ShExMLGenerationTests.scala @@ -1,6 +1,6 @@ -package es.weso.xmlschema2shex.inputoutputtests +package com.herminiogarcia.xmlschema2shex.inputoutputtests -import es.weso.xmlschema2shex.parser.XMLSchema2ShexParser +import com.herminiogarcia.xmlschema2shex.parser.XMLSchema2ShexParser import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers @@ -13,13 +13,13 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { test("Xml1 version") { val xml = Source.fromResource("xml1version.xsd").mkString - val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll(" |\n|\t", "") + val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll("\\s", "") output should include ("""PREFIX : |PREFIX xs: - |PREFIX xsd: """.stripMargin.replaceAll(" |\n|\t", "")) + |PREFIX xsd: """.stripMargin.replaceAll("\\s", "")) output should include (""" |SOURCE example - |""".stripMargin.replaceAll(" |\n|\t", "")) + |""".stripMargin.replaceAll("\\s", "")) output should include ("""ITERATOR shipto { | FIELD name | FIELD address
@@ -49,7 +49,7 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { | } |} |EXPRESSION exp - |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll(" |\n|\t", "")) + |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll("\\s", "")) output should include (""":shiporder :[exp.orderid] { | :orderperson [exp.orderperson] xs:string ; | :shipto @:shipto ; @@ -67,18 +67,18 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { | :address [exp.shipto.address] xs:string ; | :city [exp.shipto.city] xs:string ; | :country [exp.shipto.country] xs:string ; - |}""".stripMargin.replaceAll(" |\n|\t", "")) + |}""".stripMargin.replaceAll("\\s", "")) } test("""Xml2 version""") { val xml = Source.fromResource("xml2version.xsd").mkString - val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll(" |\n|\t", "") + val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll("\\s", "") output should include ("""PREFIX : |PREFIX xs: - |PREFIX xsd: """.stripMargin.replaceAll(" |\n|\t", "")) + |PREFIX xsd: """.stripMargin.replaceAll("\\s", "")) output should include (""" |SOURCE example - |""".stripMargin.replaceAll(" |\n|\t", "")) + |""".stripMargin.replaceAll("\\s", "")) output should include ("""ITERATOR shiporder { | FIELD orderid | FIELD orderperson @@ -96,7 +96,7 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { | } |} |EXPRESSION exp - |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll(" |\n|\t", "")) + |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll("\\s", "")) output should include (""":shiporder :[exp.orderid] { | :orderperson [exp.orderperson] xs:string ; | :shipto @:shipto ; @@ -114,18 +114,18 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { | :address [exp.shipto.address] xs:string ; | :city [exp.shipto.city] xs:string ; | :country [exp.shipto.country] xs:string ; - |}""".stripMargin.replaceAll(" |\n|\t", "")) + |}""".stripMargin.replaceAll("\\s", "")) } test("XML Schema conversion for addresses") { val xml = Source.fromResource("address.xsd").mkString - val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll(" |\n|\t", "") + val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll("\\s", "") output should include ("""PREFIX : |PREFIX xs: - |PREFIX xsd: """.stripMargin.replaceAll(" |\n|\t", "")) + |PREFIX xsd: """.stripMargin.replaceAll("\\s", "")) output should include (""" |SOURCE example - |""".stripMargin.replaceAll(" |\n|\t", "")) + |""".stripMargin.replaceAll("\\s", "")) output should include ("""ITERATOR addresses { | ITERATOR address
{ | FIELD name @@ -137,26 +137,26 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { | FIELD street |} |EXPRESSION exp - |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll(" |\n|\t", "")) + |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll("\\s", "")) output should include (""":addresses :[subjectAutoincrementId] { | :address @:address ; |} |:address :[subjectAutoincrementId] { | :name [exp.name] xs:string ; | :street [exp.street] xs:string ; - |}""".stripMargin.replaceAll(" |\n|\t", "")) + |}""".stripMargin.replaceAll("\\s", "")) } test("""XML Schema conversion from Microsoft example""") { val xml = Source.fromResource("purchaseOrderFull.xsd").mkString - val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll(" |\n|\t", "") + val output = XMLSchema2ShexParser().convertToShExML(xml).stripMargin.replaceAll("\\s", "") output should include ("""PREFIX : |PREFIX xs: |PREFIX xsd: - |PREFIX tn: """.stripMargin.replaceAll(" |\n|\t", "")) + |PREFIX tn: """.stripMargin.replaceAll("\\s", "")) output should include (""" |SOURCE example - |""".stripMargin.replaceAll(" |\n|\t", "")) + |""".stripMargin.replaceAll("\\s", "")) output should include ("""ITERATOR purchaseOrder { | FIELD orderDate | FIELD comment @@ -188,7 +188,7 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { | } |} |EXPRESSION exp - |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll(" |\n|\t", "")) + |AUTOINCREMENT subjectAutoincrementId <"subject_" + 1 to 2147483647 by 1>""".stripMargin.replaceAll("\\s", "")) output should include ("""tn:purchaseOrder tn:[subjectAutoincrementId] { | tn:shipTo @tn:shipTo ; | tn:billTo @tn:billTo ; @@ -222,7 +222,7 @@ class ShExMLGenerationTests extends AnyFunSuite with Matchers { | tn:state [exp.shipTo.state] xs:string ; | tn:zip [exp.shipTo.zip] xs:decimal ; | tn:country tn:[exp.shipTo.country] ; - |}""".stripMargin.replaceAll(" |\n|\t", "")) + |}""".stripMargin.replaceAll("\\s", "")) }