1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-26 02:46:13 -04:00

Support more implicit markup of source files

This commit is contained in:
Jonas Fonseca 2006-01-09 11:01:36 +01:00 committed by Jonas Fonseca
parent 9799a66710
commit 938c8a80b4
3 changed files with 99 additions and 56 deletions

View File

@ -6,16 +6,16 @@ monospacedwords=\basciidoc\(1\)
<a id="{0}" href="#{0}">{0}</a> <a id="{0}" href="#{0}">{0}</a>
[enum-inlinemacro] [enum-inlinemacro]
<a id="{0}" href="#{0}">enum {0}</a> <a id="{target}">enum {target}: {0}</a>
[func-inlinemacro] [func-inlinemacro]
<a id="{0}" href="#{0}">{0}()</a> <a id="{target}">{target}(): {0}</a>
[struct-inlinemacro] [struct-inlinemacro]
<a id="{0}" href="#{0}">struct {0}</a> <a id="{target}">struct {target}: {0}</a>
[callback-inlinemacro] [typedef-inlinemacro]
<a id="{0}" href="#{0}">callback {0}</a> <a id="{target}">typedef {target}: {0}</a>
[ref-inlinemacro] [ref-inlinemacro]
<a href="{target}#{0}">{0}</a> <a href="{target}#{0}">{0}</a>

View File

@ -4,7 +4,7 @@ use warnings;
use diagnostics; use diagnostics;
use Getopt::Std; use Getopt::Std;
my $HELP = "Usage: $0 [FILE] my $HELP = "Usage: $0 [FILE]...
Parses [FILE], outputing the result to stdout."; Parses [FILE], outputing the result to stdout.";
sub usage { sub usage {
@ -12,40 +12,84 @@ sub usage {
exit; exit;
} }
our($opt_h, $opt_v); our($opt_h, $opt_v, $title, $body, $indent, $idpath, $inblock);
getopts("hv") or usage($HELP); getopts("hv") or usage($HELP);
$opt_v and usage("Copyleft (c) 2006, Russ Rowan (See `COPYING')"); $opt_v and usage("Copyleft (c) 2006, Russ Rowan (See `COPYING')");
usage($HELP) if $opt_h or @ARGV < 1; usage($HELP) if $opt_h or @ARGV < 1;
my ($header, $indent, $idpath); sub put_section {
$idpath = ''; $indent = ''; if ($title) {
print "\n$title\n";
$_ = $title;
s/[^-]/-/g;
print "$_\n" if not $indent;
}
if ($body) {
$_ = $body;
s/#newline#/$indent/g;
print "$_\n";
}
$title = $body = undef;
}
$idpath = $title = $body = "";
while (<>) while (<>)
{ {
my $end = s/\s*\*+\//\n/ ? 'yes' : undef; my $end = s/\s*\*+\//\n/ ? 'yes' : undef;
if ($end and /[^=]*[\s*](\w+)[\s,;].*\/\*::\s*(.*)/) { if ($end and /[^=]*[\s*](\w+)[\s,;].*\/\*:\s*(.*)/) {
# Implicit id for enum values and struct members. # Implicit id for enum values and struct members.
$_ = "\nid:[$idpath$1]::\n\t$2\n"; print "\nid:[$idpath$1]::\n\t$2\n";
} elsif ($header) { } elsif ($inblock) {
# Redo the indentation, preserve empty lines. # Redo the indentation, preserve empty lines.
s/^(\s|\*)*/$indent/; s/^(\s|\*)*//;
s/^$indent$/\n/; s/^$/\n/;
$body .= "#newline#" . $_;
} elsif (s/^\s*\/\*\*\s(.*)$/$1/) { } elsif (s/^\s*\/\*\*\s*(.*)$/$1/) {
# Found magic header; record idpath and underline title. # Found magic header; flush, record title and set indentation.
$header = "$1"; put_section;
$idpath = /struct:[[]([^\]]+)[\]]/ ? "$1." : ""; $title = "$1";
$indent = /::/ ? "\t" : ""; $indent = /::/ ? "\t" : "";
$_ = '' if $indent;
s/[^-]/-/g; chop;
$_ = "\n$header\n$_\n";
} else { } else {
next if not ($title or $body);
if (/^struct\s+(\w+)\s*{/) {
$title = "struct:$1" . "[$title]";
$idpath = "$1.";
} elsif (/^enum\s+(\w+)\s*{/) {
$title = "enum:$1" . "[$title]";
$idpath = "";
} else {
while (not /[^=]*[\s*](\w+).*[,;]/) {
$_ .= <>;
}
if (/typedef/) {
if (/.*\(\*(\w+)\)\(/) {
$title = "typedef:$1" . "[$title]";
} elsif (/typedef.*\s(\w+);/) {
$title = "typedef:$1" . "[$title]";
}
$idpath = "";
} else {
if (/.*[\s*](\w+)\(/) {
$title = "func:$1" . "[$title]";
$idpath = "";
} elsif (/[^=]*[\s*](\w+)[\s,;]/) {
$title = "id:[$idpath$1]::";
$indent = "\t";
}
}
}
put_section;
next; next;
} }
$header = undef if $end; $inblock = $end ? undef : 'yes';
print STDOUT $_;
} }

View File

@ -11,12 +11,12 @@ struct sgml_parser;
struct string; struct string;
struct uri; struct uri;
/** enum:[sgml_parser_type]: SGML parser type /** SGML parser type
* *
* There are two kinds of parser types: One that optimises one-time access to * There are two kinds of parser types: One that optimises one-time access to
* the DOM tree and one that creates a persistent DOM tree. */ * the DOM tree and one that creates a persistent DOM tree. */
enum sgml_parser_type { enum sgml_parser_type {
/** id:[SGML_PARSER_STREAM]:: /**
* The first one will simply push nodes on the stack, not building a * The first one will simply push nodes on the stack, not building a
* DOM tree. This interface is similar to that of SAX (Simple API for * DOM tree. This interface is similar to that of SAX (Simple API for
* XML) where events are fired when nodes are entered and exited. It is * XML) where events are fired when nodes are entered and exited. It is
@ -24,7 +24,7 @@ enum sgml_parser_type {
* do all processing in a stream-like manner, such as when highlighting * do all processing in a stream-like manner, such as when highlighting
* HTML code. */ * HTML code. */
SGML_PARSER_STREAM, SGML_PARSER_STREAM,
/** id:[SGML_PARSER_TREE]:: /**
* The second one is a DOM tree builder, that builds a persistent DOM * The second one is a DOM tree builder, that builds a persistent DOM
* tree. When using this type, it is possible to do even more * tree. When using this type, it is possible to do even more
* (pre)processing than for parser streams. For example you can sort * (pre)processing than for parser streams. For example you can sort
@ -33,49 +33,48 @@ enum sgml_parser_type {
SGML_PARSER_TREE, SGML_PARSER_TREE,
}; };
/** enum:[sgml_parser_flag]: SGML parser flags /** SGML parser flags
* *
* These flags control how the parser behaves. * These flags control how the parser behaves.
*/ */
enum sgml_parser_flag { enum sgml_parser_flag {
SGML_PARSER_COUNT_LINES = 1, /*:: Make line numbers available. */ SGML_PARSER_COUNT_LINES = 1, /*: Make line numbers available. */
SGML_PARSER_COMPLETE = 2, /*:: Used internally when incremental. */ SGML_PARSER_COMPLETE = 2, /*: Used internally when incremental. */
SGML_PARSER_INCREMENTAL = 4, /*:: Parse chunks of input. */ SGML_PARSER_INCREMENTAL = 4, /*: Parse chunks of input. */
SGML_PARSER_DETECT_ERRORS = 8, /*:: Report errors. */ SGML_PARSER_DETECT_ERRORS = 8, /*: Report errors. */
}; };
/** struct:[sgml_parser_state]: SGML parser state /** SGML parser state
* *
* The SGML parser has only little state. * The SGML parser has only little state.
*/ */
struct sgml_parser_state { struct sgml_parser_state {
/** id:[sgml_parser_state.info]:: /**
* Info about the properties of the node contained by state. * Info about the properties of the node contained by state.
* This is only meaningful to element and attribute nodes. For * This is only meaningful to element and attribute nodes. For
* unknown nodes it points to the common 'unknown node' info. */ * unknown nodes it points to the common 'unknown node' info. */
struct sgml_node_info *info; struct sgml_node_info *info;
/** id:[sgml_parser_state.end_token]:: /**
* This is used by the DOM source renderer for highlighting the * This is used by the DOM source renderer for highlighting the
* end-tag of an element. */ * end-tag of an element. */
struct dom_scanner_token end_token; struct dom_scanner_token end_token;
}; };
/** enum:[sgml_parser_code]: (Error) codes for the SGML parser /** (Error) codes for the SGML parser
* *
* These enum values are used for return codes. * These enum values are used for return codes.
*/ */
enum sgml_parser_code { enum sgml_parser_code {
SGML_PARSER_CODE_OK, /*:: The parsing was successful */ SGML_PARSER_CODE_OK, /*: The parsing was successful */
SGML_PARSER_CODE_INCOMPLETE, /*:: The parsing could not be completed */ SGML_PARSER_CODE_INCOMPLETE, /*: The parsing could not be completed */
SGML_PARSER_CODE_MEM_ALLOC, /*:: Failed to allocate memory */ SGML_PARSER_CODE_MEM_ALLOC, /*: Failed to allocate memory */
/**
/** id:[SGML_PARSER_CODE_ERROR]::
* FIXME: For when we will add support for requiring stricter parsing * FIXME: For when we will add support for requiring stricter parsing
* or even a validator. */ * or even a validator. */
SGML_PARSER_CODE_ERROR, SGML_PARSER_CODE_ERROR,
}; };
/** callback:[sgml_error_T]: SGML error callback /** SGML error callback
* *
* Called by the SGML parser when a parsing error has occurred. * Called by the SGML parser when a parsing error has occurred.
* *
@ -85,29 +84,29 @@ typedef enum sgml_parser_code
(*sgml_error_T)(struct sgml_parser *, struct dom_string *, unsigned int); (*sgml_error_T)(struct sgml_parser *, struct dom_string *, unsigned int);
/** struct:[sgml_parser]: The SGML parser /** The SGML parser
* *
* This struct hold info used while parsing SGML data. * This struct hold info used while parsing SGML data.
* *
* NOTE: The only variable the user should set is ref:[sgml_parser.error_func]. * NOTE: The only variable the user should set is ref:[sgml_parser.error_func].
*/ */
struct sgml_parser { struct sgml_parser {
enum sgml_parser_type type; /*:: Stream or tree */ enum sgml_parser_type type; /*: Stream or tree */
enum sgml_parser_flag flags; /*:: Flags that control the behaviour */ enum sgml_parser_flag flags; /*: Flags that control the behaviour */
struct sgml_info *info; /*:: Backend dependent info */ struct sgml_info *info; /*: Backend dependent info */
struct dom_string uri; /*:: The URI of the DOM document */ struct dom_string uri; /*: The URI of the DOM document */
struct dom_node *root; /*:: The document root node */ struct dom_node *root; /*: The document root node */
sgml_error_T error_func; /*:: Called for detected errors */ sgml_error_T error_func; /*: Called for detected errors */
struct dom_stack stack; /*:: A stack for tracking parsed nodes */ struct dom_stack stack; /*: A stack for tracking parsed nodes */
struct dom_stack parsing; /*:: Used for tracking parsing states */ struct dom_stack parsing; /*: Used for tracking parsing states */
}; };
/** func:[init_sgml_parser]: Initialise an SGML parser /** Initialise an SGML parser
* *
* Initialise an SGML parser with the given properties. * Initialise an SGML parser with the given properties.
* *
@ -122,7 +121,7 @@ struct sgml_parser *
init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype, init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
struct dom_string *uri, enum sgml_parser_flag flags); struct dom_string *uri, enum sgml_parser_flag flags);
/** func:[done_sgml_parser]: Release an SGML parser /** Release an SGML parser
* *
* Deallocates all resources, _expect_ the root node. * Deallocates all resources, _expect_ the root node.
* *
@ -130,7 +129,7 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
*/ */
void done_sgml_parser(struct sgml_parser *parser); void done_sgml_parser(struct sgml_parser *parser);
/** func:[parse_sgml]: Parse a chunk of SGML source /** Parse a chunk of SGML source
* *
* Parses the given `buffer`. For incremental rendering the last buffer can be * Parses the given `buffer`. For incremental rendering the last buffer can be
* signals through the `complete` parameter. * signals through the `complete` parameter.
@ -145,7 +144,7 @@ void done_sgml_parser(struct sgml_parser *parser);
enum sgml_parser_code enum sgml_parser_code
parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete); parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete);
/** func:[get_sgml_parser_line_number]: Get the line position in the source /** Get the line position in the source
* *
* Returns what line number the parser is currently at or zero if there has * Returns what line number the parser is currently at or zero if there has
* been no parsing yet. * been no parsing yet.