Changeset 02d65b0 in tol


Ignore:
Timestamp:
Sep 21, 2009, 10:21:31 PM (17 years ago)
Author:
Jorge Pérez <josp.jorge@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
3e62049
Parents:
5c99964
Message:

new functions TolObj2TclObj and TolObj2TclObjNamed to convert from a
TOL object to an "equivalente" Tcl object

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1418 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tolbase/lib/byswidget/bfunctions/bftoltcl.tcl

    r5c99964 r02d65b0  
    628628    "date" {
    629629      set delimeter {' '}
    630       set gestor [string trim [TclGetVar Text DBA] {"}]
     630      set gestor [string trim [TclGetVar Text DBA] {"}]; #"
    631631
    632632      switch $gestor {
    … …  
    652652}
    653653
    654 
    655 
    656654#///////////////////////////////////////////////////////////////////////////
    657655proc EvalTolExp {grammar expression {seed _tempName}} {
    … …  
    668666  return $lstRes
    669667}
     668
     669#///////////////////////////////////////////////////////////////////////////
     670proc TolObj2TclObj { obj } {
     671# PURPUSE: Dado una referencia a un objeto TOL retorna una representacion en
     672#          TCL equivalente. Esta funcion debe reemplazar a TolSet2TclLst.
     673#
     674# RETURN: Un objeto Tcl que representa el contenido del objeto TOL
     675#
     676#///////////////////////////////////////////////////////////////////////////
     677 #puts "obj = $obj"
     678  set vinfo [ tol::info variable $obj ]
     679  set grammar [ lindex $vinfo 0 ]
     680  if { $grammar eq "Set" || $grammar eq "NameBlock" } {
     681    set result [ list ]
     682    set idx 1
     683    tol::foreach it $obj {
     684      array set it_info $it
     685      #puts "$it_info(grammar) $it_info(name) $it_info(content) "
     686      set G $it_info(grammar)
     687      if { $G eq "Set" || $G eq "NameBlock" } {
     688        set value [ TolObj2TclObj [ eval list $obj $idx ] ]
     689      } else {
     690        set value $it_info(content)
     691      }
     692      lappend result $value
     693      incr idx
     694    }
     695    set result
     696  } else {
     697    lindex $vinfo 2
     698  }
     699}
     700
     701#///////////////////////////////////////////////////////////////////////////
     702proc TolObj2TclObjNamed { obj } {
     703# PURPUSE: Dado una referencia a un objeto TOL retorna una representacion en
     704#          TCL equivalente manteniendo los nombres de los objetos TOL.
     705#          Si alguno de los objetos no tiene nombre se le asigna el nombre "".
     706#          Esta funcion puede reemplazar a TolSet2TclLst.
     707#
     708# RETURN: Un lista Tcl de pares <nombre,valor> que representa el contenido
     709#         con nombredel objeto TOL
     710#
     711#///////////////////////////////////////////////////////////////////////////
     712  #puts "obj = $obj"
     713  set vinfo [ tol::info variable $obj ]
     714  set grammar [ lindex $vinfo 0 ]
     715  if { $grammar eq "Set" || $grammar eq "NameBlock" } {
     716    set result [ list ]
     717    set idx 1
     718    tol::foreach it $obj {
     719      array set it_info $it
     720      #puts "$it_info(grammar) $it_info(name) $it_info(content) "
     721      set G $it_info(grammar)
     722      if { $G eq "Set" || $G eq "NameBlock" } {
     723        set value [ TolObj2TclObj [ eval list $obj $idx ] ]
     724      } else {
     725         set value $it_info(content)
     726      }
     727      lappend result $it_info(name) $value
     728      incr idx
     729    }
     730    set result
     731  } else {
     732    lrange $vinfo 1 2
     733  }
     734}
     735
     736proc loadtt { } {
     737  package require Toltcl
     738  tol::initkernel
     739  tol::initlibrary
     740}
     741
     742proc test1.1 { } {
     743  TolObj2TclObj {Set BdtChartMet}
     744}
     745
     746proc test1.2 { } {
     747  TolObj2TclObjNamed {Set BdtChartMet}
     748}
     749
     750proc test2.1 { } {
     751  tol::console eval {
     752    Set {[[ Set kk = Empty ]]}
     753  }
     754  set result [ TolObj2TclObj {Console 1} ]
     755  tol::console stack release
     756  return $result
     757}
     758
     759proc test2.2 { } {
     760  tol::console eval {
     761    Set {[[ Set kk = Empty ]]}
     762  }
     763  set result [ TolObj2TclObjNamed {Console 1} ]
     764  tol::console stack release
     765  return $result
     766}
     767
     768proc test3.1 { } {
     769  tol::console eval {
     770    Set {[[ 1, 2, Set kk = [[ 3, 4 ]] ]]}
     771  }
     772  set result [ TolObj2TclObj {Console 1} ]
     773  tol::console stack release
     774  return $result
     775}
     776
     777proc test3.2 { } {
     778  tol::console eval {
     779    Set {[[ 1, 2, Set kk = [[ 3, 4 ]] ]]}
     780  }
     781  set result [ TolObj2TclObjNamed {Console 1} ]
     782  tol::console stack release
     783  return $result
     784}
Note: See TracChangeset for help on using the changeset viewer.