Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
MatDau committed Aug 31, 2020
1 parent 09de1de commit f78c33e
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ BlockExpression:
;

VariableDeclaration:
{VariableDeclaration} typeobject='var' =>(name=ID '=' (right=ArithmeticExpression | right=Object | right=FlyFunctionCall | right=DeclarationObject)) (onCloud?='on' environment+=[VariableDeclaration] (',' environment+=[VariableDeclaration])* )? |
{ConstantDeclaration} typeobject='const' =>(name = ID '=' (right=ArithmeticExpression | right=Object ))
{VariableDeclaration} typeobject='var' =>(name=ID '=' (right=ArithmeticExpression | right=FlyFunctionCall | right=DeclarationObject | right=Object)) (onCloud?='on' environment+=[VariableDeclaration] (',' environment+=[VariableDeclaration])* )? |
{ConstantDeclaration} typeobject='const' =>(name = ID '=' (right=ArithmeticExpression | right=Object ))
;

Object:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ Workflow {
generate = true
}

// validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
// }
validator={
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
composedCheck ="org.xtext.validation.FLYValidator"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ class FLYGenerator extends AbstractGenerator {
fsa.generateFile(name + ".java", resource.compileJava)
// generate .js or .py file
for (element : resource.allContents.toIterable.filter(FlyFunctionCall)) {
var type_env = ((element.environment.right as DeclarationObject).features.get(0) as DeclarationFeature).
value_s;
var type_env = ((element.environment.right as DeclarationObject).features.get(0) as DeclarationFeature).value_s;
var async = element.isAsync;
if(type_env.equals("smp") && ((element.environment.right as DeclarationObject).features.length==3)){
if(((element.environment.right as DeclarationObject).features.get(2) as DeclarationFeature).value_s.contains("python")){
Expand Down Expand Up @@ -128,7 +127,6 @@ class FLYGenerator extends AbstractGenerator {
}
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ class FLYScopeProvider extends AbstractFLYScopeProvider {
val allElements = exp.getContainerOfType(typeof(Fly)).elements
val containingElement = allElements.findFirst[isAncestor(it, exp)]
for (element : allElements.subList(0, allElements.indexOf(containingElement)).typeSelect(
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[(right as DeclarationObject).features.get(0).value_s.equals("channel")]) {
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[!((right as DeclarationObject).features.get(0).value_s.nullOrEmpty)].filter[(right as DeclarationObject).features.get(0).value_s.equals("channel")]) {
elements.add(element)
}
for (element : allElements.subList(0, allElements.indexOf(containingElement)).typeSelect(
typeof(ConstantDeclaration))) {
elements.add(element)
}
for (element : allElements.subList(0, allElements.indexOf(containingElement)).typeSelect(
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[list_environment.contains((right as DeclarationObject).features.get(0).value_s)]) {
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[!((right as DeclarationObject).features.get(0).value_s.nullOrEmpty)].filter[list_environment.contains((right as DeclarationObject).features.get(0).value_s)]) {
elements.add(element)
}
for (element : allElements.subList(0, allElements.indexOf(containingElement)).typeSelect(
Expand Down Expand Up @@ -116,19 +116,19 @@ class FLYScopeProvider extends AbstractFLYScopeProvider {
declaration.add(element)
}
for (element : allElements.subList(0, allElements.indexOf(containingElement) + 1).typeSelect(
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[(right as DeclarationObject).features.get(0).value_s.equals("DataFrame")]) {
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[!((right as DeclarationObject).features.get(0).value_s.nullOrEmpty)].filter[(right as DeclarationObject).features.get(0).value_s.equals("DataFrame")]) {
declaration.add(element)
}
for (element : allElements.subList(0, allElements.indexOf(containingElement) + 1).typeSelect(
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[(right as DeclarationObject).features.get(0).value_s.equals("channel")]) {
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[!((right as DeclarationObject).features.get(0).value_s.nullOrEmpty)].filter[(right as DeclarationObject).features.get(0).value_s.equals("channel")]) {
declaration.add(element)
}
for (element : allElements.subList(0, allElements.indexOf(containingElement) + 1).typeSelect(
typeof(FunctionDefinition))) {
declaration.add(element)
}
for (element : allElements.subList(0, allElements.indexOf(containingElement) + 1).typeSelect(
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[list_environment.contains((right as DeclarationObject).features.get(0).value_s)]) {
typeof(VariableDeclaration)).filter[right instanceof DeclarationObject].filter[!((right as DeclarationObject).features.get(0).value_s.nullOrEmpty)].filter[list_environment.contains((right as DeclarationObject).features.get(0).value_s)]) {
declaration.add(element)
}
return declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import org.eclipse.emf.ecore.EObject
import org.xtext.fLY.FunctionDefinition
import org.xtext.fLY.Fly
import org.xtext.fLY.FunctionReturn
import org.xtext.fLY.VariableDeclaration
import org.xtext.fLY.DeclarationObject
import org.xtext.fLY.FlyFunctionCall
import java.util.ArrayList
import java.util.Arrays

/**
* This class contains custom validation rules.
Expand All @@ -25,7 +30,182 @@ import org.xtext.fLY.FunctionReturn
*/
class FLYValidator extends AbstractFLYValidator {

////@Inject extension FlyTypeProvider
public static val MISSING_ATTR = "org.text.fly.MissingAttribute"
public static val WRONG_ATTR_TYPE = "org.text.fly.WrongAttributeType"
public static val WRONG_ATTR = "org.text.fly.WrongAttribute"
public static val WRONG_LOCAL_NUM = "org.text.fly.WrongLocalDefinitionLength"

public static val WRONG_AWS_DECLARATION = "org.xtext.fly.WrongAWSDeclaration"
public static val WRONG_AWS_NUM = ""
public static val WRONG_AWS_CONC = ""
public static val WRONG_AWS_MEM = ""
public static val WRONG_AWS_TIME = ""

public static val WRONG_AZURE_DECLARATION = "org.xtext.fly.WrongAzureDeclaration"
public static val WRONG_AZURE_NUM = ""
public static val WRONG_AZURE_CONC = ""
public static val WRONG_AZURE_TIME = ""

public static ArrayList listEnvironment = new ArrayList(Arrays.asList("aws","aws-local","azure","local"));


//@Check
def checkVariableDeclaration(VariableDeclaration dec){

if(dec.right instanceof DeclarationObject){
if((dec.right as DeclarationObject).features.get(0).feature != "type"){
error("Missing type attribute",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,MISSING_ATTR)

}

if((dec.right as DeclarationObject).features.get(0).value_s.nullOrEmpty){
error("Attribute type must be a non-empty String",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_ATTR_TYPE)
}
var type = (dec.right as DeclarationObject).features.get(0).value_s
if (listEnvironment.contains(type)){
checkEnvironment(dec.right as DeclarationObject)
}else if(type.equals("channel")){

}else if(type.equals("random")){

}else if(type.equals("file")){

}else if(type.equals("dataframe")){

}

} else if(dec.right instanceof Object) {
return //nothing to check
}else if(dec.right instanceof ArithmeticException){
return //nothing to check
}else if(dec.right instanceof FlyFunctionCall){
return //nothing to check
}

}


//@Check
def checkEnvironment(DeclarationObject right){
var type = right.features.get(0).value_s
if(type.equals("local")){
if(right.features.length!=2){
error("Error in local environment declaration: wrong number of attributes.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_LOCAL_NUM)
}
if(!right.features.get(1).feature.equals("nthread")){
error("Error in local environment declaration: missing argument nthread.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_LOCAL_NUM)
}
if(right.features.get(1).value_t <= 2){
error("Error in local environment declaration: nthread must be an int grater than 2.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_LOCAL_NUM)
}
}else if(type.equals("aws") || type.equals("aws-debug")){
if(right.features.length!=9){
error("Error in AWS environment declaration: wrong number of attributes.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_NUM)
}
if(right.features.get(1).feature.equals("profile")){
error("Error in AWS environment declaration: missing argument user.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(1).value_s.isNullOrEmpty){
error("Error in AWS environment declaration: user must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(2).feature.equals("access_key")){
error("Error in AWS environment declaration: missing argument access_key.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(2).value_s.isNullOrEmpty){
error("Error in AWS environment declaration: access_key must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(3).feature.equals("secret_key")){
error("Error in AWS environment declaration: missing argument secret_key.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(3).value_s.isNullOrEmpty){
error("Error in AWS environment secret_key: user must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(4).feature.equals("region")){
error("Error in AWS environment declaration: missing argument region.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(4).value_s.isNullOrEmpty){
error("Error in AWS environment declaration: region must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(5).feature.equals("language")){
error("Error in AWS environment declaration: missing argument language.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(5).value_s.isNullOrEmpty){
error("Error in AWS environment declaration: language must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(6).feature.equals("concurrency")){
error("Error in AWS environment declaration: missing argument concurrency.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(6).value_t<=2 || right.features.get(6).value_t>1000 ){
error("Error in AWS environment declaration: concurrency must be an int between 2 and 1000.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_CONC)
}
if(right.features.get(7).feature.equals("memory")){
error("Error in AWS environment declaration: missing argument memory.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(7).value_t<128 || right.features.get(7).value_t>3008){
error("Error in AWS environment declaration: memory must be an int between 128 and 3008.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_MEM)
}
if(right.features.get(8).feature.equals("time_limit")){
error("Error in AWS environment declaration: missing argument time_limit.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_DECLARATION)
}
if(right.features.get(8).value_t<=0 || right.features.get(8).value_t>900){
error("Error in AWS environment declaration: time_limit must be an int between 0 and 900.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AWS_TIME)
}
}else if(type.equals("azure")){
if(right.features.length!=9){
error("Error in Azure environment declaration: wrong number of attributes.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_NUM)
}
if(right.features.get(1).feature.equals("client_id")){
error("Error in Azure environment declaration: missing argument client_id.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(1).value_s.isNullOrEmpty){
error("Error in Azure environment declaration: client_id must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(2).feature.equals("tenant_id")){
error("Error in Azure environment declaration: missing argument tenant_id.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(2).value_s.isNullOrEmpty){
error("Error in Azure environment declaration: tenant_id must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(3).feature.equals("secret_key")){
error("Error in Azure environment declaration: missing argument secret_key.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(3).value_s.isNullOrEmpty){
error("Error in Azure environment declaration: secret_key must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(4).feature.equals("subscription_id")){
error("Error in Azure environment declaration: missing argument subscription_id.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(4).value_s.isNullOrEmpty){
error("Error in Azure environment declaration: subscription_id must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(5).feature.equals("region")){
error("Error in Azure environment declaration: missing argument region.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(5).value_s.isNullOrEmpty){
error("Error in Azure environment declaration: region must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(6).feature.equals("language")){
error("Error in Azure environment declaration: missing argument language.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(6).value_s.isNullOrEmpty){
error("Error in Azure environment declaration: language must be a non-empty string.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_DECLARATION)
}
if(right.features.get(7).feature.equals("concurrency")){
error("Error in Azure environment declaration: missing argument concurrency.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_CONC)
}
if(right.features.get(7).value_t<2 || right.features.get(7).value_t>1000){
error("Error in Azure environment declaration: concurrency must be an int between 2 and 1000.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_CONC)
}
if(right.features.get(8).feature.equals("time_limit")){
error("Error in Azure environment declaration: missing argument time_limit.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_TIME)
}
if(right.features.get(8).value_t<=0 || right.features.get(8).value_t>600){
error("Error in Azure environment declaration: time_limit must be an int between 0 and 600.",FLYPackage.Literals::VARIABLE_DECLARATION__RIGHT,WRONG_AZURE_TIME)
}
}
}

//@Inject extension FlyTypeProvider
//
// public static val FORWARD_REFERENCE = "org.text.fly.ForwardReference";
//
Expand Down
4 changes: 2 additions & 2 deletions docs/_site/docs/bootstrap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<meta property="og:url" content="http://localhost:4000/docs/bootstrap/" />
<meta property="og:site_name" content="FLY Language" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2020-01-09T21:50:23+01:00" />
<meta property="article:published_time" content="2020-01-24T18:35:41+01:00" />
<script type="application/ld+json">
{"description":"Buttons Default Primary Success Info Warning Danger Link Default Primary Success Info Warning Danger Link Default Action Another action Something else here Separated link","headline":"Bootstrap Features","dateModified":"2020-01-09T21:50:23+01:00","datePublished":"2020-01-09T21:50:23+01:00","@type":"WebPage","url":"http://localhost:4000/docs/bootstrap/","@context":"https://schema.org"}</script>
{"description":"Buttons Default Primary Success Info Warning Danger Link Default Primary Success Info Warning Danger Link Default Action Another action Something else here Separated link","headline":"Bootstrap Features","dateModified":"2020-01-24T18:35:41+01:00","datePublished":"2020-01-24T18:35:41+01:00","@type":"WebPage","url":"http://localhost:4000/docs/bootstrap/","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->


Expand Down
4 changes: 2 additions & 2 deletions docs/_site/docs/cheatsheet/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<meta property="og:url" content="http://localhost:4000/docs/cheatsheet/" />
<meta property="og:site_name" content="FLY Language" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2020-01-09T21:50:23+01:00" />
<meta property="article:published_time" content="2020-01-24T18:35:41+01:00" />
<script type="application/ld+json">
{"description":"From adam-p/markdown-here","headline":"Markdown Cheatsheet","dateModified":"2020-01-09T21:50:23+01:00","datePublished":"2020-01-09T21:50:23+01:00","@type":"WebPage","url":"http://localhost:4000/docs/cheatsheet/","@context":"https://schema.org"}</script>
{"description":"From adam-p/markdown-here","headline":"Markdown Cheatsheet","dateModified":"2020-01-24T18:35:41+01:00","datePublished":"2020-01-24T18:35:41+01:00","@type":"WebPage","url":"http://localhost:4000/docs/cheatsheet/","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->


Expand Down
4 changes: 2 additions & 2 deletions docs/_site/docs/customization/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<meta property="og:url" content="http://localhost:4000/docs/customization/" />
<meta property="og:site_name" content="FLY Language" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2020-01-09T21:50:23+01:00" />
<meta property="article:published_time" content="2020-01-24T18:35:41+01:00" />
<script type="application/ld+json">
{"description":"This template uses bootstrap-sass along with bootwatch themes. You can create your own theme by writing your own sass files.","headline":"Customization","dateModified":"2020-01-09T21:50:23+01:00","datePublished":"2020-01-09T21:50:23+01:00","@type":"WebPage","url":"http://localhost:4000/docs/customization/","@context":"https://schema.org"}</script>
{"description":"This template uses bootstrap-sass along with bootwatch themes. You can create your own theme by writing your own sass files.","headline":"Customization","dateModified":"2020-01-24T18:35:41+01:00","datePublished":"2020-01-24T18:35:41+01:00","@type":"WebPage","url":"http://localhost:4000/docs/customization/","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->


Expand Down

0 comments on commit f78c33e

Please sign in to comment.