Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. int a = 1;
  2. int b = 2;
  3. boolean sleepSuccess = doSleep(2000); // sleep two seconds
  4. int c = 3;
  5. int d = 4;
  6.  
  7. int a = 1;
  8. int b = 2;
  9. doSleep(2000, new DoSleepCallback() {
  10. public void onTrigger(boolean rc) {
  11. boolean sleepSuccess = rc;
  12. int c = 3;
  13. int d = 4;
  14. }
  15. });
  16.  
  17. grammar org.qedlang.qed.QED with jbase.Jbase // Jbase inherits Xbase
  18.  
  19. ...
  20.  
  21. FunctionDeclaration return XExpression:
  22. =>({FunctionDeclaration} type=JvmTypeReference name=ValidID '(')
  23. (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)?
  24. ')' block=XBlockExpression
  25. ;
  26.  
  27. boolean doSleep(int millis) {} // async FunctionDeclaration element stub
  28.  
  29. public static class DoSleepCallback() {
  30. public abstract void onTrigger(boolean rc);
  31. }
  32. public void doSleep(int millis, DoSleepCallback callback) {
  33. <perform sleep and call callback.onTrigger(<success>)>
  34. }
  35.  
  36. override appendFeatureCall(XAbstractFeatureCall call, ITreeAppendable b) {
  37. ...
  38. val feature = call.feature
  39. ...
  40. if (feature instanceof JvmExecutable) {
  41. b.append('(')
  42.  
  43. val arguments = call.actualArguments
  44.  
  45. if (!arguments.isEmpty) {
  46. ...
  47. arguments.appendArguments(b, shouldBreakFirstArgument)
  48.  
  49. // HERE IS THE PART I DON'T KNOW HOW TO DO
  50. <IF feature IS A FunctionDeclaration>
  51. <argument.appendArgument(NEW GENERATED CALLBACK PARAMETER)>
  52. <INSERT REST OF XBlockExpression body INSIDE CALLBACK INSTANCE>
  53. <ENDIF>
  54. }
  55.  
  56. b.append(');')
  57. }
  58. }
  59.  
  60. def void inferExpressions(JvmDeclaredType it, FunctionDeclaration function) {
  61. // now let's go over the features
  62. for ( f : (function.block as XBlockExpression).expressions ) {
  63. if (f instanceof FunctionDeclaration) {
  64. members += f.toClass(f.fullyQualifiedName) [
  65. inferVariables(f)
  66. superTypes += typeRef(FunctionDeclarationObject)
  67.  
  68. // let's add a default constructor
  69. members += f.toConstructor [
  70. for (p : f.params)
  71. parameters += p.toParameter(p.name, p.parameterType)
  72. body = f.block
  73. ]
  74. inferExpressions(f)
  75. ]
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement