isac-java/src/java/isac/gui/mawen/editor/TransformAstUtil.scala
changeset 5213 1f3173a59903
parent 5212 51971c00458f
equal deleted inserted replaced
5212:51971c00458f 5213:1f3173a59903
    31   def UnBox(ast: Ast) = ast match {
    31   def UnBox(ast: Ast) = ast match {
    32      case Appl(List(Constant(str), a)) if str.startsWith("BOX") => a
    32      case Appl(List(Constant(str), a)) if str.startsWith("BOX") => a
    33      case _ =>  throw new AstException("UnBox, Box has a false structure(required: Appl(List(Constant(\"BOX.1\"), ast), get: " + raw_string_of(ast) + ")")
    33      case _ =>  throw new AstException("UnBox, Box has a false structure(required: Appl(List(Constant(\"BOX.1\"), ast), get: " + raw_string_of(ast) + ")")
    34   }
    34   }
    35   def BoxNextChild(c: AstContainer) = {
    35   def BoxNextChild(c: AstContainer) = {
    36      val boxAst = AstInfoUtil.FindBox(c.getAst())
    36      AstInfoUtil.FindBox(c.getAst()) match {
    37      if (boxAst != null) {// check if there is a box
    37        case None => {}
    38        val boxAstElem  = TransformAstUtil.UnBox(boxAst) // get ast from Appl(Cursor, ast)
    38        case Some(boxAst) => {// check if there is a box
    39        val unboxedroot = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox) // remove Box from Root Ast
    39          val boxAstElem  = TransformAstUtil.UnBox(boxAst) // get ast from Appl(Cursor, ast)
    40        AstInfoUtil.Parent(unboxedroot, boxAstElem) match {
    40          val unboxedroot = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox) // remove Box from Root Ast
    41          case Some(parentAst) => c.setAst(TransformAstUtil.Update(unboxedroot, AstInfoUtil.NextChild(parentAst, boxAstElem), TransformAstUtil.Box))
    41          AstInfoUtil.Parent(unboxedroot, boxAstElem) match {
    42          case None => {}
    42            case Some(parentAst) => c.setAst(TransformAstUtil.Update(unboxedroot, AstInfoUtil.NextChild(parentAst, boxAstElem), TransformAstUtil.Box))
       
    43            case None => {}
       
    44          }
    43        }
    45        }
    44        
       
    45       
       
    46      }
    46      }
    47   }
    47   }
    48   def BoxPrevChild(c: AstContainer) = {
    48   def BoxPrevChild(c: AstContainer) =  AstInfoUtil.FindBox(c.getAst()) match {
    49      val boxAst = AstInfoUtil.FindBox(c.getAst())
    49     case None => {}
    50      if (boxAst != null) {// check if there is a box
    50     case Some(boxAst) => {
    51        val boxAstElem  = TransformAstUtil.UnBox(boxAst)
    51        val boxAstElem  = TransformAstUtil.UnBox(boxAst)
    52        val unboxedAst = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox)
    52        val unboxedAst = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox)
    53        AstInfoUtil.Parent(unboxedAst, boxAstElem) match {
    53        AstInfoUtil.Parent(unboxedAst, boxAstElem) match {
    54          case Some(parentAst) => c.setAst(TransformAstUtil.Update(unboxedAst, AstInfoUtil.PrevChild(parentAst, boxAstElem), TransformAstUtil.Box))
    54          case Some(parentAst) => c.setAst(TransformAstUtil.Update(unboxedAst, AstInfoUtil.PrevChild(parentAst, boxAstElem), TransformAstUtil.Box))
    55          case None => {}
    55          case None => {}
    56        }
    56        }
    57        
       
    58      }
    57      }
    59   }
    58   }
    60   def BoxParent(c: AstContainer) = {
    59   def BoxParent(c: AstContainer) = AstInfoUtil.FindBox(c.getAst()) match{
    61      val boxAst = AstInfoUtil.FindBox(c.getAst())
    60     case None => {}
    62      if (boxAst != null) {// check if there is a box
    61     case Some(boxAst) =>  {// check if there is a box
    63        val boxAstElem  = TransformAstUtil.UnBox(boxAst)
    62        val boxAstElem  = TransformAstUtil.UnBox(boxAst)
    64        val unboxedAst = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox)
    63        val unboxedAst = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox)
    65        AstInfoUtil.Parent(unboxedAst, boxAstElem) match {
    64        AstInfoUtil.Parent(unboxedAst, boxAstElem) match {
    66          case Some(parentAst) => c.setAst(TransformAstUtil.Update(unboxedAst, parentAst, TransformAstUtil.Box))
    65          case Some(parentAst) => c.setAst(TransformAstUtil.Update(unboxedAst, parentAst, TransformAstUtil.Box))
    67          case None => {}
    66          case None => {}
    68        }
    67        }
    69        
       
    70      }
    68      }
       
    69     
    71   }
    70   }
    72   def BoxChild(c: AstContainer) = {
    71   def BoxChild(c: AstContainer) = {
    73      val boxAst = AstInfoUtil.FindBox(c.getAst())
    72      AstInfoUtil.FindBox(c.getAst()) match {
    74      if (boxAst != null) { // check if there is a box
    73        case None => {}
    75        val boxAstElem  = TransformAstUtil.UnBox(boxAst)
    74        case Some(boxAst) => {
    76        if (AstInfoUtil.FirstChild(boxAstElem) != null) {
    75          val boxAstElem  = TransformAstUtil.UnBox(boxAst)
    77          val unboxedAst = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox)
    76          if (AstInfoUtil.FirstChild(boxAstElem) != null) {
    78           AstInfoUtil.FirstChild(boxAstElem) match {
    77            val unboxedAst = TransformAstUtil.Update(c.getAst(), boxAst, TransformAstUtil.UnBox)
    79            case Some(a) => c.setAst(TransformAstUtil.Update(unboxedAst, a, TransformAstUtil.Box))
    78             AstInfoUtil.FirstChild(boxAstElem) match {
    80            case None => {}
    79              case Some(a) => c.setAst(TransformAstUtil.Update(unboxedAst, a, TransformAstUtil.Box))
       
    80              case None => {}
       
    81            }
       
    82            
    81          }
    83          }
    82          
       
    83        }
    84        }
    84      }
    85      }
       
    86     
       
    87        
       
    88      
    85   }
    89   }
    86   def CursorNextChild(c: AstContainer) = {
    90   def CursorNextChild(c: AstContainer) = {
    87      val boxAst = AstInfoUtil.FindCursor(c.getAst())
    91      val boxAst = AstInfoUtil.FindCursor(c.getAst())
    88      if (boxAst != null) {
    92      if (boxAst != null) {
    89        val boxAstElem  = TransformAstUtil.CursorToAst(boxAst) // get ast from Appl(Cursor, ast)
    93        val boxAstElem  = TransformAstUtil.CursorToAst(boxAst) // get ast from Appl(Cursor, ast)