-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ljs015/master
minor bug fixes & another handler based off of your basic.awk (ljs015)
- Loading branch information
Showing
4 changed files
with
239 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# This is a basic gawk backend for bashdoc(1) | ||
# (c) 2007 Andrés J. Díaz <[email protected]> | ||
# -- | ||
# This file is part of bashdoc project. | ||
|
||
# At the beggining set the flag last_comment to 0, this flag is used to | ||
# detect when a code block starts (or a comment block ends). | ||
BEGIN { last_comment=0; debug=1 } | ||
|
||
# We ignore lines which starts by a comment followed by exclamation mark or | ||
# minus sign. | ||
/^[#]!/ { | ||
if (debug == 0) | ||
next | ||
else | ||
print "<ignore>"$0 | ||
} | ||
/^[#]-/ { | ||
if (debug == 0) | ||
next | ||
else | ||
print "<ignore>"$0 | ||
} | ||
|
||
# Code block parser. We consider a code block everthing which are not | ||
# a comment block. We print the :: mark (starts a pre-formated block in RST) | ||
# only at the beggining of code block. | ||
/^[:space:]*[^#\n].*/ { | ||
if (last_comment == 1) | ||
printf "\n\n::\n\n" | ||
last_comment=0 | ||
if (debug == 0) | ||
print " "$0 | ||
else | ||
print " <code>"$0 | ||
} | ||
|
||
# The following rules create a RST notes for each codification label, such | ||
# as TODO, FIXME and XXX. | ||
/^[#][ ]*TODO.*/ { | ||
print "\n.. note:: To-Do" | ||
sub("^[#][ ]*TODO[:]?","") | ||
if (debug == 0) | ||
print " "$0 | ||
else | ||
print " <TODO>"$0 | ||
} | ||
/^[#][ ]*FIXME.*/ { | ||
print "\n.. note:: Fix me" | ||
sub("^[#][ ]*FIXME[:]?","") | ||
if (debug == 0) | ||
print " "$0 | ||
else | ||
print " <FIXME>"$0 | ||
} | ||
/^[#][ ]*XXX.*/ { | ||
print "\n.. note:: Hack" | ||
sub("^[#][ ]*XXX[:]?","") | ||
if (debug == 0) | ||
print " "$0 | ||
else | ||
print " <HACK>"$0 | ||
} | ||
|
||
# Comment block parser. A comment block is a number of lines starting by | ||
# a sharp symbol (#). We also accept lines in advanced bsah guide format, | ||
# such as #+ and #>. Some text are parser specially, for example the | ||
# copyright line in emphatized, and both, copyright and registered symbols | ||
# are substituted. | ||
/^[#].*/ { | ||
last_comment=1 | ||
sub("^[:space:]*#[+> ]*","") | ||
sub("^[Cc]opyright.*","*&*") | ||
sub("\\([cC]\\)","©") | ||
sub("\\([rR]\\)","®") | ||
|
||
if (debug == 0) | ||
printf "\n%s",$0 | ||
else | ||
printf "\n<comment>%s",$0 | ||
} | ||
|
||
# Finally print the EOL (we do not put the EOL when parsing comment block. | ||
END { printf "\n" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# This is an attempted at a correction to the basic gawk backend for bashdoc(1) | ||
# the author doesn't really understand liscenses & copyright; don't be a dick. | ||
|
||
# initial state | ||
BEGIN { | ||
debug = 0 | ||
bash_pound_comment_line = 0 | ||
styled_bash_pound_comment_line = 0 | ||
consecutive_noncomment_lines = 0 | ||
ignore_this_line = 0 | ||
} | ||
|
||
# Skip shebangs | ||
(FNR == 1) && /^#!.*$/ { | ||
if (debug == 1) | ||
print "*next*; shebang:"$0 | ||
next | ||
} | ||
|
||
# I haven't played around with these yet; straight from the original basic.awk: | ||
# The following rules create a RST notes for each codification label, such | ||
# as TODO, FIXME and XXX. | ||
# /^[#][ ]*TODO.*/ { | ||
# print "\n.. note:: To-Do" | ||
# sub("^[#][ ]*TODO[:]?","") | ||
# if (debug == 0) | ||
# print " "$0 | ||
# else | ||
# print " <TODO>"$0 | ||
# } | ||
# /^[#][ ]*FIXME.*/ { | ||
# print "\n.. note:: Fix me" | ||
# sub("^[#][ ]*FIXME[:]?","") | ||
# if (debug == 0) | ||
# print " "$0 | ||
# else | ||
# print " <FIXME>"$0 | ||
# } | ||
# /^[#][ ]*XXX.*/ { | ||
# print "\n.. note:: Hack" | ||
# sub("^[#][ ]*XXX[:]?","") | ||
# if (debug == 0) | ||
# print " "$0 | ||
# else | ||
# print " <HACK>"$0 | ||
# } | ||
|
||
# detection first, printing later | ||
# ------------------------------- | ||
|
||
# detect anything that is not a 'bash-#-comment-only line' | ||
/^[[:space:]]*[^#].*$/ { | ||
bash_pound_comment_line = 0 | ||
styled_bash_pound_comment_line = 0 | ||
ignore_this_line = 0 | ||
if (debug == 1) | ||
print "not a 'bash-#-comment-only line':"$0 | ||
} | ||
# detect anything that is a 'bash-#-comment-only line' | ||
/^[[:space:]]*[#].*$/ { | ||
bash_pound_comment_line = 1 | ||
styled_bash_pound_comment_line = 0 | ||
ignore_this_line = 0 | ||
if (debug == 1) | ||
print "is a 'bash-#-comment-only line':"$0 | ||
} | ||
# detect anything that is a styled 'bash-#-comment-only line' and which we should not ignore | ||
/^[[:space:]]*[#][![:space:]].*$/ { | ||
if ((debug == 1) && (bash_pound_comment_line != 1)) | ||
print "*error state*; 'bash-#-comment-only line' should have already registered." | ||
styled_bash_pound_comment_line = 1 | ||
ignore_this_line = 0 | ||
if (debug == 1) | ||
print "is a styled 'bash-#-comment-only line':"$0 | ||
} | ||
# detect anything that is a styled 'bash-#-comment-only line' and which we should ignore | ||
/^[[:space:]]*[#][^![:space:]].*$/ { | ||
if ((debug == 1) && (bash_pound_comment_line != 1)) | ||
print "*error state*; 'bash-#-comment-only line' should have already registered." | ||
styled_bash_pound_comment_line = 1 | ||
ignore_this_line = 1 | ||
if (debug == 1) | ||
print "*ignored*; is a styled 'bash-#-comment-only line':"$0 | ||
} | ||
# detect blank lines because nothing else will | ||
/^$/ { | ||
bash_pound_comment_line = 0 | ||
styled_bash_pound_comment_line = 0 | ||
ignore_this_line = 1 | ||
if (debug == 1) | ||
print "*ignored*; is a blank line:"$0 | ||
} | ||
# I can't think of a way to account for the following comments using a single regexp or just a few regexps (textbook regexs shouldn't be able to catch the patterns of these lines) | ||
# These could be accounted for individually, but that would be bad for users (it would dash their unentitled expectations and make them rage, a lot) and would not scale to cover the more general problem. | ||
# | ||
# ^$((muffin--)) # I have less muffins now.$ | ||
# | ||
# ^wigglytuff_used='#' # It's not very effective.$ | ||
# | ||
# ^wigglytuff_used='##' # It's not very effective.$ | ||
# | ||
# ^wigglytuff_used='#"' # It's not very effective.$ | ||
# | ||
# ^wigglytuff_used='"#"' # It's not very effective.$ | ||
# | ||
# ^wigglytuff_used="#'" # It's not very effective.$ | ||
# | ||
# ^wigglytuff_used="# # It's not very effective.$ | ||
# | ||
# ^} # And *that* was the best function ever.$ | ||
# | ||
# ^{ # don't you want some chocolate right now?$ | ||
# | ||
# ^{ # } # tread carefully if you try to implement single curly-brace cases$ | ||
# | ||
|
||
# printing now | ||
# ------------ | ||
|
||
# If the ignore_this_line flag's state survived this far, then honor it. | ||
ignore_this_line == 1 { | ||
if (debug == 1) | ||
print "*next*; *ignored*:"$0 | ||
next | ||
} | ||
|
||
# print a thing that is exactly a 'bash-#-comment-only line' | ||
(bash_pound_comment_line == 1) && (styled_bash_pound_comment_line == 0) && (parentheses_then_bash_pound_comment_line == 0) { | ||
sub("^[[:space:]]*#","") | ||
printf "\n%s",$0 | ||
consecutive_noncomment_lines = 0 | ||
} | ||
# print a thing that is exactly a styled 'bash-#-comment-only line' | ||
(bash_pound_comment_line == 1) && (styled_bash_pound_comment_line == 1) && (parentheses_then_bash_pound_comment_line == 0) { | ||
sub("^[[:space:]]*#[![:space:]]","") | ||
printf "\n%s",$0 | ||
consecutive_noncomment_lines = 0 | ||
} | ||
# anything that is not a comment, is code; For each code line, if it is consecutively the first such of its code block, then treat it specially. | ||
(bash_pound_comment_line == 0) && (consecutive_noncomment_lines == 0) && (parentheses_then_bash_pound_comment_line == 0) { | ||
printf "\n\n::\n\n" | ||
} | ||
# anything that is not a comment, is code; print it now. | ||
bash_pound_comment_line == 0 { | ||
print " "$0 | ||
++consecutive_noncomment_lines | ||
} | ||
|
||
END { printf "\n" } |