- Joined
- 5 Dec 2001
- Messages
- 6,498
Please see this post I posted for the most up-to-date sed script: http://forum.osnn.net/showpost.php?p=856765&postcount=8
--
I am a sick sick person, and I love regex's . I have written a rather quick and dirty C++ parser that does a few things (I am using this to create my Portfolio website). This is a sed script, which goes through the C++ files it is handed.
It also does some other cool things, for example I wanted to embed links in my C++ source files, so that on the web page those come out, what I figured I would do is take a page from the Markdown idea.
Allows this script to create links that are embedded in the C++ source code files. I figured I'd post it here.
--
I am a sick sick person, and I love regex's . I have written a rather quick and dirty C++ parser that does a few things (I am using this to create my Portfolio website). This is a sed script, which goes through the C++ files it is handed.
It also does some other cool things, for example I wanted to embed links in my C++ source files, so that on the web page those come out, what I figured I would do is take a page from the Markdown idea.
Code:
{Text here}[url here]
Allows this script to create links that are embedded in the C++ source code files. I figured I'd post it here.
Code:
#!/usr/bin/sed -E -f
# Remove anything HTML is going to hate us for
s/</\</g
s/>/\>/g
# Multiline comments
/\/\*\*/,/\*\*\//{
# Replace the first instance with a span
/\/\*\*/c\
<span class="comment">/**
# Close the span
/\*\*\//c\
**/</span>
# We parse URL's in comments, but nothing else!
b url
}
/\/\// {
s/(\/\/ .*)/<span class=\"comment\">\1<\/span>/
b url
}
# Pre-processor
/^#.*/ {
# We add a span to syntax highlight it
s/(#.*)/<span class=\"preproc\">\1<\/span>/
# We want to make links out of the headers we have written
s/#include \"(.*)\"/#include "<a href=\"\.\/\1tml\" alt=\"\1\">\1<\/a>"/
# Only process URL's, nothing else!
b url
}
# Replace text within quotes
s/\"([^"]*)\"/\"<span class=\"text\">\1<\/span>\"/g
# We syntax highlight the standard library stuff (not sure if I want to turn this on)
# s/(std::[^ (]+)/<span class=\"keyword\">\1<\/span>/g
# Types
s/(int)/<span class=\"keyword\">\1<\/span>/g
s/(char)/<span class=\"keyword\">\1<\/span>/g
s/(struct)/<span class=\"keyword\">\1<\/span>/g
# Keywords
s/(switch)/<span class=\"keyword\">\1<\/span>/g
s/(case)/<span class=\"keyword\">\1<\/span>/g
s/(default)/<span class=\"keyword\">\1<\/span>/g
s/(new)/<span class=\"keyword\">\1<\/span>/g
s/(delete)/<span class=\"keyword\">\1<\/span>/g
s/(typedef)/<span class=\"keyword\">\1<\/span>/g
s/(return)/<span class=\"keyword\">\1<\/span>/g
s/(public:)/<span class=\"keyword\">\1<\/span>/g
s/(private:)/<span class=\"keyword\">\1<\/span>/g
s/(protected:)/<span class=\"keyword\">\1<\/span>/g
s/(const)/<span class=\"keyword\">\1<\/span>/g
s/(friend)/<span class=\"keyword\">\1<\/span>/g
# This one is special, if we are not careful we also match class= from all the above <span>'s.
s/(class )/<span class=\"keyword\">class<\/span> /g
: url
# Replace URL's {Text here}[URL here]
s/\{([^\{]*)\}\[([^\[]*)\]/<a href=\"\2\" alt=\"\1\">\1<\/a>/g
Last edited: