flat assembler
Message board for the users of flat assembler.

flat assembler > Examples and Tutorials > Syntax Highlighter: Convert Code 2 HTML

Author
Thread Post new topic Reply to topic
m3ntal



Joined: 08 Dec 2013
Posts: 296
A minimal syntax highlighter (HTML+CSS) written in FASM's preprocessor language. Supports comments, numbers, 'strings' and operators. Easily customizable and upgradable.

How To: In NAME.ASM, specify SOURCE.EXT file/s then Run/F9 to generate *.HTML. Preview:
Code:
; EXAMPLE.ASM>*.HTML

include 'html.inc'

source.file equ 'DRAW.INC'
title.t equ 'Drawing Functions'

comment.color equ '#A0A0A0'
number.color equ '#5E00F7'
symbol.color equ '#2207FF'
string.color equ '#FF1777'

html.begin
html.code source.file
html.end    
Code:
;;;;;;;;;;;;;;;;;;;; HTML.INC ;;;;;;;;;;;;;;;;;;;;

format binary as 'HTML'

is.symbol? equ \
 a=';' | a=27h | a=22h | a='=' | a=',' | \
 a='+' | a='-' | a='*' | a='/' | a='%' | \
 a='\' | a='(' | a=')' | a='{' | a='}' | \
 a='[' | a=']' | a='<' | a='>' | a='~' | \
 a='&' | a='|' | a='^' | a=':' | a='#' | a='`'

is.symbolic? equ \
 a='_' | a='.' | a='?' | a='!' | a='@' | a='$'

is.space?  equ (a=' ' | a=9)
is.return? equ (a=0Dh | a=0Ah)
is.white?  equ (is.space? | is.return?)
is.string? equ (a=27h | a=22h)
is.upper?  equ (a>='A' & a<='Z')
is.lower?  equ (a>='a' & a<='z')
is.alpha?  equ (is.upper? | is.lower?)
is.name?   equ (is.alpha? | is.symbolic?)
is.number? equ (a>='0' & a<='9')
is.hex.a?  equ (a>='a' & a<='f')
is.hex.A?  equ (a>='A' & a<='F')
is.digit?  equ (is.hex.a? | is.hex.A?)
is.suffix? equ (a='h' | a='H' | a='b' | a='B')
is.end?    equ (is.white? | is.symbol?)

R equ 0Dh,0Ah

macro htmlx [p] { forward db p }

macro html [p] { common htmlx p, R }

macro html.begin title {
 html '<!DOCTYPE html>', '<html>', '<head>'
 html '<meta http-equiv="content-type"'
 html 'context="text/html; charset=windows-1252">'
 html '<title>', title.t, '</title>', '</head>'
 html '<body bgcolor="#FFFFFF">', '<b>', R

 html '<style>', R, 'body {'
 html ' font-size: 18px;'
 html ' font-weight: bold;'
 html ' width: 720px;'
 html ' font-family: "Consolas",'
 html ' "Bitstream Vera Sans Mono",'
 html ' "Courier New", "Courier",'
 html ' "Andale Mono WT", "Andale Mono",'
 html ' "Lucida Console", "DejaVu Sans Mono",'
 html ' "Monaco", monospace;'
 html '}', R

 html '.comment {'
 htmlx ' color: ', comment.color, ';', R
 html ' font-style: italic;'
 html '}', R

 htmlx '.symbol { color: ', symbol.color, '; }', R
 htmlx '.number { color: ', number.color, '; }', R
 htmlx '.string { color: ', string.color, '; }', R
 html '</style>', R
}

macro html.text t, a {
 db '<font color="#000000" size="4" '
 db 'face="Times New Roman">', R
 db '<p align="', `a, '">', R
 db t, R, '</p>', '</font>', R, R
}

macro html.subject s, a {
 db '<font color="#000000" size="5" '
 db 'face="Times New Roman">', R
 db '<p align="', `a, '"><u><i>', R
 db s, R, '</i></u></p>', '</font>', R, R
}

macro html.end { html '</body>', '</html>' }

macro style name
 { db '<span class=''', `name, '''>' }

macro end.style { db '</span>' }    
Code:
;;;;;;;;; SOURCE CODE, SYNTAX HIGHLIGHT ;;;;;;;;;;

; load/extract/insert source file with
; syntax highlighting

macro html.code name {
 local p, i, line.n,\
  in.comment?, in.number?, in.string?

 db '<pre style="background:white; color:black;', R
 db 'border:2px solid white; padding:.2em .2em;">', R

 virtual at 0
  p:: file name
  file.$=$
 end virtual

 line.n=1
 in.comment?=0
 in.number?=0
 in.string?=0
 i=0
 while i<file.$
  load a byte from p:i
  if a=0Dh
   line.n=line.n+1
  end if
  if in.comment?
   if a=0Dh
    in.comment?=0
    end.style
   end if
   db a
  else if in.number?
   if is.end?
    in.number?=0
    end.style
   end if
   db a
  else if in.string?
   if is.string?
    in.string?=0
    db a
    end.style
   else
    db a
   end if
  else if is.number?
   c=a
   if in.number?=0
    if i>0
     load a byte \
      from p:i-1
     if ((is.end? | \
      ~is.name?) & \
      ~is.number?)
      in.number?=1
      style number
     end if
    else
     in.number?=1
     style number
    end if
   end if
   db c
  else if is.string?
   in.string?=1
   style string
   db a
  else if is.symbol?
   if a=';'
    in.comment?=1
    style comment
    db a
   else
    style symbol
    db a
    end.style
   end if
  else
   db a
  end if
  i=i+1
 end while

 db '</pre>'
}    

New: [ARM] Magic-ARM Library, Import/Export


Description: Syntax Highlighter + Examples
Download
Filename: syntax.zip
Filesize: 24.87 KB
Downloaded: 199 Time(s)

Post 10 Apr 2014, 19:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.