Skip to content

Commit

Permalink
Add html dumper of Nemerle sources.
Browse files Browse the repository at this point in the history
git-svn-id: https://nemerle.googlecode.com/svn/nemerle/trunk@3388 c8a6711f-211a-0410-a8d5-2f220496d6d1
  • Loading branch information
nazgul committed Oct 28, 2004
1 parent 8b4cc34 commit 29a2d82
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
48 changes: 48 additions & 0 deletions misc/htmldumper/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright (c) 2003, 2004 The University of Wroclaw.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the University may not be used to endorse or promote
# products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
# NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Include configuration determined by configure script.
include ../../config.mak

############################################################
# VARIABLES
############################################################

EXECUTE = $(NET_ENGINE) $(NET_FLAGS)

############################################################
# TARGETS
############################################################

all: dumper.exe

dumper.exe: dumper.n
$(EXECUTE) ../../ncc/out.stage3/ncc.exe -r ../../ncc/out.stage3/Nemerle.Compiler.dll -out dumper.exe dumper.n

clean:
rm -f *.exe core core.[0-9]*

117 changes: 117 additions & 0 deletions misc/htmldumper/dumper.n
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System.Globalization;

using Nemerle.Compiler;
using Nemerle.IO;

class LexerDumper : LexerFile {
mutable last_dump_loc : Location = Location.Default;
mutable last_dump_length : int = 0;

public this (file : string) {
base (file);
store_comments = true;
}

public override GetToken () : Token {
def tok = base.GetToken ();
def (token_len, token_str) =
match (tok) {
| Token.Identifier (name) => (name.Length, name)

| Token.Keyword (name) =>
(name.Length, $"<span class='key'>$name</span>")

| Token.Operator (name, _) =>
(name.Length, $"<span class='op'>$name</span>")

| Token.StringLiteral (value) =>
def value = value.Replace ("\n", "\\n");
(value.Length + 2, $"<span class='str'>\"$value\"</span>")

| Token.CharLiteral (value) =>
(3, $"<span class='char'>'$(value)'</span>")

| Token.SByteLiteral (value) =>
def str = value.ToString ();
(str.Length + 2, $"<span class='num'>$(value)SB</span>")

| Token.ByteLiteral (value) =>
def str = value.ToString ();
(str.Length + 1, $"<span class='num'>$(value)B</span>")

| Token.ShortLiteral (value) =>
def str = value.ToString ();
(str.Length + 1, $"<span class='num'>$(value)S</span>")

| Token.UShortLiteral (value) =>
def str = value.ToString ();
(str.Length + 2, $"<span class='num'>$(value)US</span>")

| Token.IntLiteral (value) =>
def str = value.ToString ();
(str.Length, $"<span class='num'>$(value)</span>")

| Token.UIntLiteral (value) =>
def str = value.ToString ();
(str.Length + 1, $"<span class='num'>$(value)U</span>")

| Token.LongLiteral (value) =>
def str = value.ToString ();
(str.Length + 1, $"<span class='num'>$(value)L</span>")

| Token.ULongLiteral (value) =>
def str = value.ToString ();
(str.Length + 2, $"<span class='num'>$(value)UL</span>")

| Token.FloatLiteral (value) =>
def str = value.ToString (CultureInfo.InvariantCulture);
(str.Length + 1, $"<span class='num'>$(value)f</span>")

| Token.DoubleLiteral (value) =>
def str = value.ToString (CultureInfo.InvariantCulture);
(str.Length, $"<span class='num'>$(value)</span>")

| Token.DecimalLiteral (value) =>
def str = value.ToString (CultureInfo.InvariantCulture);
(str.Length + 1, $"<span class='num'>$(value)M</span>")

| Token.Comment (value) =>
(value.Length + 6, $"<span class='comment'>/* $(value) */</span>")

| Token.EndOfFile => (0, "")
}
def cur_loc = this.Location;
if (cur_loc.Line != last_dump_loc.Line && cur_loc != Location.Default) {
repeat (cur_loc.Line - last_dump_loc.Line) print ("<br>");
repeat (cur_loc.Column) print ("&nbsp;");
}
else
repeat (cur_loc.Column - last_dump_loc.Column - last_dump_length)
Nemerle.IO.print ("&nbsp;");
last_dump_loc = cur_loc;
last_dump_length = token_len;
print (token_str);
tok
}
}

module Dumper {
Main (args : array <string>) : void {
if (args.Length < 1) printf ("usage: dumper.exe filename\n");
else {
def filename = args [0];
LibraryReferenceManager.LoadMacrosFrom ("Nemerle.Macros");
MacroRegistry.LoadSyntaxExtensions ("Nemerle.Core");
Location.AddFiles ([filename]);

def lex = LexerDumper (filename);
print ("<head>\n"
" <link id='MainStyle' type='text/css' rel='stylesheet' href='style.css'></link>\n"
"</head>\n"
"<body>\n");
_ = Parser.parse (lex);
print ("\n</body>\n");
}
}
}

6 changes: 6 additions & 0 deletions misc/htmldumper/dumphtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

echo $PWD
make
export MONO_PATH=$MONO_PATH:../../ncc/out.stage3/;
mono dumper.exe $@

0 comments on commit 29a2d82

Please sign in to comment.