Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Syntax highlighting EBNF grammar language

by BUU (Prior)
on Dec 05, 2004 at 11:36 UTC ( [id://412478]=note: print w/replies, xml ) Need Help??


in reply to Re: Syntax highlighting EBNF grammar language
in thread Syntax highlighting EBNF grammar language

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

Replies are listed 'Best First'.
Re^3: Syntax highlighting EBNF grammar language
by ikegami (Patriarch) on Dec 10, 2004 at 01:12 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://412478]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found