Created
July 14, 2012 22:30
-
-
Save oscar-broman/3113705 to your computer and use it in GitHub Desktop.
Generate Notepad++ configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Requires PAWN-Scanner | |
// Get it here: https://github.com/oscar-broman/PAWN-Scanner | |
// Include path to scan | |
define('INCLUDE_PATH', './', 'a_npc.inc'); | |
// Where to save the files | |
define('PAWN_XML', './PAWN.xml'); | |
define('USER_DEF_LANG', './userDefineLang.xml'); | |
require 'PAWNScanner.php'; | |
$scanner = new PAWNScanner\Scanner(); | |
$scanner->scan_dir(INCLUDE_PATH); | |
// ----------------------------------------------------------------------------- | |
// PAWN.xml | |
// ----------------------------------------------------------------------------- | |
$xml = new SimpleXMLElement('<NotepadPlus></NotepadPlus>'); | |
$ac = $xml->addChild('AutoComplete'); | |
$ac->addAttribute('language', 'PAWN'); | |
// Add environment info | |
$env = $ac->addChild('Environment'); | |
$env->addAttribute('ignoreCase', 'no'); | |
$env->addAttribute('startFunc', '('); | |
$env->addAttribute('stopFunc', ')'); | |
$env->addAttribute('paramSeparator', ','); | |
$env->addAttribute('terminal', ';'); | |
// Add preprocessor directives | |
$directives = array('assert', 'define', 'else', 'elseif', 'emit', 'endif', | |
'endinput', 'error', 'file', 'if', 'include', 'line', | |
'pragma', 'tryinclude', 'undef'); | |
foreach ($directives as $directive) { | |
$kw = $ac->addChild('KeyWord'); | |
$kw->addAttribute('name', '#' . $directive); | |
} | |
// Add constants created by the compiler | |
$constants = array('cellbits', 'cellmax', 'cellmin', 'charbits', 'charmax', | |
'charmin', 'debug', 'EOS', 'false', 'true', 'ucharmax', | |
'__Pawn', ); | |
foreach ($constants as $constant) { | |
$ac->addChild('KeyWord')->addAttribute('name', $constant); | |
} | |
// Add macros | |
foreach ($scanner->macros as $search => $replacement) { | |
$ac->addChild('KeyWord')->addAttribute('name', $search); | |
} | |
// Add constants | |
foreach ($scanner->constants as $name => $value) { | |
$ac->addChild('KeyWord')->addAttribute('name', $name); | |
} | |
// Add enumerations | |
foreach ($scanner->enums as $enum) { | |
if ($enum->name !== null) | |
$ac->addChild('KeyWord')->addAttribute('name', $enum->name); | |
foreach ($enum->entries as $entry) { | |
$ac->addChild('KeyWord')->addAttribute('name', $entry->varname); | |
} | |
} | |
// Add functions | |
foreach ($scanner->functions as $function) { | |
$func = $ac->addChild('KeyWord'); | |
$func->addAttribute('name', $function->name); | |
$func->addAttribute('func', 'yes'); | |
$params = $func->addChild('Overload'); | |
$params->addAttribute('retVal', $function->tag === null ? '' : $function->tag . ':'); | |
foreach ($function->arguments as $argument) { | |
$params->addChild('Param')->addAttribute('name', $argument); | |
} | |
} | |
// Use the DOMElement to format the output. | |
$dom = dom_import_simplexml($xml)->ownerDocument; | |
$dom->formatOutput = true; | |
// Save it. | |
file_put_contents(PAWN_XML, $dom->saveXML()); | |
// ----------------------------------------------------------------------------- | |
// userDefineLang.xml | |
// ----------------------------------------------------------------------------- | |
$xml = new SimpleXMLElement('<NotepadPlus></NotepadPlus>'); | |
$ul = $xml->addChild('UserLang'); | |
$ul->addAttribute('name', 'PAWN'); | |
$ul->addAttribute('ext', 'pwn inc'); | |
$settings = $ul->addChild('Settings'); | |
$setting = $settings->addChild('Global'); | |
$setting->addAttribute('caseIgnored', 'no'); | |
$setting->addAttribute('escapeChar', '\\'); | |
$setting = $settings->addChild('TreatAsSymbol'); | |
$setting->addAttribute('comment', 'yes'); | |
$setting->addAttribute('commentLine', 'yes'); | |
$setting = $settings->addChild('TreatAsSymbol'); | |
$setting->addAttribute('words1', 'no'); | |
$setting->addAttribute('words2', 'no'); | |
$setting->addAttribute('words3', 'no'); | |
$setting->addAttribute('words4', 'no'); | |
$keywords = $ul->addChild('KeywordLists'); | |
$operators = '*= /= %= += -= <<= >>>= >>= &= ^= |= || && == != <= >= << >>> >> ' | |
. '++ -- ... .. \' - ! " % & ( ) , : ; ? [ ] ^ { | } ~ + < = >'; | |
$keywords->addChild('Keywords', $operators)->addAttribute('name', 'Operators'); | |
$keywords->addChild('Keywords', '"\'0"\'0')->addAttribute('name', 'Delimiters'); | |
$keywords->addChild('Keywords', '{')->addAttribute('name', 'Folder+'); | |
$keywords->addChild('Keywords', '}')->addAttribute('name', 'Folder-'); | |
$keywords->addChild('Keywords', '1/* 2*/ 0//')->addAttribute('name', 'Comment'); | |
// Add function names | |
$keywords->addChild('Keywords', implode(' ', array_keys($scanner->functions))) | |
->addAttribute('name', 'Words1'); | |
// Add macro search strings, constants, and enums | |
$words2 = array_keys($scanner->constants); | |
foreach ($scanner->macros as $search => $replacement) { | |
// Only include simple macros (the ones that are like constants) | |
if (preg_match('/^[a-z@_][a-z0-9@_\.\:]*$/i', $search)) | |
$words2[] = $search; | |
} | |
foreach ($scanner->enums as $enum) { | |
if ($enum->name !== null) | |
$words2[] = $enum->name; | |
foreach ($enum->entries as $entry) { | |
$words2[] = $entry->varname; | |
} | |
} | |
$words2 = implode(' ', $words2); | |
$keywords->addChild('Keywords', $words2)->addAttribute('name', 'Words2'); | |
// Add compiler directives | |
$keywords->addChild('Keywords', '#' . implode(' #', $directives))->addAttribute('name', 'Words3'); | |
// Add tags | |
$tags = array(); | |
// Tags in functions | |
foreach ($scanner->functions as $function) { | |
if ($function->tag !== null) | |
$tags[$function->tag] = true; | |
// Tags in function arguments | |
foreach ($function->arguments as $argument) { | |
if ($argument->tags === null) | |
continue; | |
foreach ($argument->tags->tags as $tag) | |
$tags[$tag] = true; | |
} | |
} | |
// Tags in constants | |
foreach ($scanner->constants as $constant) { | |
if ($constant->tags === null) | |
continue; | |
foreach ($constant->tags->tags as $tag) { | |
$tags[$tag] = true; | |
} | |
} | |
// Tags in enums | |
foreach ($scanner->enums as $enum) { | |
if ($enum->tag !== null) | |
$tags[$enum->tag] = true; | |
foreach ($enum->entries as $entry) { | |
if ($entry->tags === null) | |
continue; | |
foreach ($entry->tags->tags as $tag) | |
$tags[$tag] = true; | |
} | |
} | |
$tags = array_keys($tags); | |
$keywords->addChild('Keywords', implode(' ', $tags))->addAttribute('name', 'Words4'); | |
// Style info | |
$styles = <<<EOD | |
<?xml version="1.0"?> | |
<Styles> | |
<WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="FOLDEROPEN" styleID="12" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="KEYWORD1" styleID="5" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="KEYWORD2" styleID="6" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="KEYWORD3" styleID="7" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="1" /> | |
<WordsStyle name="KEYWORD4" styleID="8" fgColor="0000C0" bgColor="FFFFFF" fontName="" fontStyle="1" /> | |
<WordsStyle name="COMMENT" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="COMMENT LINE" styleID="2" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="NUMBER" styleID="4" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="OPERATOR" styleID="10" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="DELIMINER1" styleID="14" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="DELIMINER2" styleID="15" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
<WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /> | |
</Styles> | |
EOD; | |
$styles = new SimpleXMLElement($styles); | |
$ul->addChild('Styles'); | |
foreach ($styles as $style) { | |
$ws = $ul->Styles->addChild('WordsStyle'); | |
foreach ($style->attributes() as $name => $value) { | |
$ws->addAttribute($name, $value); | |
} | |
} | |
// Use the DOMElement to format the output. | |
$dom = dom_import_simplexml($xml)->ownerDocument; | |
$dom->formatOutput = true; | |
// Save it. | |
file_put_contents(USER_DEF_LANG, $dom->saveXML()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment