Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a = 1;
- int b = 2;
- boolean sleepSuccess = doSleep(2000); // sleep two seconds
- int c = 3;
- int d = 4;
- int a = 1;
- int b = 2;
- doSleep(2000, new DoSleepCallback() {
- public void onTrigger(boolean rc) {
- boolean sleepSuccess = rc;
- int c = 3;
- int d = 4;
- }
- });
- grammar org.qedlang.qed.QED with jbase.Jbase // Jbase inherits Xbase
- ...
- FunctionDeclaration return XExpression:
- =>({FunctionDeclaration} type=JvmTypeReference name=ValidID '(')
- (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)?
- ')' block=XBlockExpression
- ;
- boolean doSleep(int millis) {} // async FunctionDeclaration element stub
- public static class DoSleepCallback() {
- public abstract void onTrigger(boolean rc);
- }
- public void doSleep(int millis, DoSleepCallback callback) {
- <perform sleep and call callback.onTrigger(<success>)>
- }
- override appendFeatureCall(XAbstractFeatureCall call, ITreeAppendable b) {
- ...
- val feature = call.feature
- ...
- if (feature instanceof JvmExecutable) {
- b.append('(')
- val arguments = call.actualArguments
- if (!arguments.isEmpty) {
- ...
- arguments.appendArguments(b, shouldBreakFirstArgument)
- // HERE IS THE PART I DON'T KNOW HOW TO DO
- <IF feature IS A FunctionDeclaration>
- <argument.appendArgument(NEW GENERATED CALLBACK PARAMETER)>
- <INSERT REST OF XBlockExpression body INSIDE CALLBACK INSTANCE>
- <ENDIF>
- }
- b.append(');')
- }
- }
- def void inferExpressions(JvmDeclaredType it, FunctionDeclaration function) {
- // now let's go over the features
- for ( f : (function.block as XBlockExpression).expressions ) {
- if (f instanceof FunctionDeclaration) {
- members += f.toClass(f.fullyQualifiedName) [
- inferVariables(f)
- superTypes += typeRef(FunctionDeclarationObject)
- // let's add a default constructor
- members += f.toConstructor [
- for (p : f.params)
- parameters += p.toParameter(p.name, p.parameterType)
- body = f.block
- ]
- inferExpressions(f)
- ]
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement