Я нашёл парсер JASS кода в нете и теперь могу переписать под JS и получится отличный тег для кодеров. Тема поднималась и ранее, но все её забросили. Скажу только, что тег [jass][/jass] с подсветкой синтаксиса помог бы лучше и быстрее разбирать код. Что скажете, господа?
Code
// Jass Highlighter // Written by Asger Feldthaus (KaTTaNa)
if(!defined('JASS_HIGHLIGHTER_INCLUDED')) // Make sure it is only included once. { var JASS_HIGHLIGHTER_INCLUDED = true;
function FixWord(word) {
Blocks = " constant native function takes returns endfunction if then else elseif endif loop endloop exitwhen ( ) [ ] ";
function HighlightJass(text) { var bb = arguments.length >= 2 ? arguments[1] : false;
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; special = "[]()"; str = "\"'"; trans = {">" : ">", "<" : "<", "&" : "&"}; if (!bb) { text = strtr(text, trans); } else { // Do some backwards working tr = {'(' : '(', ')' : ')', '[' : '[', ']' : ']', '"' : '"'}; text = strtr(text,tr); }
result = ""; comment = 0; Lines = explode("\n", text); anchors = []; n = 0; // First, find all functions and place an anchor there for (var Line in Lines ) { // Leave anchor here? reg = []; anchors[n] = ''; if (ereg('^ *(constant )? *(function|native) *([a-zA-Z_][a-zA-Z_0-9]*) *takes', Line, reg)) { l = max(0, n-12); anchors[l] += '<a name="'+strtolower(reg[3])+'"></a>'; } n++; } n = 0; for (var Line in Lines ) { result += anchors[n]; Line = rtrim(Line); if (isString) { result = result + "</span>"; } stop = strpos(Line, "//"); if (stop == false) { stop = strlen(Line); comment = 0; } else { comment = 1; } i = 0; word = ""; isString = 0; stringStarter = ""; slashed = 0; // Highlight while (i < stop) { c = substr(Line, i, 1); i += 1;
if (isString) { result = result + c; if (c == "\\") { slashed = (slashed)? 0:1; } else if ((c == stringStarter) && !(slashed)) { result = result + "</span>"; isString = 0; } else { slashed = 0; } } else { // If normal character if (strpos(chars, c) != false) { word = word + c;
// If bracket } else if (strpos(special, c) != false) { result = result + FixWord(word) + FixWord(c); word = "";
// If string } else if (strpos(str, c) != false) { result = result + FixWord(word) + "<span style=\"color: blue\">" + c; slashed = 0; word = ""; isString = 1; stringStarter = c;
// If other character } else { result = result + FixWord(word) + c; word = ""; }
} // if ($isString) } result = result + FixWord(word);
// Add comment if (comment) { result = result + "<span style=\"color: green;\">"+strstr(Line, "//")+"</span>"; } // Add linebreak result = result + '<br />'; n++; } result = substr(result, 0, strlen(result)-1); // Remove last linebreak
Velm@ris, В пред. теме я написал что-то вроде "Тег пригодится тем, кто пишет код на языке Jass и очень поможет при выявлении ошибок (парсер не будет подсвечивать ошибочные директивы) и в пр. оптимизации работы".
Velm@ris, ты, далекий от картостроя, конечно же тебе пофиг, а вот я не против читабельности кода с нормальной табуляцией и подсветкой.
Я в контакте и на warcraft3ft.info. Кто может сказать, почему **** дизайнер писал вместо "pt" "px" в CSS, благодаря чему нужно смотреть форум через лупу с Ctrl++?
method CheckItems2 takes nothing returns nothing local integer this_id local integer i = 0 loop set this_id = GetItemTypeId(UnitItemInSlot(.u, i)) if this_id == .item0_id then set .item1 = UnitItemInSlot(.u, i) elseif this_id == .item1_id then set .item2 = UnitItemInSlot(.u, i) endif set i = i + 1 exitwhen i >= bj_MAX_INVENTORY endloop if .item1 != null and .item2 != null then call RemoveItem(.item1) call RemoveItem(.item2) call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) call UnitAddItemById(.u, .item2_id) set .item1 = null set .item2 = null set .u = null endif endmethod
method CheckItems3 takes nothing returns nothing local integer this_id local integer i = 0 loop set this_id = GetItemTypeId(UnitItemInSlot(.u, i)) if this_id == .item0_id then set .item1 = UnitItemInSlot(.u, i) elseif this_id == .item1_id then set .item2 = UnitItemInSlot(.u, i) elseif this_id == .item2_id then set .item3 = UnitItemInSlot(.u, i) endif set i = i + 1 exitwhen i >= bj_MAX_INVENTORY endloop if .item1 != null and .item2 != null and .item3 != null then call RemoveItem(.item1) call RemoveItem(.item2) call RemoveItem(.item3) call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) //adds a special effect call UnitAddItemById(.u, .item3_id) set .item1 = null set .item2 = null set .item3 = null set .u = null endif endmethod
method CheckItems4 takes nothing returns nothing local integer this_id local integer i = 0 loop set this_id = GetItemTypeId(UnitItemInSlot(.u, i)) if this_id == .item0_id then set .item1 = UnitItemInSlot(.u, i) elseif this_id == .item1_id then set .item2 = UnitItemInSlot(.u, i) elseif this_id == .item2_id then set .item3 = UnitItemInSlot(.u, i) elseif this_id == .item3_id then set .item4 = UnitItemInSlot(.u, i) endif set i = i + 1 exitwhen i >= bj_MAX_INVENTORY endloop if .item1 != null and .item2 != null and .item3 != null and .item4 != null then call RemoveItem(.item1) call RemoveItem(.item2) call RemoveItem(.item3) call RemoveItem(.item4) call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) call UnitAddItemById(.u, .item4_id) set .item1 = null set .item2 = null set .item3 = null set .item4 = null set .u = null endif endmethod
method CheckItems5 takes nothing returns nothing local integer this_id local integer i = 0 loop set this_id = GetItemTypeId(UnitItemInSlot(.u, i)) if this_id == .item0_id then set .item1 = UnitItemInSlot(.u, i) elseif this_id == .item1_id then set .item2 = UnitItemInSlot(.u, i) elseif this_id == .item2_id then set .item3 = UnitItemInSlot(.u, i) elseif this_id == .item3_id then set .item4 = UnitItemInSlot(.u, i) elseif this_id == .item4_id then set .item5 = UnitItemInSlot(.u, i) endif set i = i + 1 exitwhen i >= bj_MAX_INVENTORY endloop if .item1 != null and .item2 != null and .item3 != null and .item4 != null and .item5 != null then call RemoveItem(.item1) call RemoveItem(.item2) call RemoveItem(.item3) call RemoveItem(.item4) call RemoveItem(.item5) call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) call UnitAddItemById(.u, .item5_id) set .item1 = null set .item2 = null set .item3 = null set .item4 = null set .item5 = null set .u = null endif endmethod
method CheckItems6 takes nothing returns nothing local integer this_id local integer i = 0 loop set this_id = GetItemTypeId(UnitItemInSlot(.u, i)) if this_id == .item0_id then set .item1 = UnitItemInSlot(.u, i) elseif this_id == .item1_id then set .item2 = UnitItemInSlot(.u, i) elseif this_id == .item2_id then set .item3 = UnitItemInSlot(.u, i) elseif this_id == .item3_id then set .item4 = UnitItemInSlot(.u, i) elseif this_id == .item4_id then set .item5 = UnitItemInSlot(.u, i) elseif this_id == .item5_id then set .item6 = UnitItemInSlot(.u, i) endif set i = i + 1 exitwhen i >= bj_MAX_INVENTORY endloop if .item1 != null and .item2 != null and .item3 != null and .item4 != null and .item5 != null and .item6 != null then call RemoveItem(.item1) call RemoveItem(.item2) call RemoveItem(.item3) call RemoveItem(.item4) call RemoveItem(.item5) call RemoveItem(.item6) call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",.u,"overhead")) call UnitAddItemById(.u, .item6_id) set .item1 = null set .item2 = null set .item3 = null set .item4 = null set .item5 = null set .item6 = null set .u = null endif endmethod endstruct
function Recipe2 takes unit hero, integer i1, integer i2, integer ni returns nothing local RecipeItems IS=RecipeItems.create() set IS.item0_id = i1 set IS.item1_id = i2 set IS.item2_id = ni set IS.u = hero call IS.CheckItems2() call IS.destroy() endfunction
function Recipe3 takes unit hero, integer i1, integer i2, integer i3, integer ni returns nothing local RecipeItems IS=RecipeItems.create() set IS.item0_id = i1 set IS.item1_id = i2 set IS.item2_id = i3 set IS.item3_id = ni set IS.u = hero call IS.CheckItems3() call IS.destroy() endfunction
function Recipe4 takes unit hero, integer i1, integer i2, integer i3, integer i4, integer ni returns nothing local RecipeItems IS=RecipeItems.create() set IS.item0_id = i1 set IS.item1_id = i2 set IS.item2_id = i3 set IS.item3_id = i4 set IS.item4_id = ni set IS.u = hero call IS.CheckItems4() call IS.destroy() endfunction
function Recipe5 takes unit hero, integer i1, integer i2, integer i3, integer i4, integer i5, integer ni returns nothing local RecipeItems IS=RecipeItems.create() set IS.item0_id = i1 set IS.item1_id = i2 set IS.item2_id = i3 set IS.item3_id = i4 set IS.item4_id = i5 set IS.item5_id = ni set IS.u = hero call IS.CheckItems5() call IS.destroy() endfunction
function Recipe6 takes unit hero, integer i1, integer i2, integer i3, integer i4, integer i5, integer i6, integer ni returns nothing local RecipeItems IS=RecipeItems.create() set IS.item0_id = i1 set IS.item1_id = i2 set IS.item2_id = i3 set IS.item3_id = i4 set IS.item4_id = i5 set IS.item5_id = i6 set IS.item6_id = ni set IS.u = hero call IS.CheckItems6() call IS.destroy() endfunction
endlibrary
Я в контакте и на warcraft3ft.info. Кто может сказать, почему **** дизайнер писал вместо "pt" "px" в CSS, благодаря чему нужно смотреть форум через лупу с Ctrl++?
function HighlightJass(text) { var bb = arguments.length >= 2 ? arguments[1] : false;
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; special = "[]()"; str = "\"'"; trans = {">" : ">", "<" : "<", "&" : "&"}; if (!bb) { text = strtr(text, trans); } else { // Do some backwards working tr = {'(' : '(', ')' : ')', '[' : '[', ']' : ']', '"' : '"'}; text = strtr(text,tr); }
result = ""; comment = 0; Lines = explode("\n", text); anchors = []; n = 0; // First, find all functions and place an anchor there for (var Line in Lines ) { // Leave anchor here? reg = []; anchors[n] = ''; if (ereg('^ *(constant )? *(function|native) *([a-zA-Z_][a-zA-Z_0-9]*) *takes', Line, reg)) { l = max(0, n-12); anchors[l] += '<a name="'+strtolower(reg[3])+'"></a>'; } n++; } n = 0; for (var Line in Lines ) { result += anchors[n]; Line = rtrim(Line); if (isString) { result = result + "</span>"; } stop = strpos(Line, "//"); if (stop == false) { stop = strlen(Line); comment = 0; } else { comment = 1; } i = 0; word = ""; isString = 0; stringStarter = ""; slashed = 0; // Highlight while (i < stop) { c = substr(Line, i, 1); i += 1;
if (isString) { result = result + c; if (c == "\\") { slashed = (slashed)? 0:1; } else if ((c == stringStarter) && !(slashed)) { result = result + "</span>"; isString = 0; } else { slashed = 0; } } else { // If normal character if (strpos(chars, c) != false) { word = word + c;
// If bracket } else if (strpos(special, c) != false) { result = result + FixWord(word) + FixWord(c); word = "";
// If string } else if (strpos(str, c) != false) { result = result + FixWord(word) + "<span style=\"color: blue\">" + c; slashed = 0; word = ""; isString = 1; stringStarter = c;
// If other character } else { result = result + FixWord(word) + c; word = ""; }
} // if ($isString) } result = result + FixWord(word);
// Add comment if (comment) { result = result + "<span style=\"color: green;\">"+strstr(Line, "//")+"</span>"; } // Add linebreak result = result + '<br />'; n++; } result = substr(result, 0, strlen(result)-1); // Remove last linebreak
Кстати, DragoN, что такое library_once? От обыкновенной я отличий не нашел.
Quote (manual)
The library_once keyword works exactly like library but you can declare the same library name twice, it would just ignore the second declaration and avoid to add its contents instead of showing a syntax error, it is useful in combination with textmacros.
позволяет использовать 2 библиотеки с одинаковыми именами без ошибок компилятора, хорошо использовать вместе с макросами у дуоса косяк, он забыл дофига значений: те же readonly, stub кури мануал для поиска дополнительных ключевых слов и запили полный список функций, как в tesh
El Psy Congroo
Сообщение отредактировал DragoN - Вторник, 31 Мая 2011, 19:44:30
The library_once keyword works exactly like library but you can declare the same library name twice, it would just ignore the second declaration and avoid to add its contents instead of showing a syntax error, it is useful in combination with textmacros.
The library_once keyword works exactly like library but you can declare the same library name twice, it would just ignore the second declaration and avoid to add its contents instead of showing a syntax error, it is useful in combination with textmacros.
The library_once keyword works exactly like library but you can declare the same library name twice, it would just ignore the second declaration and avoid to add its contents instead of showing a syntax error, it is useful in combination with textmacros.