Syntax Highlighting

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Syntax Highlighting

Post by JJeronimo »

I think a wiki with so much code samples should support syntax highlighting. It would make code a lot easier to read.

JJ
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Re: Syntax Highlighting

Post by JackScott »

I agree with you completely, I see no reason not to have it. A quick Google search turns up this, which might be worth a go.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Syntax Highlighting

Post by 01000101 »

I personally find the [ code ] blocks very hard to read as they are all uniform in color and a very dull color at that. very tough on the eyes.
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Re: Syntax Highlighting

Post by JackScott »

01000101: Do you mean the Code blocks on the forum, or the Wiki?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Syntax Highlighting

Post by Troy Martin »

I think he means the wiki, the forum ones are fine to me.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Syntax Highlighting

Post by pcmattman »

I'm pretty sure he meant the Forum ones - why else would he specifically write [code] into his post? The wiki doesn't have BBCode syntax, unless there's a custom extension I don't know about.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Syntax Highlighting

Post by xenos »

Syntax highlighting would be great - both in the wiki and the forum. Sometimes it's a pure mess to dig through those huge single color code blocks here in the forum...

There might be other opinions, since anything dealing with colors depends on skin settings, which differ among users. So, a syntax highlighting suitable for one user might be painful for another. So if we want syntax highlighting for the forum, it should be different for every skin (and maybe there should be an option to switch it off...). And, besides that, we need a different one for different languages - ASM or Pascal need a different highlighting than C++. Maybe this could do the job for the forum.

In the wiki there is no such trouble with skins, so I think syntax highlighting would definitely be a good idea.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Syntax Highlighting

Post by 01000101 »

I meant the forums, but on second thought, it 100% applies to the wiki as well. I'm using a dark theme in the forums and the code blocks here are a shade of grey, so its very unsightly.

I think some C/ASM syntax highlighting for both would go a long way, then if it works out, get more of the other languages to utilize syntax-highlighting.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: Syntax Highlighting

Post by Alboin »

XenOS wrote:There might be other opinions, since anything dealing with colors depends on skin settings, which differ among users. So, a syntax highlighting suitable for one user might be painful for another.
If we all just used the damn ponies theme, this wouldn't be a problem!

I second the desire to experiment with highlighting. Test Forum?
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
chase
Site Admin
Posts: 710
Joined: Wed Oct 20, 2004 10:46 pm
Libera.chat IRC: chase_osdev
Location: Texas
Discord: chase/matt.heimer
Contact:

Re: Syntax Highlighting

Post by chase »

Added to the wiki. See the CPUID article for an example.
Using this mediawiki extension: http://www.mediawiki.org/wiki/Extension ... ight_GeSHi
The extension actually uses GeSHi 1.0.8.3 from here: http://qbnz.com/highlighter/
I noticed that at least the cpuid instruction was missing from the syntax file for asm so I added that. I'm sure there are other instructions that are missing, if anyone wants to download Geshi 1.0.8.3 and create an updated asm.php file I'll install it.

The extension can be used like:

Code: Select all

<source lang="asm">
mov eax, 0x0
cpuid
</source>
Or to add line numbers

Code: Select all

<source lang="asm" line>
mov eax, 0x0
cpuid
</source>
Or to add line numbers that start at a specified number

Code: Select all

<source lang="asm" line start="20">
mov eax, 0x0
cpuid
</source>

Valid languages are

Code: Select all

abap
actionscript3
actionscript
ada
apache
applescript
apt_sources
asm
asp
autoit
bash
basic4gl
blitzbasic
bnf
boo
caddcl
cadlisp
cfdg
cfm
cil
c_mac
cobol
c
cpp
cpp-qt
csharp
css
delphi
diff
div
dos
dot
d
eiffel
fortran
freebasic
genero
gettext
glsl
gml
gnuplot
groovy
haskell
html4strict
idl
ini
inno
io
java5
java
javascript
kixtart
klonec
klonecpp
latex
lisp
lotusformulas
lotusscript
lua
m68k
matlab
mirc
mpasm
mxml
mysql
nsis
objc
ocaml-brief
ocaml
oobas
oracle8
pascal
perl
per
php-brief
php
plsql
powershell
python
qbasic
rails
reg
robots
ruby
sas
scala
scheme
sdlbasic
smalltalk
smarty
sql
tcl
text
thinbasic
tsql
vbnet
vb
verilog
vhdl
visualfoxpro
winbatch
xml
xorg_conf
xpp
z80
OrOS
Member
Member
Posts: 143
Joined: Sat Sep 08, 2007 11:26 pm
Location: Canada

Re: Syntax Highlighting

Post by OrOS »

I have finished from A to E. Its mostly fine, however I (or someone else needs to fix the spacing in a few of the examples.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Syntax Highlighting

Post by Combuster »

I noticed that at least the cpuid instruction was missing from the syntax file for asm so I added that. I'm sure there are other instructions that are missing
It seems that all of the MMX and SSE instructions are absent, the long mode registers.

Going by the directives array, the thing ends with 486 support. (cmpxchg8b is missing as well). I guess it needs a bit more than a little work :(
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
chase
Site Admin
Posts: 710
Joined: Wed Oct 20, 2004 10:46 pm
Libera.chat IRC: chase_osdev
Location: Texas
Discord: chase/matt.heimer
Contact:

Re: Syntax Highlighting

Post by chase »

How many people do you think are trying to syntax highlight asm code in a wiki? :)

The asm.php file that I mention in my previous message is a pretty straight forward array of keywords. See: http://geshi.svn.sourceforge.net/viewvc ... iew=markup Mostly just needs the additional keywords mentioned in http://scintilla.cvs.sourceforge.net/vi ... iew=markup which served as the original source for asm.php but has been updated to be mostly current.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Syntax Highlighting

Post by Combuster »

oh well, for the relevant part of asm.php: (not tested)

Code: Select all

'KEYWORDS' => array(
        /*CPU*/
        1 => array(
            'aaa','aad','aam','aas','adc','add','and','call','cbw', 'cflush', 'clc','cld','cli','cmc','cmp',
            'cmps','cmpsb','cmpsw','cmpxchg8b','cpuid','cwd','daa','das','dec','div','esc','hlt','idiv','imul','in','inc',
            'int','int1','int3','into','iret','ja','jae','jb','jbe','jc','jcxz','je','jg','jge','jl','jle','jmp',
            'jna','jnae','jnb','jnbe','jnc','jne','jng','jnge','jnl','jnle','jno','jnp','jns','jnz',
            'jo','jp','jpe','jpo','js','jz','lahf','lds','lea','les','lods','lodsb','lodsw','loop',
            'loope','loopew','loopne','loopnew','loopnz','loopnzw','loopw','loopz','loopzw','mov',
            'movs','movsb','movsw','mul','neg','nop','not','or','out','pop','popf','push','pushf',
            'rcl','rcr','ret','retf','retn','rol','ror','sahf','sal','sar','sbb','scas','scasb','scasw',
            'shl','shr','stc','std','sti','stos','stosb','stosw','sub','test','wait','xchg','xlat',
            'xlatb','xor','bound','enter','ins','insb','insw','leave','outs','outsb','outsw','popa','pusha','pushw',
            'arpl','lar','lsl','sgdt','sidt','sldt','smsw','str','verr','verw','clts','lgdt','lidt','lldt','lmsw','ltr',
            'bsf','bsr','bt','btc','btr','bts','cdq','cmpsd','cwde','insd','iretd','iretdf','iretf','iretw',
            'jecxz','lfs','lgs','lodsd','loopd','looped','loopned','loopnzd','loopzd','lss','movsd',
            'movsx','movzx','outsd','popad','popfd','pushad','pushd','pushfd','scasd','seta','setae',
            'setb','setbe','setc','sete','setg','setge','setl','setle','setna','setnae','setnb','setnbe',
            'setnc','setne','setng','setnge','setnl','setnle','setno','setnp','setns','setnz','seto','setp',
            'setpe','setpo','sets','setz','shld','shrd','stosd','bswap','cmpxchg','invd','invlpg','wbinvd','xadd','lock',
            'rep','repe','repne','repnz','repz','rdmsr','wrmsr','rdpmc','rdshr','rdtsc','rsdc','rsldt','rsm',
            'rsts','salc','smi','smintold','smint','svdc','svldt','svts','pause','syscall','sysenter','sysexit','sysret',
            'ud2','umov','xbts','wrshr'
            ),
        /*FPU*/
        2 => array(
            'f2xm1','fabs','fadd','faddp','fbld','fbstp','fchs','fclex','fcom','fcomp','fcompp','fdecstp',
            'fdisi','fdiv','fdivp','fdivr','fdivrp','feni','ffree','fiadd','ficom','ficomp','fidiv',
            'fidivr','fild','fimul','fincstp','finit','fist','fistp','fisub','fisubr','fld','fld1',
            'fldcw','fldenv','fldenvw','fldl2e','fldl2t','fldlg2','fldln2','fldpi','fldz','fmul',
            'fmulp','fnclex','fndisi','fneni','fninit','fnop','fnsave','fnsavew','fnstcw','fnstenv',
            'fnstenvw','fnstsw','fpatan','fprem','fptan','frndint','frstor','frstorw','fsave',
            'fsavew','fscale','fsqrt','fst','fstcw','fstenv','fstenvw','fstp','fstsw','fsub','fsubp',
            'fsubr','fsubrp','ftst','fwait','fxam','fxch','fxtract','fyl2x','fyl2xp1',
            'fsetpm','fcos','fldenvd','fnsaved','fnstenvd','fprem1','frstord','fsaved','fsin','fsincos',
            'fstenvd','fucom','fucomp','fucompp',
            'emms','femms','fxsave','fxrstor'
            ),
        /*registers*/
        3 => array(
            'ah','al','ax','bh','bl','bp','bx','ch','cl','cr0','cr2','cr3','cs','cx','dh','di','dl',
            'dr0','dr1','dr2','dr3','dr6','dr7','ds','dx','eax','ebp','ebx','ecx','edi','edx',
            'es','esi','esp','fs','gs','si','sp','ss','st','tr3','tr4','tr5','tr6','tr7',
            'rax','rbx','rcx','rdx','rsi','rdi','rbp','rsp','cr8','spl','bpl','sil','dil',
            'r8b','r9b','r10b','r11b','r12b','r13b','r14b','r15b',
            'r8w','r9w','r10w','r11w','r12w','r13w','r14w','r15w',
            'r8d','r9d','r10d','r11d','r12d','r13d','r14d','r15d',
            'r8','r9','r10','r11','r12','r13','r14','r15'
            ),
        /*Directive*/
        4 => array(
            '186','286','286c','286p','287','386','386c','386p','387','486','486p','586','686'
            '8086','8087','alpha','break','code','const','continue','cref','data','data?',
            'dosseg','else','elseif','endif','endw','err','err1','err2','errb',
            'errdef','errdif','errdifi','erre','erridn','erridni','errnb','errndef',
            'errnz','exit','fardata','fardata?','if','lall','lfcond','list','listall',
            'listif','listmacro','listmacroall',' model','no87','nocref','nolist',
            'nolistif','nolistmacro','radix','repeat','sall','seq','sfcond','stack',
            'startup','tfcond','type','until','untilcxz','while','xall','xcref',
            'xlist','alias','align','assume','catstr','comm','comment','db','dd','df','dq',
            'dt','dup','dw','echo','elseif1','elseif2','elseifb','elseifdef','elseifdif',
            'elseifdifi','elseife','elseifidn','elseifidni','elseifnb','elseifndef','end',
            'endm','endp','ends','eq',' equ','even','exitm','extern','externdef','extrn','for',
            'forc','ge','goto','group','high','highword','if1','if2','ifb','ifdef','ifdif',
            'ifdifi','ife',' ifidn','ifidni','ifnb','ifndef','include','includelib','instr','invoke',
            'irp','irpc','label','le','length','lengthof','local','low','lowword','lroffset',
            'macro','mask','mod','msfloat','name','ne','offset','opattr','option','org','%out',
            'page','popcontext','private','proc','proto','ptr','public','purge','pushcontext','record',
            'rept','seg','segment','short','size','sizeof','sizestr','struc','struct',
            'substr','subtitle','subttl','textequ','this','title','typedef','union','width',
            '.model', '.stack', '.code', '.data'
            ),
        /*Operands*/
        5 => array(
            '@b','@f','addr','basic','byte','c','carry?','dword',
            'far','far16','fortran','fword','near','near16','overflow?','parity?','pascal','qword',
            'real4',' real8','real10','sbyte','sdword','sign?','stdcall','sword','syscall','tbyte',
            'vararg','word','zero?','flat','near32','far32',
            'abs','all','assumes','at','casemap','common','compact',
            'cpu','dotname','emulator','epilogue','error','export','expr16','expr32','farstack',
            'forceframe','huge','language','large','listing','ljmp','loadds','m510','medium','memory',
            'nearstack','nodotname','noemulator','nokeyword','noljmp','nom510','none','nonunique',
            'nooldmacros','nooldstructs','noreadonly','noscoped','nosignextend','nothing',
            'notpublic','oldmacros','oldstructs','os_dos','para','prologue',
            'readonly','req','scoped','setif2','smallstack','tiny','use16','use32','uses'
            )
        ),
which should add 64 bit support, as well as all non-vector instructions up to the opteron series. (vmx/svm and later extentions are still missing)

at least, its an start :)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Syntax Highlighting

Post by Troy Martin »

It appears it's meant for MASM or TASM, not really a NASM syntax.. maybe we should fix that?
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Post Reply