Home Page   We Generate Your Software.
Products Services Company Technology Demo Contact Site Map Search
Please note: this document is currently under revision.
The information herein contained, while still valid, does not reflect the latest state of the described technology.
The Somusar/SoProTech[tm] Booklet Series
Volume IV

"somusar/Tefigel: A Tutorial Introduction"

Printer friendly


Contents
1. Introduction
2. Language Summary
3. Text File Components
4. Text File Processing
5. Modularity
6. Multilanguage Applicability
7. Generating Object-oriented Languages
8. Generating Internet-oriented Languages and Protocols
9. Generating Procedural Languages
10. Generating Scripting or Special-purpose Languages
11. Advanced Features and Topics
11.1 Tefigel and Sisendel
11.2 Multilevel Contents Association
11.3 Data Translation Filters
12. A More Extensive Example
13. Further Reading

Chapter 11 - Advanced Features and Topics

After the basic elements of Tefigel have been introduced, it is now possible to shortly describe some more advanced and useful features and applications of Tefigel.

11.1 - Tefigel and Sisendel        top

The main driver to the definition and implementation of Tefigel has been its role as the back-end language within the SoProTech[tm], fully described in "Somusar/Software Production Technique[tm]: An Introduction ". Thus, Tefigel - although fully applicable as a powerful stand-alone tool - should be viewed as a part of a larger picture, as illustrated below.

Figure 1 - Tefigel and Sisendel
Figure 1 - Tefigel and Sisendel
Enlarge

This concept is also illustrated and described in "Somusar/Software Production Technique[tm]: A Sample Project ".

11.2 - Multilevel Contents Association        top

Multilevel contents association is a simple mechanism that can be used to build reference-to-contents relationships stored into associative variables, as the next example shows. "Multilevel" means that nested contents of an aggregated group of data can be directly referenced to at any level of its nesting.

Code Example 37 - Contents association via DASH
Usage of DASH to accomplish contents association. Note that dynamically changing DASH does not impact contents association. Multilevel association is shown on source lines 7, 8, 16, 17, 28 and 30. Built-in VALUE, used on lines 25, 27, 30 and 33, repeatedly expands its parameter - usually an associative variable - until all placeholders therein contained have been substituted with their current value.
Source code - File "associate"
    1      #
    2      # Set type definitions for Java
    3      #
    4      @ dash :
    5      @ set Java:Float=double
    6      @ set Java:Boolean=boolean
    7      @ set Java:String:Short=String
    8      @ set Java:String:Long=String
    9      Type definition for "Float" in Java:: JavaFloat
   10      #
   11      # Set type definitions for SQL
   12      #
   13      @ dash /
   14      @ set SQL/Float=decimal(10,2)
   15      @ set SQL/Boolean=char(1)
   16      @ set SQL/String/Short=varchar(20)
   17      @ set SQL/String/Long=varchar(200)
   18      Type definition for "StringLong" in SQL: SQLStringLong
   19      #
   20      # Access values by means of associative operator dash and built-in value
   21      #
   22      @ dash .
   23      @ set Type=Boolean
   24      @ set Language=Java
   25      Definition of "Type" in Language: ~value(Language.Type)
   26      @ set Language=SQL
   27      Definition of "Type" in Language: ~value(Language.Type)
   28      @ set Type=String.Long
   29      Mapping of Type between Java and SQL:
   30         SQL ~value(SQL.Type) maps to Java ~value(Java.Type)
   31      @ set Type=Float
   32      Mapping of Type between Java and SQL:
   33         SQL ~value(SQL.Type) maps to Java ~value(Java.Type)
	       
Output of "/opt/somusar/bin/tefigel associate"
    1      Type definition for "Float" in Java: double
    2      Type definition for "StringLong" in SQL: varchar(200)
    3      Definition of "Boolean" in Java: boolean
    4      Definition of "Boolean" in SQL: char(1)
    5      Mapping of StringLong between Java and SQL:
    6         SQL varchar(200) maps to Java String
    7      Mapping of Float between Java and SQL:
    8         SQL decimal(10,2) maps to Java double
	       

11.3 - Data Translation Filters        top

Data translation filters are a means to process input textual data that are structured in various regular forms like lists or tables, for instance comma-separated records, or name-value pairs. With Tefigel filters it is rather simple to convert data from tabular form, such as the following file of bar-separated records to - for example - XML.

Input table - File "data_tab"
    1      Name|Position|Age|Salary
    2      
    3      John Smith|Product manager|34|120,000
    4      Mark Twain|Technical writer|67|250,000
    5      # This is a comment and should be ignored by tefigel filters
    6      Bill Young|Java programmer|4|85,000
    7      # This is a comment and should be ignored by tefigel filters
    8      Tom Rich|Millionaire|49|0
	       

It should be noted that the first line in the input file above contains the description of the records, thus making the file self-described. Additional information in the file header would easily allow to associate a complete metadata description of the table contents, specifying for example the type of the data fields.

Code Example 38 - Table filters
Tefigel FILTERs to translate data from raw tabular form into simple XML: the first filter "t_data" processes lines containing separator "|", the second one "t_skip" skips all other lines (empty and comments). Note use of the special character instruction ARGDELIM, that sets the parameter separator to "/" instead of ",".
Source code - File "t_filter"
    1      @ argdelim /
    2      @ filter t_data |
    3      @ filter t_skip ^.*$
	       
Output of "/opt/somusar/bin/tefigel t_filter data_tab"
    1          <!-- next record >
    2              <Name> John Smith </Name>
    3              <Position> Product manager </Position>
    4              <Age> 34 </Age>
    5              <Salary> 120,000 </Salary>
    6          <!-- next record >
    7              <Name> Mark Twain </Name>
    8              <Position> Technical writer </Position>
    9              <Age> 67 </Age>
   10              <Salary> 250,000 </Salary>
   11          <!-- next record >
   12              <Name> Bill Young </Name>
   13              <Position> Java programmer </Position>
   14              <Age> 4 </Age>
   15              <Salary> 85,000 </Salary>
   16          <!-- next record >
   17              <Name> Tom Rich </Name>
   18              <Position> Millionaire </Position>
   19              <Age> 49 </Age>
   20              <Salary> 0 </Salary>
	       

Code Example 39 - Table filter 1
This filter splits matching input record into separate fields, and writes them out as XML fragments. Note use of GLOBSET to store field descriptor tags recognized on first input row into global name space variables called COL_0, COL_1, etc. Also note use of built-in FIELD to extract n-th field from the bar-separated record: note that separator "|" is also a parameter to built-in FIELD.
Source code - File "t_data"
    1      @ interface(LINE)
    2      @ eval ignore LINE~^#
    3      @ if ignore=0
    4      @    set VAL_0=~field(LINE/0/|)
    5      @    set VAL_1=~field(LINE/1/|)
    6      @    set VAL_2=~field(LINE/2/|)
    7      @    set VAL_3=~field(LINE/3/|)
    8      @    if COL_0=
    9      @       globset COL_0=VAL_0
   10      @       globset COL_1=VAL_1
   11      @       globset COL_2=VAL_2
   12      @       globset COL_3=VAL_3
   13      @    else
   14          <!-- next record >
   15              <COL_0> VAL_0 </COL_0>
   16              <COL_1> VAL_1 </COL_1>
   17              <COL_2> VAL_2 </COL_2>
   18              <COL_3> VAL_3 </COL_3>
   19      @    endif
   20      @ endif
	       

Code Example 40 - Table filter 2
Completely empty script, ignores input and produces no output.
Source code - File "t_skip"
	       

[Previous chapter]    [Next chapter]    [Back to top]

http:// www.somusar.com  / doc  / booklets  / tefigel_tut  - Powered by SoProMach
Copyright © 2003-2012 Somusar - Trademarks - Legal - Privacy - Webmaster