Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Fix transform syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasun authored and Kasun committed Sep 2, 2019
1 parent 80f09b3 commit b862104
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ gotools: gotools/todos
.PHONY: generate
generate: generate/todos

.PHONY: validate
validate: validate/todos

.PHONY: compile
compile: todos_client/todos todos_server/todos

Expand All @@ -26,6 +29,7 @@ GRAMMAR = grammars/go.gen.g
TYPES_TRANSFORM_INPUT = $(TYPES_TRANSFORM) $(GRAMMAR)

gen = $(SYSLGEN) gen --root-model . --root-transform . --transform $(1) --model examples/$(2).sysl --grammar $(GRAMMAR) --start goFile --outdir $(2)
validate = $(SYSLGEN) validate --grammar $(GRAMMAR) --start goFile --root-transform . --transform $(1)

clean/%:
-rm $*_client/$*-client
Expand All @@ -52,3 +56,10 @@ generate/%:
$(call gen,$(INTERFACE_TRANSFORM),$*)
$(call gen,$(HANDLER_TRANSFORM),$*)
$(call gen,$(ROUTER_TRANSFORM),$*)

validate/%:
$(call validate,$(TYPES_TRANSFORM),$*)
$(call validate,$(CLIENT_TRANSFORM),$*)
$(call validate,$(INTERFACE_TRANSFORM),$*)
$(call validate,$(HANDLER_TRANSFORM),$*)
$(call validate,$(ROUTER_TRANSFORM),$*)
24 changes: 12 additions & 12 deletions transforms/svc_client.sysl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CodeGenTransform:
)
)

!view makeValueExpr(strValue <: string) -> Expression:
!view makeValueExpr(strValue <: string) -> FuncArgsRest:
strValue -> (:
Expression = strValue -> <Expression>(:
ValueExpr = strValue
Expand All @@ -106,7 +106,7 @@ CodeGenTransform:
)
)

!view makeFunctionCall(funcName <: string, arg0 <: Expression, rest <: sequence of Expression) -> Expression:
!view makeFunctionCall(funcName <: string, arg0 <: Expression, rest <: sequence of Expression) -> FuncArgsRest:
funcName -> (:
Expression = funcName -> <Expression>(:
FunctionCall = funcName -> <FunctionCall>(:
Expand Down Expand Up @@ -141,10 +141,10 @@ CodeGenTransform:
DeclareAndAssignStmt = ep -> <DeclareAndAssignStmt> (:
Variables = "u, err"
let sprintfArg = formatArgs(ep).formatArgs
let params = ep.value.pathvars -> <string> (:
let params = ep.value.pathvars -> <FuncArgsRest> (:
Expression = makeValueExpr(.name).Expression
)
let getArgExpr = ep -> <Expression> (:
let getArgExpr = ep -> <FuncArgsRest> (:
Expression = makeGetArgExpr("s", "url")
)
let restArg = [getArgExpr] | params
Expand All @@ -159,19 +159,19 @@ CodeGenTransform:
Statement = ep -> <Statement> (:
ReturnStmt = ep -> <ReturnStmt> (:

let body = ep.value.params where("body" in .attrs.patterns) -> <Expression> (:
let body = ep.value.params where("body" in .attrs.patterns) -> <FuncArgsRest> (:
Expression = makeValueExpr(ToLower(Join(Split(.name, "_"), ""))).Expression
)

let nilExpr = ep -> <Expression> (:
let nilExpr = ep -> <FuncArgsRest> (:
Expression = makeValueExpr("nil").Expression
)

let body2 = if body count == 0 then [nilExpr] else body
let functionZeroExpr = ep -> <Expression>(:
let functionZeroExpr = ep -> <FuncArgsRest>(:
Expression = makeFunctionZero("u.String")
)
let getArgExpr = ep -> <Expression> (:
let getArgExpr = ep -> <FuncArgsRest> (:
Expression = makeGetArgExpr("s", "client")
)
let restofArgs = [getArgExpr, makeValueExpr('"' + ep.value.method + '"'), functionZeroExpr] | body2 | [makeValueExpr("headers"), makeValueExpr("required") , makeValueExpr("responses")]
Expand All @@ -187,13 +187,13 @@ CodeGenTransform:
DeclareAndAssignStmt = ep -> <DeclareAndAssignStmt> (:
Variables = "resp, err"
let args = buildSprintfCall(ep)
let params = ep.value.pathvars -> <string> (:
let params = ep.value.pathvars -> <FuncArgsRest> (:
Expression = makeValueExpr(.name).Expression
)
let getArgExprUrl = ep -> <Expression> (:
let getArgExprUrl = ep -> <FuncArgsRest> (:
Expression = makeGetArgExpr("s", "url")
)
let getArgExprClient = ep -> <Expression> (:
let getArgExprClient = ep -> <FuncArgsRest> (:
Expression = makeGetArgExpr("s", "client")
)
let restArg = [getArgExprUrl] | params
Expand Down Expand Up @@ -371,7 +371,7 @@ CodeGenTransform:
TypeName = "context.Context"
)

let httpHeader = ep -> <ParameterDecl>(:
let httpHeader = ep -> <ParameterList>(:
ParameterDecl = ep -> <ParameterDecl>(:
Identifier = "headers"
TypeName = "map[string]string"
Expand Down
20 changes: 10 additions & 10 deletions transforms/svc_handler.sysl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CodeGenTransform:
IfElseStmt = condition -> <IfElseStmt> (:
Expression = makeValueExpr(condition)
Block = condition -> <Block> (:
let interfaceCall = condition -> <Statement> (:
let interfaceCall = condition -> <StatementList> (:
Statement = condition -> <Statement> (:
DeclareAndAssignStmt = condition -> <DeclareAndAssignStmt> (:
Variables = "errResp"
Expand All @@ -65,10 +65,10 @@ CodeGenTransform:
FunctionName = "s.serviceInterface.GetErrorResponse"
FunctionArgs = condition -> <FunctionArgs> (:
Expression = makeValueExpr(errorCode)
let errMsgExpr = condition -> <Expression> (:
let errMsgExpr = condition -> <FuncArgsRest> (:
Expression = makeValueExpr(errorMsg)
)
let errObjExpr = condition -> <Expression> (:
let errObjExpr = condition -> <FuncArgsRest> (:
Expression = makeValueExpr(errorObj)
)
FuncArgsRest = [errMsgExpr, errObjExpr]
Expand All @@ -78,16 +78,16 @@ CodeGenTransform:
)
)
)
let sendResp = condition -><Statement> (:
let sendResp = condition -><StatementList> (:
Statement = condition -><Statement> (:
FunctionCall = condition -> <ReturnStmt> (:
FunctionName = "restlib.SendHTTPResponse"
FunctionArgs = condition -> <FunctionArgs> (:
Expression = makeValueExpr("w")
let badRequestExpr = condition -> <Expression> (:
let badRequestExpr = condition -> <FuncArgsRest> (:
Expression = makeValueExpr("http.StatusBadRequest")
)
let errRespExpr = condition -> <Expression> (:
let errRespExpr = condition -> <FuncArgsRest> (:
Expression = makeValueExpr("errResp")
)
FuncArgsRest = [badRequestExpr, errRespExpr]
Expand All @@ -96,7 +96,7 @@ CodeGenTransform:
)
)

let returnStmt = condition -> <Statement> (:
let returnStmt = condition -> <StatementList> (:
Statement = condition -> <Statement> (:
ReturnStmt = condition -> <ReturnStmt> (:
PayLoad = ""
Expand Down Expand Up @@ -330,7 +330,7 @@ CodeGenTransform:

Block = ep -> <Block>(:

let implCall = ep -> <Statement> (:
let implCall = ep -> <StatementList> (:
Statement = ep -> <Statement> (:
DeclareAndAssignStmt = ep -> <DeclareAndAssignStmt> (:
Variables = returnValues
Expand All @@ -346,7 +346,7 @@ CodeGenTransform:
)
)

let setHeadersCall = ep -> <Statement> (:
let setHeadersCall = ep -> <StatementList> (:
Statement = ep -> <Statement> (:
FunctionCall = ep -> <FunctionCall> (:
FunctionName = "restlib.SetHeaders"
Expand All @@ -360,7 +360,7 @@ CodeGenTransform:
)
)

let sendRespCall = ep -> <Statement> (:
let sendRespCall = ep -> <StatementList> (:
Statement = ep -> <Statement> (:
FunctionCall = ep -> <FunctionCall> (:
FunctionName = "restlib.SendHTTPResponse"
Expand Down
2 changes: 1 addition & 1 deletion transforms/svc_interface.sysl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CodeGenTransform:
methodName = GoName(method + Join(methodPostfix flatten(.out), "")).out
)

!view panicBlock(methodName <: string) -> StatementList:
!view panicBlock(methodName <: string) -> Block:
methodName -> (:
StatementList = [methodName] -> <StatementList> (:
Statement = methodName -> <Statement> (:
Expand Down

0 comments on commit b862104

Please sign in to comment.