Pages

Thursday, September 16, 2010

Go language syntax highlighting for Notepad++

Save the code below as go.lang.xml

<NotepadPlus>
    <UserLang name="go" ext="go">
        <Settings>
            <Global caseIgnored="no" escapeChar="\" />
            <TreatAsSymbol comment="yes" commentLine="yes" />
            <Prefix words1="no" words2="no" words3="no" words4="no" />
        </Settings>
        <KeywordLists>
            <Keywords name="Delimiters">&quot;&apos;0&quot;&apos;0</Keywords>
            <Keywords name="Folder+">{</Keywords>
            <Keywords name="Folder-">}</Keywords>
            <Keywords name="Operators">- ! % &amp; ( ) * . : ? ^ | ~ + &lt; = &gt;</Keywords>
            <Keywords name="Comment">1/* 2*/ 0//</Keywords>
            <Keywords name="Words1">const func struct type var chan defer break case const continue default else fallthrough for go goto if return switch export extends final goto implements import interface package range select static volatile</Keywords>
            <Keywords name="Words2">nil true false boolean byte char enum float int int32 int64 uint uint32 uint64 string</Keywords>
            <Keywords name="Words3"></Keywords>
            <Keywords name="Words4"></Keywords>
        </KeywordLists>
        <Styles>
            <WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="FOLDEROPEN" styleID="12" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD1" styleID="5" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD2" styleID="6" fgColor="0080FF" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="KEYWORD3" styleID="7" fgColor="004000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD4" styleID="8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT" styleID="1" fgColor="C0C0C0" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT LINE" styleID="2" fgColor="C0C0C0" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="NUMBER" styleID="4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="OPERATOR" styleID="10" fgColor="808000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="DELIMINER1" styleID="14" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="DELIMINER2" styleID="15" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
        </Styles>
    </UserLang>
</NotepadPlus>

Open Notepad++ View -> User Define Dialog and now import go.lang.xml. Now go to Settings -> Preferences -> File Association, click on customize and add go. Close Notepad++ and open it again to see the effect.


Refer: http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Languages
http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Language_Files

Wednesday, September 15, 2010

Invalid identifier character 0xfeff

I got this error while trying to compile a UTF-8 ecoded file with windows build go compiler. Error messages are as follows

UTF 8 =>
$ 8g hello.go 
hello.go:1: invalid identifier character 0xfeff 
hello.go:1: package statement must be first 
hello.go:1: non-declaration statement outside function body 
hello.go:1: syntax error: unexpected name, expecting semicolon or 
newline

Unicode (in notepad)=>
$ 8g hello.go 
hello.go:1: illegal NUL byte 
hello.go:1: illegal UTF-8 sequence 
        ff fe 70 00 
hello.go:1: invalid identifier character 0xfffd 
hello.go:1: illegal NUL byte 
hello.go:1: package statement must be first 
hello.go:1: illegal NUL byte 
hello.go:1: non-declaration statement outside function body 
hello.go:1: syntax error: unexpected name, expecting semicolon or 
newline 
hello.go:1: illegal NUL byte 
hello.go:1: too many errors 

Rob Pike suggest that my editor (Notepad ++) is misbehaving . I have tried Windows Notepad, X-ConTEXT, and notepad2 without any luck. Finally I got it working with EditPlus 3. The supported encoding is "UTF-8 without BOM" which is default for EditPlus 3 UTF, for Notepad ++ you have to select "UTF-8 without BOM" instead of only "UFT-8" and for Programmer's Notepad you have to select "UTF-8 No Mark". No such option in Windows Notepad, X-ConTEXT, or notepad2.

Tuesday, September 14, 2010

Batch file to compile go program with express go compiler

Download  Express go compiler from http://www.unicorn-enterprises.com and copy ng folder to c:\. Save the code below to ng.bat file

@echo off
c:\ng\bin\vmgc.exe -I c:\ng\pkg -o out.vmo %1
IF EXIST out.vmo c:\ng\bin\vmld.exe -L c:\ng\pkg -o out.vmx out.vmo
IF EXIST out.vmx c:\ng\bin\vmrun.exe out.vmx %2 %3 %4
IF EXIST out.vmx del out.vmx
IF EXIST out.vmo del out.vmo

move  ng.bat to c:\windows

now from command prompt you can run your go file by calling

c:\>ng hello.go
 
Powered by NishantSoft