in reply to Syntax highlighting EBNF grammar language

Do you have a pointer to a piece of moderately complex sample JASS code?


Examine what is said, not who speaks.
"But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
"Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo         "Efficiency is intelligent laziness." -David Dunham
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
  • Comment on Re: Syntax highlighting EBNF grammar language

Replies are listed 'Best First'.
Re^2: Syntax highlighting EBNF grammar language
by BUU (Prior) on Dec 05, 2004 at 11:36 UTC
    Sure, heres a couple of samples:

    Sample 1

    function AsciiCharToInteger takes string char returns integer local string charMap = " !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFG +HIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" local string u = SubString(char, 0, 1) local string c local integer i = 0 loop set c = SubString(charMap, i, i + 1) exitwhen c == "" if c == u then return i + 32 endif set i = i + 1 endloop return 0 endfunction function IdStringToIdInteger takes string value returns integer return AsciiCharToInteger(SubString(value, 0, 1)) * 0x1000000 + Asci +iCharToInteger(SubString(value, 1, 2)) * 0x10000 + AsciiCharToInteger +(SubString(value, 2, 3)) * 0x100 + AsciiCharToInteger(SubString(value +, 3, 4)) endfunction function makeAdvancedUnit takes player who, string id, location where, + real angle, string life, string mana, string abil returns unit local integer unitid = S2I(id) local integer spellmnt = StringLength(abil)/4 local unit u = null local integer i = 0 if unitid == 0 then set unitid = IdStringToIdInteger(id) endif set u = CreateUnit(who, unitid, GetLocationX(where), GetLocationY(wher +e), angle) loop exitwhen i>=spellmnt call UnitAddAbility(u, IdStringToIdInteger(SubString(abil,i*4,(i+1)* +4)) ) set i = i + 1 endloop if StringCase(SubString(life,StringLength(life)-1,StringLength(life) ) +,false) == "p" then call SetUnitLifePercentBJ(u,S2R(SubString(life,0,String Length(life +)) )) else call SetUnitLifeBJ(u, S2R(life) ) endif if StringCase(SubString(mana,StringLength(mana)-1,StringLength(mana) ) +,false) == "p" then call SetUnitManaPercentBJ(u,S2R(SubString(mana,0,String Length(mana +)) )) else call SetUnitManaBJ(u, S2R(mana) ) endif return u endfunction

    Sample 2

    function Trig_respawn_Condition takes nothing returns boolean return true endfunction function Trig_respawn_Actions takes nothing returns nothing local location respawn_point local integer respawn_unit local unit u local integer i = 0 call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_013" ) loop exitwhen i > udg_max_units if ( GetTriggerUnit() == udg_all_monsters[i] ) then set respawn_unit = GetUnitTypeId(GetTriggerUnit()) set respawn_point = Location( udg_unit_pos_x[i], udg_unit_ +pos_y[i] ) call DisplayTextToForce( GetPlayersAll(), "Unit: " ) call DisplayTextToForce( GetPlayersAll(), I2S( i ) ) call TriggerSleepAction( 5.00 ) set u = CreateUnitAtLoc( GetOwningPlayer( GetTriggerUnit() + ), respawn_unit, respawn_point, bj_UNIT_FACING ) set udg_all_monsters[i] = u else endif set i = i + 1 endloop endfunction //==================================================================== +======= function InitTrig_respawn takes nothing returns nothing set gg_trg_respawn = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_respawn, EVENT_PLAYER_U +NIT_DEATH ) call TriggerAddCondition( gg_trg_respawn, Condition( function Trig +_respawn_Condition ) ) call TriggerAddAction( gg_trg_respawn, function Trig_respawn_Actio +ns ) endfunction

      The first sample you provided isn't valid. In two places, "StringLength" was written as "String  Length".

        Well, I'll blame someone else as it's not actually my code, but it apparently works, so I have no real idea. I'll look in to it.