Permalink
Browse files

- syntax towards dependent types

- simplify descriptions
- bugfix: custom ==, != and !
- docbook improvements
- simplifier improvements
- updated Xtext version
- validate XML
  • Loading branch information...
stefanbohne committed May 20, 2017
1 parent 8738a3c commit 334c60f29e03596153f8e4859c38fb6655bb4fe9
Showing with 925 additions and 412 deletions.
  1. +1 −0 org.bynar.versailles.xtext.ide/.classpath
  2. +4 −3 org.bynar.versailles.xtext.ide/.project
  3. +3 −1 org.bynar.versailles.xtext.ide/META-INF/MANIFEST.MF
  4. +11 −0 org.bynar.versailles.xtext.ide/src/org/bynar/versailles/xtext/ide/VersaillesLangIdeModule.xtend
  5. +17 −0 org.bynar.versailles.xtext.ide/src/org/bynar/versailles/xtext/ide/VersaillesLangIdeSetup.scala
  6. 0 org.bynar.versailles.xtext.ide/src/org/bynar/versailles/xtext/ide/VersaillesLangIdeSetup.xtend
  7. +4 −2 org.bynar.versailles.xtext.tests/META-INF/MANIFEST.MF
  8. +3 −3 ...bynar.versailles.xtext.tests/src/org/bynar/versailles/xtext/tests/VersaillesLangParsingTest.xtend
  9. +3 −3 ....versailles.xtext.tests/src/org/bynar/versailles/xtext/tests/VersaillesVariableAnalyzerTest.scala
  10. +4 −2 org.bynar.versailles.xtext.ui.tests/META-INF/MANIFEST.MF
  11. +9 −17 org.bynar.versailles.xtext/src/org/bynar/versailles/xtext/Converter.scala
  12. +6 −1 org.bynar.versailles.xtext/src/org/bynar/versailles/xtext/DocBookGeneratorFactory.scala
  13. +14 −22 org.bynar.versailles.xtext/src/org/bynar/versailles/xtext/VersaillesLang.xtext
  14. +34 −0 org.bynar.versailles.xtext/src/org/bynar/versailles/xtext/validation/VersaillesLangValidator.scala
  15. +21 −7 org.bynar.versailles/src/org/bynar/versailles/DocBookGenerator.scala
  16. +7 −1 org.bynar.versailles/src/org/bynar/versailles/PrettyPrinter.scala
  17. +309 −146 org.bynar.versailles/src/org/bynar/versailles/Simplifier.scala
  18. +4 −0 org.bynar.versailles/src/org/bynar/versailles/Term.scala
  19. +4 −4 org.bynar.versailles/src/org/bynar/versailles/TermImplicits.scala
  20. +9 −2 org.bynar.versailles/src/org/bynar/versailles/VariableAnalyzer.scala
  21. +1 −0 org.bynar.xtext.ide/.classpath
  22. +4 −3 org.bynar.xtext.ide/.project
  23. +3 −1 org.bynar.xtext.ide/META-INF/MANIFEST.MF
  24. +11 −0 org.bynar.xtext.ide/src/org/bynar/xtext/ide/BynarLangIdeModule.xtend
  25. +17 −0 org.bynar.xtext.ide/src/org/bynar/xtext/ide/BynarLangIdeSetup.scala
  26. 0 org.bynar.xtext.ide/src/org/bynar/xtext/ide/BynarLangIdeSetup.xtend
  27. +4 −2 org.bynar.xtext.tests/META-INF/MANIFEST.MF
  28. +3 −3 org.bynar.xtext.tests/src/org/bynar/xtext/tests/BynarLangParsingTest.xtend
  29. +3 −3 org.bynar.xtext.tests/src/org/bynar/xtext/tests/BynarVariableAnalyzerTest.scala
  30. +4 −2 org.bynar.xtext.ui.tests/META-INF/MANIFEST.MF
  31. +4 −4 org.bynar.xtext/.project
  32. +5 −0 org.bynar.xtext/.settings/org.eclipse.jdt.core.prefs
  33. +12 −0 org.bynar.xtext/.settings/org.scala-ide.sdt.core.prefs
  34. +2 −2 org.bynar.xtext/META-INF/MANIFEST.MF
  35. +6 −0 org.bynar.xtext/src/org/bynar/xtext/BynarLang.xtext
  36. +17 −2 org.bynar.xtext/src/org/bynar/xtext/generator/BynarLangGenerator.scala
  37. +34 −0 org.bynar.xtext/src/org/bynar/xtext/validation/BynarLangValidator.scala
  38. +0 −25 org.bynar.xtext/src/org/bynar/xtext/validation/BynarLangValidator.xtend
  39. +248 −93 org.bynar/src/org/bynar/DocBookGenerator.scala
  40. +34 −34 org.bynar/src/org/bynar/Simplifier.scala
  41. +41 −19 org.bynar/src/org/bynar/TextPrettyPrinter.scala
  42. +5 −5 org.bynar/src/org/bynar/VariableAnalyzer.scala
@@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
@@ -11,22 +11,23 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
@@ -7,7 +7,9 @@ Bundle-SymbolicName: org.bynar.versailles.xtext.ide; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: org.bynar.versailles.xtext,
org.eclipse.xtext.ide,
org.eclipse.xtext.xbase.ide
org.eclipse.xtext.xbase.ide,
org.antlr.runtime,
org.scala-lang.scala-library
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.bynar.versailles.xtext.ide.contentassist.antlr,
org.bynar.versailles.xtext.ide.contentassist.antlr.internal
@@ -0,0 +1,11 @@
/*
* generated by Xtext 2.11.0
*/
package org.bynar.versailles.xtext.ide
/**
* Use this class to register ide components.
*/
class VersaillesLangIdeModule extends AbstractVersaillesLangIdeModule {
}
@@ -0,0 +1,17 @@
package org.bynar.versailles.xtext.ide
import com.google.inject.Guice
import org.bynar.versailles.xtext.VersaillesLangRuntimeModule
import org.bynar.versailles.xtext.VersaillesLangStandaloneSetup
import org.eclipse.xtext.util.Modules2
/**
* Initialization support for running Xtext languages as language servers.
*/
class VersaillesLangIdeSetup extends VersaillesLangStandaloneSetup {
override def createInjector() = {
Guice.createInjector(Modules2.mixin(new VersaillesLangRuntimeModule, new VersaillesLangIdeModule))
}
}
@@ -10,9 +10,11 @@ Require-Bundle: org.bynar.versailles.xtext,
org.eclipse.xtext.junit4,
org.eclipse.xtext.xbase.junit,
org.eclipse.xtext.xbase.lib,
org.scala-lang.scala-library
org.scala-lang.scala-library,
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.bynar.versailles.xtext.tests
Export-Package: org.bynar.versailles.xtext.tests;x-internal=true
Import-Package: org.hamcrest.core,
org.junit;version="4.5.0",
org.junit.runners.model;version="4.5.0",
@@ -5,12 +5,12 @@ package org.bynar.versailles.xtext.tests
import com.google.inject.Inject
import org.bynar.versailles.xtext.versaillesLang.CompilationUnit
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
@RunWith(XtextRunner)
@InjectWith(VersaillesLangInjectorProvider)
@@ -1,7 +1,6 @@
package org.bynar.versailles.xtext.tests
import com.google.inject.Inject
import org.eclipse.xtext.junit4.util.ParseHelper
import org.bynar.versailles.xtext.versaillesLang.CompilationUnit
import org.bynar.versailles.xtext.Converter
import org.bynar.versailles.VariableAnalyzer
@@ -10,10 +9,11 @@ import org.bynar.versailles.JanusClass
import org.bynar.versailles.Irreversible
import org.junit.Test
import org.junit.runner.RunWith
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.bynar.versailles.xtext.versaillesLang.Statements
import org.bynar.versailles.Statement
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.util.ParseHelper
@RunWith(classOf[XtextRunner])
@InjectWith(classOf[VersaillesLangInjectorProvider])
@@ -10,9 +10,11 @@ Require-Bundle: org.bynar.versailles.xtext.ui,
org.eclipse.xtext.junit4,
org.eclipse.xtext.xbase.junit,
org.eclipse.core.runtime,
org.eclipse.ui.workbench;resolution:=optional
org.eclipse.ui.workbench;resolution:=optional,
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.bynar.versailles.xtext.ui.tests
Export-Package: org.bynar.versailles.xtext.ui.tests;x-internal=true
Import-Package: org.hamcrest.core,
org.junit;version="4.5.0",
org.junit.runners.model;version="4.5.0",
@@ -30,7 +30,7 @@ class Converter {
e
else
v.Block(fromStatements(cu.getStatements), e).putAnnotation(source, cu)
}
}
def fromExpression(it: Expression): v.Expression =
it match {
@@ -90,6 +90,7 @@ class Converter {
case ">=" => normal(v.GreaterOrEquals())
case "&&" => normal(v.And())
case "||" => normal(v.Or())
case "in" => normal(v.In())
}
case it: UnaryExpr =>
val a = fromExpression(it.getExpr)
@@ -273,9 +274,12 @@ class Converter {
).putAnnotation(source, it)
).putAnnotation(source, it))
case it: TypeStmt =>
val args = (if (it.getTypeArguments != null) Seq(fromTupleTypeType(it.getTypeArguments)) else Seq()) ++
(for (a <- it.getValueArguments) yield fromExpression(a))
val t = fromTypeExpression(it.getType)
val args = (if (it.getTypeArguments != null) Seq(fromTypeExpression(it.getTypeArguments)) else Seq()) ++
(for (a <- it.getArguments) yield fromExpression(a))
val t = (fromTypeExpression(it.getType) /: Option(it.getKind)){
case (t, k) => v.Application(v.Application(v.Typed().putAnnotation(source, it), fromTypeExpression(k)).putAnnotation(source, it), t).putAnnotation(source, it)
}
val t2 = if (args.isEmpty) t else
(args.take(args.size - 1) :\ v.Lambda(v.Irreversible().putAnnotation(source, it), args.last, t).putAnnotation(source, it)){
case (a, b) => v.Lambda(v.Irreversible().putAnnotation(source, it), a, b).putAnnotation(source, it)
@@ -297,7 +301,7 @@ class Converter {
fromExpression(it.getDescription)))
Seq(result)
case it: DefStmt =>
val args = (if (it.getTypeArguments != null) Seq(fromTupleTypeType(it.getTypeArguments)) else Seq()) ++
val args = (if (it.getTypeArguments != null) Seq(fromTypeExpression(it.getTypeArguments)) else Seq()) ++
(for (a <- it.getArguments) yield fromExpression(a))
val (body, jc) = if (it.getValueType != null) {
// value with type
@@ -406,18 +410,6 @@ class Converter {
case _ =>
v.Tuple().putAnnotation(source, it)
}
def fromTupleTypeType(it: TupleTypeTypeExpr): v.Expression =
if (it.getArguments.size == 1 &&
!it.isForceTuple())
v.Variable(v.VariableIdentity.setName(new v.VariableIdentity, Symbol(it.getArguments.get(0).getName)), true).
putAnnotation(source, it.getArguments.get(0))
else
v.TupleType(it.getArguments.map{
case tv =>
v.Variable(v.VariableIdentity.setName(new v.VariableIdentity, Symbol(tv.getName)), true).
putAnnotation(source, tv)
}:_*).putAnnotation(source, it)
val regex = Pattern.compile("(0D|0X|0O|0B)?([0-9A-F]+)(?:\\.([0-9A-F]+))?(?:(?:E|P)((?:\\+|-)?[0-9A-F]+))?")
def fromNumber(it: NumberLiteral): v.NumberLiteral = {
@@ -2,7 +2,12 @@ package org.bynar.versailles.xtext
import org.bynar.versailles.DocBookGenerator
import org.bynar.versailles.Statement
import org.bynar.versailles.PrettyPrinter
import org.bynar.versailles.Simplifier
class DocBookGeneratorFactory {
def create(root: Statement): DocBookGenerator = new DocBookGenerator(root)
def create(root: Statement): DocBookGenerator = new DocBookGenerator(root) {
val pp = new PrettyPrinter
val simp = new Simplifier
}
}
@@ -14,10 +14,10 @@ Sep hidden (WS, ML_COMMENT, SL_COMMENT):
Name: ID_LOWER | "pass" | "fail" | "let" | "forget" | "remember" | "def" | "letdef" | "type" | "lettype" |
"if" | "else" | "fi" | "case" | "match" | "in" | "from" | "loop" | "until" | "do" |
"module" | "for" | "where" | ID_BACKTICK
"module" | "for" | "where" | "abstract" | ID_BACKTICK | TypeName
;
TypeName: ID_UPPER | ID_FORWARDTICK;
TypeNamePath: steps+=TypeName ("." steps+=TypeName)*;
NamePath: steps+=Name ("." steps+=Name)*;
Statement:
@@ -29,11 +29,12 @@ Statement:
| {IfStmt} "if" condition=Expression "then" then=Statements (=> "else" else=Statements)? ("fi" assertion=Expression)?
| {LoopStmt} ("from" assertion=Expression)? ("do" do=Statements)? ("loop" loop=Statements)? "until" condition=Expression
| {CaseStmt} "case" case=LambdaExpr
| {DefStmt} ("def"|let?="letdef") name=Name (typeArguments=TupleTypeTypeExpr)? (arguments+=TupleExpr)* (title=STRING)? (description=InterpolatedString)?
| {DefStmt} ("def"|let?="letdef") name=Name (typeArguments=TupleTypeExpr)? (arguments+=TupleExpr)* (title=STRING)? (description=InterpolatedString)?
( janusClass=JanusClassExpression name2=Name? results=TupleExpr (title2=STRING)? (description2=InterpolatedString)? ("{" statements=Statements "}")?
| ":" valueType=TypeExpression "=" value=Expression)
| {TypeStmt} ("type"|let?="lettype") name=TypeName typeArguments=TupleTypeTypeExpr? (valueArguments+=TupleExpr)* (title=STRING)? (description=InterpolatedString)? "=" type=TypeExpression
| {ModuleStmt} "module" path=TypeNamePath (title=STRING)? (description=InterpolatedString)? "{" statements=Statements "}"
| {TypeStmt} ("type"|let?="lettype") name=Name typeArguments=TupleTypeExpr? (arguments+=TupleExpr)* (title=STRING)? (description=InterpolatedString)?
(":" kind=TypeExpression)? "=" type=TypeExpression
| {ModuleStmt} "module" path=NamePath (title=STRING)? (description=InterpolatedString)? "{" statements=Statements "}"
;
Statements:
{Statements} ((statements+=Statement)? Sep)*
@@ -96,7 +97,7 @@ ExpressionUn returns Expression:
ExpressionAppl returns Expression:
ExpressionSimple ( {ApplicationExpr.function=current} => argument=TupleExpr
| {TypeApplicationExpr.function=current} => argument=TupleTypeExpr
| {MemberAccessExpr.base=current} => "." memberName=(Name|TypeName))*
| {MemberAccessExpr.base=current} => "." memberName=Name)*
;
ExpressionSimple returns Expression:
Variable
@@ -107,7 +108,6 @@ ExpressionSimple returns Expression:
| InterpolatedString
| TupleExpr
| {TypeExpr} "@" type=TypeExpression
| {TypeExpr} type=TypeVariable
| {SpecialVariable} "_"
;
Variable:
@@ -141,33 +141,25 @@ TypeModifiers returns TypeExpression:
TypeExtension
;
TypeExtension returns TypeExpression:
TypeValueConcretion ({TypeExtension.base=current} => "{" block=Statements "}")*
;
TypeValueConcretion returns TypeExpression:
TypeConcretion ({TypeValueConcretion.function=current} => argument=TupleExpr)*
TypeConcretion ({TypeExtension.base=current} => "{" block=Statements "}")*
;
TypeConcretion returns TypeExpression:
TypeSub ({TypeConcretion.base=current} => argument=TupleTypeExpr)?
;
TypeSub returns TypeExpression:
TypeSimple ({TypeMemberAccessExpr.base=current} => "." memberName=(Name|TypeName))*
TypeSimple ( {TypeValueConcretion.function=current} => argument=TupleExpr
| {TypeConcretion.base=current} => argument=TupleTypeExpr
| {TypeMemberAccessExpr.base=current} => "." memberName=Name)*
;
TypeSimple returns TypeExpression:
{AbstractTypeExpr} "abstract"
| {TypeNumberLiteral} value=NUMBER
| {TypeStringLiteral} value=STRING
| {ValueType} value=TupleExpr
| {ValueType} "type" value=Expression
| TypeVariable
| TupleTypeExpr
| "(" TypeExpression ")"
;
TypeVariable:
name=TypeName
;
TypeVariableDefinition:
variance=("+"|"-")? name=TypeName
;
TupleTypeTypeExpr:
{TupleTypeTypeExpr} "[" (arguments+=TypeVariableDefinition ("," arguments+=TypeVariableDefinition)*)? (forceTuple?=",")? "]"
;
TupleTypeExpr returns TypeExpression:
{TupleTypeExpr} "[" "]"
| {TupleTypeExpr} "[" => positional+=TypeExpression ("," positional+=TypeExpression)* ("," names+=Name ":" named+=TypeExpression)* (forceTuple?=",")? "]"
@@ -16,13 +16,33 @@ import org.bynar.versailles.Variable
import org.bynar.versailles.xtext.versaillesLang.MatchExpr
import org.bynar.versailles.xtext.Converter
import com.google.inject.Inject
import org.bynar.versailles.xtext.versaillesLang.InterpolatedString
import org.eclipse.emf.ecore.EStructuralFeature
import org.xml.sax.SAXParseException
import org.bynar.versailles.xtext.versaillesLang.VersaillesLangPackage
import scala.xml.XML
import org.bynar.versailles.xtext.versaillesLang.TypeStmt
import org.bynar.versailles.xtext.versaillesLang.DefStmt
import org.bynar.versailles.xtext.versaillesLang.ModuleStmt
class VersaillesLangValidator extends AbstractVersaillesLangValidator {
@Inject
val converter: Converter = null
@Inject
val variableAnalyzer: VariableAnalyzer = null
def checkDescription(description: InterpolatedString, feature: EStructuralFeature) {
if (description != null && description.getStrings != null) {
val text = description.getStrings().map{ s => s.substring(1, s.size - 1) }.mkString("")
try {
XML.loadString("<root>" + text + "</root>")
} catch {
case e: SAXParseException =>
error(e.getLocalizedMessage, feature)
}
}
}
@Check
def checkBlock(block: BlockExpr) {
@@ -71,4 +91,18 @@ class VersaillesLangValidator extends AbstractVersaillesLangValidator {
}
showErrors(newIt)
}
@Check
def checkTypeStmtDescription(stmt: TypeStmt) {
checkDescription(stmt.getDescription, VersaillesLangPackage.eINSTANCE.getTypeStmt_Description)
}
@Check
def checkDefStmtDescription(stmt: DefStmt) {
checkDescription(stmt.getDescription, VersaillesLangPackage.eINSTANCE.getDefStmt_Description)
checkDescription(stmt.getDescription2, VersaillesLangPackage.eINSTANCE.getDefStmt_Description2)
}
@Check
def checkModuleStmtDescription(stmt: ModuleStmt) {
checkDescription(stmt.getDescription, VersaillesLangPackage.eINSTANCE.getModuleStmt_Description)
}
}
Oops, something went wrong.

0 comments on commit 334c60f

Please sign in to comment.