mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Support more implicit markup of source files
This commit is contained in:
parent
9799a66710
commit
938c8a80b4
@ -6,16 +6,16 @@ monospacedwords=\basciidoc\(1\)
|
||||
<a id="{0}" href="#{0}">{0}</a>
|
||||
|
||||
[enum-inlinemacro]
|
||||
<a id="{0}" href="#{0}">enum {0}</a>
|
||||
<a id="{target}">enum {target}: {0}</a>
|
||||
|
||||
[func-inlinemacro]
|
||||
<a id="{0}" href="#{0}">{0}()</a>
|
||||
<a id="{target}">{target}(): {0}</a>
|
||||
|
||||
[struct-inlinemacro]
|
||||
<a id="{0}" href="#{0}">struct {0}</a>
|
||||
<a id="{target}">struct {target}: {0}</a>
|
||||
|
||||
[callback-inlinemacro]
|
||||
<a id="{0}" href="#{0}">callback {0}</a>
|
||||
[typedef-inlinemacro]
|
||||
<a id="{target}">typedef {target}: {0}</a>
|
||||
|
||||
[ref-inlinemacro]
|
||||
<a href="{target}#{0}">{0}</a>
|
||||
|
@ -4,7 +4,7 @@ use warnings;
|
||||
use diagnostics;
|
||||
use Getopt::Std;
|
||||
|
||||
my $HELP = "Usage: $0 [FILE]
|
||||
my $HELP = "Usage: $0 [FILE]...
|
||||
Parses [FILE], outputing the result to stdout.";
|
||||
|
||||
sub usage {
|
||||
@ -12,40 +12,84 @@ sub usage {
|
||||
exit;
|
||||
}
|
||||
|
||||
our($opt_h, $opt_v);
|
||||
our($opt_h, $opt_v, $title, $body, $indent, $idpath, $inblock);
|
||||
|
||||
getopts("hv") or usage($HELP);
|
||||
$opt_v and usage("Copyleft (c) 2006, Russ Rowan (See `COPYING')");
|
||||
usage($HELP) if $opt_h or @ARGV < 1;
|
||||
|
||||
my ($header, $indent, $idpath);
|
||||
$idpath = ''; $indent = '';
|
||||
sub put_section {
|
||||
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 (<>)
|
||||
{
|
||||
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.
|
||||
$_ = "\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.
|
||||
s/^(\s|\*)*/$indent/;
|
||||
s/^$indent$/\n/;
|
||||
s/^(\s|\*)*//;
|
||||
s/^$/\n/;
|
||||
$body .= "#newline#" . $_;
|
||||
|
||||
} elsif (s/^\s*\/\*\*\s(.*)$/$1/) {
|
||||
# Found magic header; record idpath and underline title.
|
||||
$header = "$1";
|
||||
$idpath = /struct:[[]([^\]]+)[\]]/ ? "$1." : "";
|
||||
$indent = /::/ ? "\t" : "";
|
||||
|
||||
$_ = '' if $indent;
|
||||
s/[^-]/-/g; chop;
|
||||
$_ = "\n$header\n$_\n";
|
||||
} elsif (s/^\s*\/\*\*\s*(.*)$/$1/) {
|
||||
# Found magic header; flush, record title and set indentation.
|
||||
put_section;
|
||||
$title = "$1";
|
||||
$indent = /::/ ? "\t" : "";
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
||||
$header = undef if $end;
|
||||
print STDOUT $_;
|
||||
$inblock = $end ? undef : 'yes';
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ struct sgml_parser;
|
||||
struct string;
|
||||
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
|
||||
* the DOM tree and one that creates a persistent DOM tree. */
|
||||
enum sgml_parser_type {
|
||||
/** id:[SGML_PARSER_STREAM]::
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* HTML code. */
|
||||
SGML_PARSER_STREAM,
|
||||
/** id:[SGML_PARSER_TREE]::
|
||||
/**
|
||||
* 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
|
||||
* (pre)processing than for parser streams. For example you can sort
|
||||
@ -33,49 +33,48 @@ enum sgml_parser_type {
|
||||
SGML_PARSER_TREE,
|
||||
};
|
||||
|
||||
/** enum:[sgml_parser_flag]: SGML parser flags
|
||||
/** SGML parser flags
|
||||
*
|
||||
* These flags control how the parser behaves.
|
||||
*/
|
||||
enum sgml_parser_flag {
|
||||
SGML_PARSER_COUNT_LINES = 1, /*:: Make line numbers available. */
|
||||
SGML_PARSER_COMPLETE = 2, /*:: Used internally when incremental. */
|
||||
SGML_PARSER_INCREMENTAL = 4, /*:: Parse chunks of input. */
|
||||
SGML_PARSER_DETECT_ERRORS = 8, /*:: Report errors. */
|
||||
SGML_PARSER_COUNT_LINES = 1, /*: Make line numbers available. */
|
||||
SGML_PARSER_COMPLETE = 2, /*: Used internally when incremental. */
|
||||
SGML_PARSER_INCREMENTAL = 4, /*: Parse chunks of input. */
|
||||
SGML_PARSER_DETECT_ERRORS = 8, /*: Report errors. */
|
||||
};
|
||||
|
||||
/** struct:[sgml_parser_state]: SGML parser state
|
||||
/** SGML parser state
|
||||
*
|
||||
* The SGML parser has only little state.
|
||||
*/
|
||||
struct sgml_parser_state {
|
||||
/** id:[sgml_parser_state.info]::
|
||||
/**
|
||||
* Info about the properties of the node contained by state.
|
||||
* This is only meaningful to element and attribute nodes. For
|
||||
* unknown nodes it points to the common 'unknown node' info. */
|
||||
struct sgml_node_info *info;
|
||||
/** id:[sgml_parser_state.end_token]::
|
||||
/**
|
||||
* This is used by the DOM source renderer for highlighting the
|
||||
* end-tag of an element. */
|
||||
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.
|
||||
*/
|
||||
enum sgml_parser_code {
|
||||
SGML_PARSER_CODE_OK, /*:: The parsing was successful */
|
||||
SGML_PARSER_CODE_INCOMPLETE, /*:: The parsing could not be completed */
|
||||
SGML_PARSER_CODE_MEM_ALLOC, /*:: Failed to allocate memory */
|
||||
|
||||
/** id:[SGML_PARSER_CODE_ERROR]::
|
||||
SGML_PARSER_CODE_OK, /*: The parsing was successful */
|
||||
SGML_PARSER_CODE_INCOMPLETE, /*: The parsing could not be completed */
|
||||
SGML_PARSER_CODE_MEM_ALLOC, /*: Failed to allocate memory */
|
||||
/**
|
||||
* FIXME: For when we will add support for requiring stricter parsing
|
||||
* or even a validator. */
|
||||
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.
|
||||
*
|
||||
@ -85,29 +84,29 @@ typedef enum sgml_parser_code
|
||||
(*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.
|
||||
*
|
||||
* NOTE: The only variable the user should set is ref:[sgml_parser.error_func].
|
||||
*/
|
||||
struct sgml_parser {
|
||||
enum sgml_parser_type type; /*:: Stream or tree */
|
||||
enum sgml_parser_flag flags; /*:: Flags that control the behaviour */
|
||||
enum sgml_parser_type type; /*: Stream or tree */
|
||||
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_node *root; /*:: The document root node */
|
||||
struct dom_string uri; /*: The URI of the DOM document */
|
||||
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 parsing; /*:: Used for tracking parsing states */
|
||||
struct dom_stack stack; /*: A stack for tracking parsed nodes */
|
||||
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.
|
||||
*
|
||||
@ -122,7 +121,7 @@ struct sgml_parser *
|
||||
init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
||||
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.
|
||||
*
|
||||
@ -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);
|
||||
|
||||
/** 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
|
||||
* signals through the `complete` parameter.
|
||||
@ -145,7 +144,7 @@ void done_sgml_parser(struct sgml_parser *parser);
|
||||
enum sgml_parser_code
|
||||
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
|
||||
* been no parsing yet.
|
||||
|
Loading…
x
Reference in New Issue
Block a user