# HG changeset patch # User Aziz K?ksal # Date 1203299617 -3600 # Node ID ef9bee5a2d61381c57acb1d25497b549283b1d0d # Parent 26d8ed59806de92fac01cbbaf7a825a1f3950456 Command 'generate' can print line numbers now. diff -r 26d8ed59806d -r ef9bee5a2d61 trunk/src/cmd/Generate.d --- a/trunk/src/cmd/Generate.d Mon Feb 18 02:47:15 2008 +0100 +++ b/trunk/src/cmd/Generate.d Mon Feb 18 02:53:37 2008 +0100 @@ -23,20 +23,21 @@ import tango.io.Print; /// Options for the generate command. -enum DocOption +enum GenOption { Empty, Tokens = 1, Syntax = 1<<1, HTML = 1<<2, - XML = 1<<3 + XML = 1<<3, + PrintLines = 1<<4 } /// Executes the command. -void execute(string filePath, DocOption options, InfoManager infoMan) +void execute(string filePath, GenOption options, InfoManager infoMan) { - assert(options != DocOption.Empty); - auto mapFilePath = options & DocOption.HTML ? GlobalSettings.htmlMapFile + assert(options != GenOption.Empty); + auto mapFilePath = options & GenOption.HTML ? GlobalSettings.htmlMapFile : GlobalSettings.xmlMapFile; auto map = TagMapLoader(infoMan).load(mapFilePath); auto tags = new TagMap(map); @@ -44,10 +45,10 @@ if (infoMan.hasInfo) return; - if (options & DocOption.Syntax) + if (options & GenOption.Syntax) highlightSyntax(filePath, tags, Stdout, options); else - highlightTokens(filePath, tags, Stdout); + highlightTokens(filePath, tags, Stdout, options); } /// Escapes the characters '<', '>' and '&' with named character entities. @@ -249,7 +250,18 @@ print.format(tags["ParserError"], e.filePath, e.loc, e.col, xml_escape(e.getMsg)); } -void highlightSyntax(string filePath, TagMap tags, Print!(char) print, DocOption options) +void printLines(uint lines, TagMap tags, Print!(char) print) +{ + auto lineNumberFormat = tags["LineNumber"]; + for (auto lineNum = 1; lineNum <= lines; lineNum++) + print.format(lineNumberFormat, lineNum); +} + +// void printMultiline(Token* token, TagMap tags, Print!(char) print) +// { +// } + +void highlightSyntax(string filePath, TagMap tags, Print!(char) print, GenOption options) { auto parser = new Parser(new SourceText(filePath, true)); auto root = parser.start(); @@ -266,6 +278,14 @@ printErrors(parser, tags, print); print(tags["CompEnd"]); } + + if (options & GenOption.PrintLines) + { + print(tags["LineNumberBegin"]); + printLines(lx.lineNum, tags, print); + print(tags["LineNumberEnd"]); + } + print(tags["SourceBegin"]); auto tagNodeBegin = tags["NodeBegin"]; @@ -287,7 +307,7 @@ // Token text. printToken(token, tags, print); // - if (options & DocOption.HTML) + if (options & GenOption.HTML) foreach_reverse (node; tokenEx.endNodes) print(tagNodeEnd); else @@ -299,7 +319,7 @@ } /// Prints all tokens of a source file using the buffer print. -void highlightTokens(string filePath, TagMap tags, Print!(char) print) +void highlightTokens(string filePath, TagMap tags, Print!(char) print, GenOption options) { auto lx = new Lexer(new SourceText(filePath, true)); lx.scanAll(); @@ -311,6 +331,14 @@ printErrors(lx, tags, print); print(tags["CompEnd"]); } + + if (options & GenOption.PrintLines) + { + print(tags["LineNumberBegin"]); + printLines(lx.lineNum, tags, print); + print(tags["LineNumberEnd"]); + } + print(tags["SourceBegin"]); // Traverse linked list and print tokens. for (auto token = lx.firstToken(); token; token = token.next) { diff -r 26d8ed59806d -r ef9bee5a2d61 trunk/src/html.css --- a/trunk/src/html.css Mon Feb 18 02:47:15 2008 +0100 +++ b/trunk/src/html.css Mon Feb 18 02:53:37 2008 +0100 @@ -1,10 +1,12 @@ @charset "utf-8"; -.compilerinfo, .sourcecode { - display: block; +.compilerinfo, .sourcecode, .linescolumn { white-space: pre; font-family: Monospace; font-size: 0.8em; } +.compilerinfo, .sourcecode { + display: block; +} .compilerinfo { white-space: normal; border: 1px solid #A22; @@ -12,20 +14,25 @@ margin: 1em; } .compilerinfo .error { display: block; } +.linescolumn { + float: left; + text-align: right; + margin-right: 0.2em; + border-right: 1px solid gray; +} +.linescolumn a { display: block; } /* Number */ .n { color: teal; } /* Keyword */ .k { color: darkblue; font-weight: bold; } -/* Line and block comments */ -.cl, .ct { color: green; } -/* Nested comments */ -.cn { color: darkgreen; } +/* Line, block and nested comments */ +.lc, .bc, .nc { color: green; } /* Identifier */ .i { color: black; } /* String literal */ .sl { color: red; } /* Character literal */ -.chl { color: purple; } +.cl { color: purple; } /* All bracket types */ .br { color: orange; } /* Special tokens */ @@ -37,15 +44,15 @@ /* When the first line starts with #! it's a "shebang" */ .shebang { color: gray; } /* Operator */ -.op { color: royalblue; } +/*.op { color: royalblue; }*/ /* Particular operators */ -.opaa { content: "and"; } /*&& ∧*/ -.opoo { content: "or"; } /*|| ∨*/ -.opn { content: "¬"; } /*!*/ -.opne { content: "≠"; } /*!=*/ -.ople { content: "≤"; } /*<=*/ -.opge { content: "≥"; } /*>=*/ -.oplg { content: "≶"; } /*<>*/ +/*.opaa { content: "and"; }*/ /*&& ∧*/ +/*.opoo { content: "or"; }*/ /*|| ∨*/ +/*.opn { content: "¬"; }*/ /*!*/ +/*.opne { content: "≠"; }*/ /*!=*/ +/*.ople { content: "≤"; }*/ /*<=*/ +/*.opge { content: "≥"; }*/ /*>=*/ +/*.oplg { content: "≶"; }*/ /*<>*/ /* d = Declaration s = Statement @@ -56,6 +63,6 @@ /* .d { background-color: #FFDDDD; } */ /* .e { background-color: #DDDDFF; } */ .d.Module .i, .d.Import .i { color: blue; } -.t .i { color: #911; } +.t .i, .TemplateTypeParameter .i { color: #911; } .t .br, .t .op { color: #911; } .t .k { color: #911; font-weight: normal; } diff -r 26d8ed59806d -r ef9bee5a2d61 trunk/src/html_map.d --- a/trunk/src/html_map.d Mon Feb 18 02:47:15 2008 +0100 +++ b/trunk/src/html_map.d Mon Feb 18 02:53:37 2008 +0100 @@ -14,6 +14,9 @@ "CompEnd" : "\n", "LexerError" : `

{0}({1},{2})L: {3}

`\n, "ParserError" : `

{0}({1},{2})P: {3}

`\n, + "LineNumberBegin" : `
`, + "LineNumberEnd" : `
`, + "LineNumber" : `{0}`, // Node categories: "Declaration" : "d", diff -r 26d8ed59806d -r ef9bee5a2d61 trunk/src/main.d --- a/trunk/src/main.d Mon Feb 18 02:47:15 2008 +0100 +++ b/trunk/src/main.d Mon Feb 18 02:53:37 2008 +0100 @@ -117,23 +117,25 @@ break; case "gen", "generate": char[] fileName; - DocOption options = DocOption.Tokens; + GenOption options = GenOption.Tokens; foreach (arg; args[2..$]) { switch (arg) { case "--syntax": - options |= DocOption.Syntax; break; + options |= GenOption.Syntax; break; case "--xml": - options |= DocOption.XML; break; + options |= GenOption.XML; break; case "--html": - options |= DocOption.HTML; break; + options |= GenOption.HTML; break; + case "--lines": + options |= GenOption.PrintLines; break; default: fileName = arg; } } - if (!(options & (DocOption.XML | DocOption.HTML))) - options |= DocOption.XML; // Default to XML. + if (!(options & (GenOption.XML | GenOption.HTML))) + options |= GenOption.XML; // Default to XML. cmd.Generate.execute(fileName, options, infoMan); infoMan.hasInfo && printErrors(infoMan); break; @@ -380,7 +382,19 @@ dil d doc/ src/main.d mymacros.ddoc -i`; break; case "gen", "generate": - msg = GetMsg(MID.HelpGenerate); +// msg = GetMsg(MID.HelpGenerate); + msg = `Generate an XML or HTML document from a D source file. +Usage: + dil gen file.d [Options] + +Options: + --syntax : generate tags for the syntax tree + --xml : use XML format (default) + --html : use HTML format + --lines : print line numbers + +Example: + dil gen Parser.d --html --syntax > Parser.html`; break; case "importgraph", "igraph": // msg = GetMsg(MID.HelpImportGraph); diff -r 26d8ed59806d -r ef9bee5a2d61 trunk/src/xml.css --- a/trunk/src/xml.css Mon Feb 18 02:47:15 2008 +0100 +++ b/trunk/src/xml.css Mon Feb 18 02:53:37 2008 +0100 @@ -1,10 +1,12 @@ @charset "utf-8"; -compilerinfo, sourcecode { - display: block; +compilerinfo, sourcecode, linescolumn { white-space: pre; font-family: Monospace; font-size: 0.8em; } +compilerinfo, sourcecode { + display: block; +} compilerinfo { white-space: normal; border: 1px solid #A22; @@ -12,14 +14,20 @@ margin: 1em; } compilerinfo error { display: block; } +linescolumn { + display: block; + float: left; + text-align: right; + margin-right: 0.2em; + border-right: 1px solid gray; +} +linescolumn a { display: block; color: #555; } /* Number */ n { color: teal; } /* Keyword */ k { color: darkblue; font-weight: bold; } -/* Line and block comments */ -c[t=l], c[t=b] { color: green; } -/* Nested comments */ -c[t=n] { color: darkgreen; } +/* Line, block and nested comments */ +lc, bc, nc { color: green; } /* Identifier */ i { color: black; } /* String literal */ @@ -36,16 +44,17 @@ fs { color: purple;} /* When the first line starts with #! it's a "shebang" */ shebang { color: gray; } +/* Deprecated styles. */ /* Operator */ -op { color: royalblue; } +/*op { color: royalblue; }*/ /* Particular operators */ -op[t=aa] { content: "and"; } /*&& ∧*/ -op[t=oo] { content: "or"; } /*|| ∨*/ -op[t=n] { content: "¬"; } /*!*/ -op[t=ne] { content: "≠"; } /*!=*/ -op[t=le] { content: "≤"; } /*<=*/ -op[t=ge] { content: "≥"; } /*>=*/ -op[t=lg] { content: "≶"; } /*<>*/ +/*op[t=aa] { content: "and"; }*/ /*&& ∧*/ +/*op[t=oo] { content: "or"; }*/ /*|| ∨*/ +/*op[t=n] { content: "¬"; }*/ /*!*/ +/*op[t=ne] { content: "≠"; }*/ /*!=*/ +/*op[t=le] { content: "≤"; }*/ /*<=*/ +/*op[t=ge] { content: "≥"; }*/ /*>=*/ +/*op[t=lg] { content: "≶"; }*/ /*<>*/ /* d = Declaration s = Statement @@ -53,10 +62,6 @@ t = Type o = Other */ -o[t=Linkage] i, o[t=Linkage] op -{ - color: red; -} /* d { background-color: #FFDDDD; } */ /* e { background-color: #DDDDFF; } */ d[t=Illegal], s[t=Illegal] { background-color: #DD4422; } diff -r 26d8ed59806d -r ef9bee5a2d61 trunk/src/xml_map.d --- a/trunk/src/xml_map.d Mon Feb 18 02:47:15 2008 +0100 +++ b/trunk/src/xml_map.d Mon Feb 18 02:53:37 2008 +0100 @@ -10,6 +10,9 @@ "CompEnd" : "\n", "LexerError" : `{0}({1},{2})L: {3}`\n, "ParserError" : `{0}({1},{2})P: {3}`\n, + "LineNumberBegin" : ``, + "LineNumberEnd" : ``, + "LineNumber" : `{0}`, // Node categories: "Declaration" : "d",