home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / AWK.PEL < prev    next >
Text File  |  1995-01-04  |  8KB  |  188 lines

  1. # $Header:   P:\source\wmacros\awk.pev   1.3   04 Jan 1995 16:57:20   PFHJXM0  $
  2. ## $Tabs:4 7$
  3.  
  4. ##############################################################################
  5. #
  6. #       Compuware Corporation
  7. #         31440 Northwestern Highway
  8. #           Farmington Hills, Michigan 48334-2564
  9. #
  10. #   This source code listing contains information that is
  11. #   proprietary to Compuware Corporation and may not be copied
  12. #   duplicated, translated, transmitted, stored, retrieved
  13. #   or in any manner or by any method conveyed or disclosed
  14. #   to a third party or parties without express written
  15. #   permission from Compuware Corporation.
  16. #
  17. #  
  18. ##############################################################################
  19.  
  20. #### $Workfile:   awk.pel  $: Awk specific functions
  21.  
  22. function setup_awk_template()
  23. {
  24.    local OB, EB, EB2 # open and closed braces
  25.    local OC, MC, EC  # open, middle, end comment markers
  26.    local BLOCK, NBLOCK
  27.  
  28.    OB  = electric_symbol.open_brace
  29.    EB  = electric_symbol.end_brace 
  30.    EB2 = electric_symbol.end_brace2
  31.  
  32.    OC = electric_symbol.open_comment
  33.    MC = electric_symbol.middle_comment
  34.    EC = electric_symbol.end_comment
  35.  
  36.    NBLOCK = electric_symbol.new_block 
  37.    BLOCK  = electric_symbol.block     
  38.    
  39.    delete( language_template );    # delete last template and start over
  40.  
  41.    ELEC_LANG = "awk"
  42.  
  43.    language_template[ "(" ] = "( `expression-1` )"
  44.    language_template[ "/*" ] = "/*\n** `comment-1`\n*/"
  45.    language_template[ "[" ] = "[ `index-1` ]"
  46.    language_template[ "{" ] = BLOCK
  47.    language_template[ "_m" ] = "_makepath(@,,,,);"
  48.    language_template[ "_s" ] = "_splitpath(@,,,,);"
  49.    language_template[ "ac" ] = "access(\"@\",);"
  50.    language_template[ "br" ] = "break;\n@"
  51.    language_template[ "ca" ] = "case `constant-expr-1`:\n\t`statement-1`\nbreak;\n"
  52.    language_template[ "cl" ] = "close(`filename-1`);"
  53.    language_template[ "co" ] = "continue;\n@"
  54.    language_template[ "do" ] = "do \n" BLOCK " while ( `expr-1` );\n"
  55.    language_template[ "fe" ] = "free( `storage-1` );"
  56.    language_template[ "fo" ] = "for (`expr-1`;`expr-2`;`expr-3` ) \n" BLOCK OC " end for " EC "\n"
  57.    language_template[ "fp" ] = "fprintf(`filename-1`,\"`format-string-1`\",`var-list-1`);"
  58.    language_template[ "fr" ] = "fread(`buffer-1`,`size-1`,`count-1`,`stream-1`);"
  59.    language_template[ "fs" ] = "fscanf(`filename-1`,\"`format-string-1`\");"
  60.    language_template[ "ft" ] = "ftell(`stream-1`);"
  61.    language_template[ "fw" ] = "fwrite(`buffer-1`,`size-1`,`count-1`,`stream-1`);"
  62.    language_template[ "gc" ] = "getc(`stream-1`);"
  63.    language_template[ "gh" ] = "getchar();"
  64.    language_template[ "go" ] = "goto `identifier-1`;    " OC " `PLEASE EXPLAIN` " EC
  65.    language_template[ "gs" ] = "gets(`buffer-1`);"
  66.    language_template[ "gw" ] = "getw(`buffer-1`);"
  67.    language_template[ "fu" ] = "function `funct-name-1`( `param-list-1` )\n" NBLOCK
  68.    language_template[ "if" ] = "if ( `expr-1` ) \n" BLOCK OC " end if " EC "\n"
  69.    language_template[ "el" ] = "else \n" BLOCK OC " end else" EC " \n"
  70.    language_template[ "ei" ] = "else " language_template["if"]
  71.    language_template[ "ie" ] = language_template["if"] "\n" language_template["el"]
  72.    language_template[ "ls" ] = "lseek(@,,SEEK_);"
  73.    language_template[ "ma" ] = "malloc(`size-1`);"
  74.    language_template[ "op" ] = "open(\"@\",,);"
  75.    language_template[ "pc" ] = "putc(`int-1`,`stdout-1`);"
  76.    language_template[ "ph" ] = "putchar(`int-1`);"
  77.    language_template[ "pr" ] = "printf(\"`format-string-1`\", `var-list-1`);"
  78.    language_template[ "ps" ] = "puts(\"`string-1`\");"
  79.    language_template[ "pw" ] = "putw(@,);"
  80.    language_template[ "re" ] = "read(@,,);"
  81.    language_template[ "rn" ] = "rename(\"`old-name-1`\", \"`new-name-1`\");"
  82.    language_template[ "rt" ] = "return `expr-1`;"
  83.    language_template[ "sc" ] = "scanf(`filename-1`, \"`format-string-1`\", `var-list-1`);"
  84.    language_template[ "sp" ] = "sprintf(`var-name-1`, \"`format-string-1`\", `var-list-1`);"
  85.    language_template[ "ss" ] = "sscanf(`buffer-1`, \"`format-string-1`\", `var-list-1`);"
  86.    language_template[ "st" ] = "static `var-name-1`;"
  87.    language_template[ "sw" ] = "switch (`expr-1`) \n" OB "\n\tdefault:\n\t`statement-2`\n" EB2 OC " end switch " EC "\n"
  88.    language_template[ "ts" ] = "typedef struct \n" BLOCK " `struct-name-1`;\n"
  89.    language_template[ "tu" ] = "typedef union \n" BLOCK " `union-name-1`;\n"
  90.    language_template[ "ty" ] = "typedef `name-1`"
  91.    language_template[ "un" ] = "unlink(\"`filename-1`\");"
  92.    language_template[ "vf" ] = "vfprintf(`file-1`,\"`format-string-1`\",`var-list-1`);"
  93.    language_template[ "vp" ] = "vprintf(\"`format-string-1`\",`var-list-1`);"
  94.    language_template[ "vs" ] = "vsprintf(`buffer-1`,\"`format-string-1`\",`var-list-1`);"
  95.    language_template[ "wh" ] = "while (`condition-1`) \n" BLOCK OC " end while " EC "\n"
  96.    language_template[ "wr" ] = "write(@,,);"
  97. }
  98.  
  99. #
  100. # Language-specific macros.  The following ("__") macros are called in turn 
  101. # whenever a file with the corresponding (".") extension is edited and
  102. # electric is enabled.  
  103. #
  104.  
  105. #function __pel()
  106. #{
  107. #}
  108.  
  109. function __awk()
  110. {
  111.    electric_symbol.open_comment   = "#"
  112.    electric_symbol.middle_comment = "#"
  113.    electric_symbol.end_comment    = "#"
  114. }
  115.  
  116. global function add_awk_type()
  117. {
  118.    add_type("awk", "Thompson Tools Awk Compiler", "awk", "4 7", "1 77", 
  119.             "{ } [ ] ( )", "\\",
  120.             default_buffer_flags, 0, 1, "()[];:,='", 1);
  121. }
  122.  
  123. global function load_factory_awk_syntax()
  124. {
  125.    local type = "awk";
  126.  
  127.    set_factory_categories( type );
  128.  
  129.    add_syntax_item(type, BLOCK, "/* */", CATEGORY_COMMENT);
  130.  
  131.    add_syntax_item(type, LINE, "\" \"", 0x10000 + CATEGORY_LITERAL);
  132.  
  133.    add_syntax_item(type, KEYWORD, "break", CATEGORY_RESERVED);
  134.    add_syntax_item(type, KEYWORD, "case", CATEGORY_RESERVED);
  135.    add_syntax_item(type, KEYWORD, "continue", CATEGORY_RESERVED);
  136.    add_syntax_item(type, KEYWORD, "do", CATEGORY_RESERVED);
  137.    add_syntax_item(type, KEYWORD, "else", CATEGORY_RESERVED);
  138.    add_syntax_item(type, KEYWORD, "for", CATEGORY_RESERVED);
  139.    add_syntax_item(type, KEYWORD, "function", CATEGORY_RESERVED);
  140.    add_syntax_item(type, KEYWORD, "goto", CATEGORY_RESERVED);
  141.    add_syntax_item(type, KEYWORD, "if", CATEGORY_RESERVED);
  142.    add_syntax_item(type, KEYWORD, "return", CATEGORY_RESERVED);
  143.    add_syntax_item(type, KEYWORD, "switch", CATEGORY_RESERVED);
  144.    add_syntax_item(type, KEYWORD, "typedef", CATEGORY_RESERVED);
  145.    add_syntax_item(type, KEYWORD, "while", CATEGORY_RESERVED);
  146.    add_syntax_item(type, KEYWORD, "{", CATEGORY_RESERVED);
  147.    add_syntax_item(type, KEYWORD, "}", CATEGORY_RESERVED);
  148.  
  149.    add_syntax_item(type, KEYWORD, "static", CATEGORY_TYPE);
  150.  
  151.    set_escape_character(type, "\\")
  152.    set_style_delimiters(type, ".();,=:")
  153.  
  154.    set_case_sensitive(type, 0)
  155. }
  156.  
  157. global function add_pel_type()
  158. {
  159.    add_type("pel", "PEL Compiler", "awk", "4 7", "1 77", "{ } [ ] ( )", "\\",
  160.             default_buffer_flags, 0, 1, "()[];:,='", 1);
  161. }
  162.  
  163. global function load_factory_pel_syntax()
  164. {
  165.    local type = "pel";
  166.  
  167.    set_factory_categories( type );
  168.  
  169.    add_syntax_item(type, LINE, "\" \"", 0x010000 + CATEGORY_LITERAL);
  170.    add_syntax_item(type, LINE, "#", CATEGORY_COMMENT);
  171.    add_syntax_item(type, KEYWORD, "break", CATEGORY_RESERVED)
  172.    add_syntax_item(type, KEYWORD, "delete", CATEGORY_RESERVED)
  173.    add_syntax_item(type, KEYWORD, "do", CATEGORY_RESERVED);
  174.    add_syntax_item(type, KEYWORD, "else", CATEGORY_RESERVED);
  175.    add_syntax_item(type, KEYWORD, "for", CATEGORY_RESERVED);
  176.    add_syntax_item(type, KEYWORD, "function", CATEGORY_RESERVED);
  177.    add_syntax_item(type, KEYWORD, "global", CATEGORY_TYPE);
  178.    add_syntax_item(type, KEYWORD, "if", CATEGORY_RESERVED);
  179.    add_syntax_item(type, KEYWORD, "local", CATEGORY_TYPE);
  180.    add_syntax_item(type, KEYWORD, "return", CATEGORY_RESERVED);
  181.    add_syntax_item(type, KEYWORD, "while", CATEGORY_RESERVED);
  182.    add_syntax_item(type, KEYWORD, "{", CATEGORY_RESERVED);
  183.    add_syntax_item(type, KEYWORD, "}", CATEGORY_RESERVED);
  184.  
  185.    set_style_delimiters(type, "()[];:,=");
  186.    set_escape_character(type, "\\");
  187. }
  188.