2014-08-01 10:37:32 +08:00
|
|
|
#! @sed@ -f
|
|
|
|
#.
|
|
|
|
# A Doxygen filter for building Fish's lexicon, for documentation bling.
|
|
|
|
#.
|
|
|
|
# Written specially for Fish, the shell for the 90's, in sed, the state of the
|
|
|
|
# art text processor from the 70's. Who's sed? sed's dead, baby, sed's dead.*
|
|
|
|
# by Mark Griffiths <mark@thebespokepixel.com> *but quite portable
|
|
|
|
#.
|
2016-07-16 18:27:02 +08:00
|
|
|
# Finds \fish..\endfish blocks in documentation source files and enhances
|
2014-08-02 11:51:43 +08:00
|
|
|
# markup. Requires that the four character word 'classes' declared here are
|
|
|
|
# added to Doxyfiles as aliases i.e.:
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Enhance for HTML Help pages (Doxyfile.user)…
|
|
|
|
# ALIASES = "fish=\htmlonly[block] \n<pre class=\"fish\">"
|
|
|
|
# ALIASES += "fish{1}=\htmlonly[block] \n<pre class=\"fish \1\">"
|
|
|
|
# ALIASES += "endfish=</pre>\endhtmlonly \n"
|
|
|
|
#.
|
|
|
|
# ALIASES += "blah{1}=<span class=\"comment\">\1</span>"
|
2014-08-27 07:30:08 +08:00
|
|
|
# ALIASES += "bltn{1}=<span class=\"command\">\1</span>" and so on...
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# And simplify for man pages (Doxyfile.help)…
|
|
|
|
# ALIASES = "fish=<pre>"
|
|
|
|
# ALIASES += "fish{1}=<pre>"
|
|
|
|
# ALIASES += "endfish=</pre>"
|
|
|
|
#.
|
|
|
|
# ALIASES += "blah{1}=\1"
|
2014-08-27 07:30:08 +08:00
|
|
|
# ALIASES += "bltn{1}=<em>\1</em>"...
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
2014-08-02 11:51:43 +08:00
|
|
|
# It's meant to only ever be run once, during make, as Doxygen's 'INPUT
|
|
|
|
# FILTER', though can be run interactively by passing a file in via stdin. It
|
|
|
|
# wont respond to arguments.
|
|
|
|
#.
|
|
|
|
# It's most easily tested by passing test strings into the compiled script:
|
|
|
|
#.
|
2014-08-03 09:22:23 +08:00
|
|
|
# echo "/fish Line to test" | ./fish_lexicon_filter
|
2014-08-02 11:51:43 +08:00
|
|
|
#.
|
|
|
|
# The, at times, archiac looking regex is down to ensuring portable sed BREs
|
|
|
|
#.
|
2014-09-18 21:07:58 +08:00
|
|
|
# This code is licensed with fish under the GPL 2.0.
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Pattern flow control for scanning doc.h
|
|
|
|
/\\fish/,/\\endfish/ {
|
2014-08-02 11:51:43 +08:00
|
|
|
# Open \fish block, firstly it it's on it's own line
|
2014-08-01 10:37:32 +08:00
|
|
|
/^\\fish$/b
|
|
|
|
/^\\fish{[^}]*}$/b
|
2014-08-02 11:51:43 +08:00
|
|
|
# Then if it's inline. Remove and process immediately...
|
2014-08-01 10:37:32 +08:00
|
|
|
/^\\fish.*$/ {
|
2014-08-08 10:44:37 +08:00
|
|
|
# Catch @ symbol
|
2016-04-04 20:43:37 +08:00
|
|
|
s/@/@at/g
|
|
|
|
# Catch & symbol
|
|
|
|
s/&\([^a-z]\)/@amp\1/g
|
|
|
|
# Catch {{ & }} symbols
|
|
|
|
s/{{/@curlyL/g
|
|
|
|
s/}}/@curlyR/g
|
2014-08-01 10:37:32 +08:00
|
|
|
s/^\\fish//
|
|
|
|
s/\\endfish//
|
2014-08-08 10:44:37 +08:00
|
|
|
b html
|
2014-08-01 10:37:32 +08:00
|
|
|
}
|
|
|
|
# Output blank lines
|
|
|
|
/^$/b
|
|
|
|
# Inside \fish block. Process...
|
|
|
|
/\\endfish/!{
|
2014-08-08 10:44:37 +08:00
|
|
|
# Catch @ symbol
|
2016-04-04 20:43:37 +08:00
|
|
|
s/@/@at/g
|
|
|
|
# Catch & symbol
|
|
|
|
s/&\([^a-z]\)/@amp\1/g
|
|
|
|
# Catch {{ & }} symbols
|
|
|
|
s/{{/@curlyL/g
|
|
|
|
s/}}/@curlyR/g
|
2014-08-01 10:37:32 +08:00
|
|
|
# Preprocess HTML and HTML-like formatting
|
|
|
|
/<[^>]*>/ {
|
|
|
|
b html
|
|
|
|
}
|
|
|
|
# Process the rest
|
|
|
|
b process
|
|
|
|
}
|
|
|
|
# End block
|
|
|
|
/\\endfish/b
|
|
|
|
}
|
|
|
|
#.
|
|
|
|
# This is not the pattern we're looking for
|
|
|
|
b
|
|
|
|
#.
|
|
|
|
# Process any HTML tags.
|
|
|
|
# Structured to reduce sed's greediness.
|
|
|
|
:html
|
|
|
|
# Spans
|
|
|
|
s|<span style=['"]\([^'"][^'"]*\)">|@span{\1,|
|
|
|
|
s|<span class=['"]\([^'"][^'"]*\)">|@spcl{\1,|
|
|
|
|
s|</span>|}|
|
|
|
|
#.
|
|
|
|
# Bold
|
|
|
|
s|<b>|@bold{|
|
|
|
|
s|<b [^>]*>|@bold{|
|
|
|
|
s|</b>|}|
|
|
|
|
#.
|
2016-07-16 18:27:02 +08:00
|
|
|
# Strong (synonimous with emphasis)
|
2014-08-01 10:37:32 +08:00
|
|
|
s|<strong>|@bold{|
|
|
|
|
s|<strong [^>]*>|@bold{|
|
|
|
|
s|</strong>|}|
|
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
# EMPHasis
|
2014-08-01 10:37:32 +08:00
|
|
|
s|<em>|@emph{|
|
|
|
|
s|<em [^>]*>|@emph{|
|
|
|
|
s|</em>|}|
|
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
# Italic (synonimous with emphasis)
|
|
|
|
s|<i>|@emph{|
|
|
|
|
s|<i [^>]*>|@emph{|
|
|
|
|
s|</i>|}|
|
|
|
|
#.
|
|
|
|
# UNDeRline
|
2014-08-01 10:37:32 +08:00
|
|
|
s|<u>|@undr{|
|
|
|
|
s|<u [^>]*>|@undr{|
|
|
|
|
s|</u>|}|
|
2016-07-16 18:27:02 +08:00
|
|
|
# Backslash (when escaping output)
|
|
|
|
s|<bs>|@bksl{|
|
|
|
|
s|</bs>|}|
|
|
|
|
t html
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
2016-07-16 18:27:02 +08:00
|
|
|
# Some handy non-standard extensions
|
|
|
|
# autoSuGgeSTion
|
|
|
|
s|<s>|@sgst{|
|
|
|
|
s|<s [^>]*>|@sgst{|
|
|
|
|
s|</s>|}|
|
|
|
|
#.
|
|
|
|
# MaTCH
|
|
|
|
s|<m>|@mtch{|
|
|
|
|
s|<m [^>]*>|@mtch{|
|
|
|
|
s|</m>|}|
|
|
|
|
#.
|
|
|
|
# SearchMaTCh
|
|
|
|
s|<sm>|@smtc{|
|
|
|
|
s|<sm [^>]*>|@smtc{|
|
|
|
|
s|</sm>|}|
|
|
|
|
#.
|
|
|
|
# ERrOR
|
2017-02-13 07:39:22 +08:00
|
|
|
s|<eror>|@eror{|
|
|
|
|
s|<eror [^>]*>|@eror{|
|
|
|
|
s|</eror>|}|
|
2016-07-16 18:27:02 +08:00
|
|
|
#.
|
|
|
|
# AsIs - protect from auto-formatting
|
|
|
|
s|<asis>|@asis{|
|
|
|
|
s|</asis>|}|
|
|
|
|
#.
|
|
|
|
# OUTPut - protect from auto-formatting
|
|
|
|
s|<outp>|@outp{|
|
|
|
|
s|</outp>|}|
|
2014-08-01 10:37:32 +08:00
|
|
|
t html
|
|
|
|
#.
|
|
|
|
# Clean other unhandled html
|
|
|
|
s|<\([A-Za-z][A-Za-z]*\)[^>]*>\([^<]*\)</\1>|\2|
|
|
|
|
t html
|
|
|
|
#.
|
|
|
|
# Start processing entities
|
|
|
|
:process
|
2014-08-08 10:44:37 +08:00
|
|
|
# Output:
|
|
|
|
# Line marked as output pass through
|
|
|
|
/@outp/ {
|
|
|
|
b
|
|
|
|
}
|
2014-08-01 10:37:32 +08:00
|
|
|
# Comments:
|
|
|
|
# Capture full line comments
|
2014-08-08 10:44:37 +08:00
|
|
|
/^\( *\)#\(.*\)$/ {
|
2014-08-01 10:37:32 +08:00
|
|
|
# Assume any line starting with a # is complete
|
2014-08-08 10:44:37 +08:00
|
|
|
s//\1@blah{\2}/
|
2014-08-01 10:37:32 +08:00
|
|
|
t
|
|
|
|
}
|
|
|
|
# Match sub-line comments
|
2014-08-08 10:44:37 +08:00
|
|
|
/#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]/ ! {
|
|
|
|
s/#\(.*$\)/\\\
|
2014-08-03 00:10:28 +08:00
|
|
|
<@blah{#\1}\
|
|
|
|
/
|
2014-08-08 10:44:37 +08:00
|
|
|
}
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Protected entities These shouldn't allow nested structure, so we move them
|
|
|
|
# to a marked, new line for a future extract/process/insert action.
|
|
|
|
#.
|
|
|
|
# AsIs block - resists formatting.
|
|
|
|
s/@asis{\(.*\)}/\\\
|
|
|
|
<@asis{\1}\
|
|
|
|
/g
|
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
# Manual <span>
|
|
|
|
s/@span{\(.*\)}/\\\
|
|
|
|
<@span{\1}\
|
|
|
|
/g
|
|
|
|
#.
|
2014-08-01 10:37:32 +08:00
|
|
|
# String Literals
|
|
|
|
s/"\([^"]*\)"/\\\
|
|
|
|
<@dblq{\1}\
|
|
|
|
/g
|
|
|
|
s/'\([^']*\)'/\\\
|
|
|
|
<@sglq{\1}\
|
|
|
|
/g
|
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
# AutoSuggestions.
|
|
|
|
s/@sgst{\([^}]*\)}/\\\
|
|
|
|
<@sgst{\1}\
|
|
|
|
/
|
|
|
|
#.
|
2014-08-01 10:37:32 +08:00
|
|
|
# Command/Function options
|
|
|
|
# Short options
|
2014-09-23 12:18:16 +08:00
|
|
|
s/\([[( ]\)-\([A-Za-z][A-Za-z]*\)\([^A-Za-z}]\)/\1\\\
|
|
|
|
<@opts{-\2}\
|
|
|
|
\3/g
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Long options
|
2014-09-23 12:18:16 +08:00
|
|
|
s/\([[( ]\)--\([A-Za-z][A-Za-z0-9=_-]*\)\([^A-Za-z0-9=_-]*\)/\1\\\
|
|
|
|
<@opts{--\2}\
|
|
|
|
\3/g
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
# Prompt
|
|
|
|
s/~>_/\\\
|
2014-08-27 02:19:24 +08:00
|
|
|
<@prmt{\
|
|
|
|
<@path{~}\
|
|
|
|
}/
|
2014-08-08 10:44:37 +08:00
|
|
|
s/^>_/@prmt/
|
|
|
|
#.
|
|
|
|
# Cursor
|
|
|
|
#.
|
2014-08-27 02:19:24 +08:00
|
|
|
s/___$/@curs/
|
|
|
|
s/___\(.\)/\\\
|
2014-08-08 10:44:37 +08:00
|
|
|
<@curs{\1}\
|
|
|
|
/
|
|
|
|
#.
|
2014-09-23 12:18:16 +08:00
|
|
|
# Escaped Options
|
|
|
|
s/ \\\([A-Za-z0-9][A-Za-z0-9]*\) / @bksl{\1} /g
|
|
|
|
#.
|
2014-09-03 20:06:49 +08:00
|
|
|
# Trailing Backslash
|
|
|
|
s/ \\$/ @bksl{ }/
|
|
|
|
#.
|
2014-08-01 10:37:32 +08:00
|
|
|
# Paths
|
2014-08-08 10:44:37 +08:00
|
|
|
/\n<@dblq[^}]*[~/]/b protect
|
|
|
|
/\n<@sglq[^}]*[~/]/b protect
|
|
|
|
/\n<@span[^}]*[~/]/b protect
|
|
|
|
#.
|
2014-08-01 10:37:32 +08:00
|
|
|
# Normal Directory
|
2014-08-08 10:44:37 +08:00
|
|
|
s|mkdir |mkdir :|
|
2016-04-04 20:43:37 +08:00
|
|
|
s|\([~/:][/]*[.A-Za-z_0-9*/-]*\)\\ |\1=|g
|
|
|
|
s| \([~/][/]*[.A-Za-z_0-9*/=-]*\)| \\\
|
2014-08-08 10:44:37 +08:00
|
|
|
<@path{\1}\
|
|
|
|
|g
|
2016-04-04 20:43:37 +08:00
|
|
|
s| \(:[/]*[.A-Za-z_0-9*/=-]*\)| \\\
|
2014-08-08 10:44:37 +08:00
|
|
|
<@path{\1}\
|
2014-08-01 10:37:32 +08:00
|
|
|
|g
|
2014-08-08 10:44:37 +08:00
|
|
|
t protect
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
# Dot Relative Directory (no spaces in path)
|
2014-08-27 02:19:24 +08:00
|
|
|
s| \(./[A-Za-z_0-9/-]*\)| \\\
|
2014-08-08 10:44:37 +08:00
|
|
|
<@path{\1}\
|
|
|
|
|g
|
2014-08-01 10:37:32 +08:00
|
|
|
b protect
|
2014-08-02 11:51:43 +08:00
|
|
|
#.
|
2014-08-01 10:37:32 +08:00
|
|
|
# Tidy up. Merge back 'pure' entities from hold space.
|
|
|
|
:tidy
|
|
|
|
#.
|
2014-08-27 02:19:24 +08:00
|
|
|
# Convert loose text to arguments
|
|
|
|
s/ \([a-zA-Z0-9+%*.-][{},a-zA-Z0-9%*._/?!=-]*\)/ @args{\1}/g
|
|
|
|
#.
|
|
|
|
# Or when tight to a newline
|
|
|
|
s|\n\([a-zA-Z0-9+%*.-][{},a-zA-Z0-9%*._/?!-]*\)|\
|
|
|
|
@args{\1}|g
|
|
|
|
#.
|
|
|
|
# Or when tight to the beginning
|
|
|
|
s|^\([a-zA-Z][{},a-zA-Z0-9%*._/?!-]*\)|@args{\1}|g
|
|
|
|
#.
|
|
|
|
# Pick up loose text after markup.
|
|
|
|
s/\([})]\)\([a-zA-Z0-9+%*.,][,a-zA-Z0-9%*._/?!-]*\);/\1@args{\2};/g
|
|
|
|
s/\([})]\)\([a-zA-Z0-9+%*.,][,a-zA-Z0-9%*._/?!-]*\)$/\1@args{\2}/g
|
2016-04-04 20:43:37 +08:00
|
|
|
s/\([})]\)\([a-zA-Z0-9+%*.,][,a-zA-Z0-9%*._/?!-]*\)@EOL/\1@args{\2}/g
|
2014-08-27 02:19:24 +08:00
|
|
|
#.
|
2014-08-01 10:37:32 +08:00
|
|
|
# Uncomment the following 2 lines (ss) to log the pattern buffer.
|
2014-08-27 02:19:24 +08:00
|
|
|
s/^.*$/Pattern : &/w lexicon.log
|
|
|
|
s/^Pattern : //
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Uncomment the following 4 lines (xssx) to log the hold buffer.
|
2014-08-08 10:44:37 +08:00
|
|
|
x
|
2014-08-27 02:19:24 +08:00
|
|
|
s/^.*$/HoldBufr: &/w lexicon.log
|
|
|
|
s/^HoldBufr: //
|
2014-08-08 10:44:37 +08:00
|
|
|
x
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Tack the hold space to the end of the pattern buffer.
|
|
|
|
G
|
|
|
|
#.
|
|
|
|
# Uncomment the folowing two lines (ss) to log the buffer join.
|
2014-09-03 22:10:53 +08:00
|
|
|
s/^.*$/Joined : &/w lexicon.log
|
|
|
|
s/^Joined : //
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Iterate over alternate lines, matching '<' to '\'
|
|
|
|
:join
|
2014-08-08 10:44:37 +08:00
|
|
|
s,\([^\\ ]*\)\\\n\([^<]*\)<\(@[^}]*[}\\]\),\1\3\2,
|
2014-08-01 10:37:32 +08:00
|
|
|
t join
|
|
|
|
# Clean up stray new lines
|
|
|
|
s/\n//g
|
2016-04-04 20:43:37 +08:00
|
|
|
# Clean up past @EOL
|
|
|
|
s/@EOL.*$//g
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
2014-08-27 02:19:24 +08:00
|
|
|
# Uncomment the folowing two lines (ss) to log the buffer before 'cleaning'.
|
|
|
|
s/^.*$/PreClean: &/w lexicon.log
|
|
|
|
s/^PreClean: //
|
2014-08-01 10:37:32 +08:00
|
|
|
# Clean up special cases
|
|
|
|
#.
|
2014-08-03 00:10:28 +08:00
|
|
|
/@blah/{
|
|
|
|
s/\(blah{[^@]*\)@sglq{\([^}]*\)}/\1'\2'/
|
|
|
|
s/\(blah{[^@]*\)@dblq{\([^}]*\)}/\1"\2"/
|
|
|
|
s/\(blah{[^@]*\)@....{\([^}]*\)}/\1\2/
|
|
|
|
}
|
2014-08-19 17:58:22 +08:00
|
|
|
/@dblq/{
|
|
|
|
:cleandblq
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\(dblq{[^@}<]*\)[<]*@...[^q]{\([^}]*\)}/\1\2/
|
2014-08-19 17:58:22 +08:00
|
|
|
t cleandblq
|
|
|
|
}
|
|
|
|
/@sglq/{
|
|
|
|
:cleansglq
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\(sglq{[^@}<]*\)[<]*@...[^q]{\([^}]*\)}/\1\2/
|
2014-08-19 17:58:22 +08:00
|
|
|
t cleansglq
|
|
|
|
}
|
2014-08-27 02:19:24 +08:00
|
|
|
/@vars/{
|
|
|
|
:cleanvars
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(vars{@optr{$}[^@}]*\)@bltn{\([^}]*\)}/\1\2/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\(vars{@optr{$}[^@}]*\)@func{\([^}]*\)}/\1\2/
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(vars{@optr{$}[^@}]*\)@cmnd{\([^}]*\)}/\1\2/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\(vars{@optr{$}[^@}]*\)@args{\([^}]*\)}/\1\2/
|
|
|
|
t cleanvars
|
|
|
|
}
|
2014-08-01 10:37:32 +08:00
|
|
|
/@redr/{
|
|
|
|
:cleanredr
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(redr{[^@}]*\)@bltn{\([^}]*\)}/\1\2/
|
2014-08-03 00:10:28 +08:00
|
|
|
s/\(redr{[^@}]*\)@func{\([^}]*\)}/\1\2/
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(redr{[^@}]*\)@cmnd{\([^}]*\)}/\1\2/
|
2014-08-03 00:10:28 +08:00
|
|
|
s/\(redr{[^@}]*\)@fsfo{\([^}]*\)}/\1\2/
|
2014-08-02 11:51:43 +08:00
|
|
|
s/\(redr{[^}]*\)}\( *\)@path{\([^}]*\)/\1\2\3/
|
2014-08-01 10:37:32 +08:00
|
|
|
t cleanredr
|
|
|
|
}
|
2014-08-19 17:58:22 +08:00
|
|
|
/@sgst/{
|
|
|
|
s/@sgst{<@/@sgst{@/
|
2014-08-08 10:44:37 +08:00
|
|
|
:cleansgst
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(sgst{@curs{.}[^@]*\)@bltn{\([^}]*\)}/\1\2/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\(sgst{@curs{.}[^@]*\)@func{\([^}]*\)}/\1\2/
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(sgst{@curs{.}[^@]*\)@cmnd{\([^}]*\)}/\1\2/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\(sgst{@curs{.}[^@]*\)@opts{\([^}]*\)}/\1\2/
|
2014-08-08 10:44:37 +08:00
|
|
|
s/\(sgst{@curs{.}[^@]*\)@path{\([^}]*\)}/\1\2/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\(sgst{@curs{.}[^@]*\)@args{\([^}]*\)}/\1\2/
|
2014-08-19 17:58:22 +08:00
|
|
|
s/\(sgst{@curs{.}[^@]*\)@fsfo{\([^}]*\)}/\1\2/
|
2014-08-08 10:44:37 +08:00
|
|
|
t cleansgst
|
|
|
|
}
|
2014-08-01 10:37:32 +08:00
|
|
|
/@fsfo/{
|
|
|
|
:cleanfsfo
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(fsfo{[^@}]*\)@bltn{\([^}]*\)}/\1\2/
|
2014-08-03 00:10:28 +08:00
|
|
|
s/\(fsfo{[^@}]*\)@func{\([^}]*\)}/\1\2/
|
2014-08-27 07:30:08 +08:00
|
|
|
s/\(fsfo{[^@}]*\)@cmnd{\([^}]*\)}/\1\2/
|
2014-08-01 10:37:32 +08:00
|
|
|
t cleanfsfo
|
|
|
|
}
|
2014-08-19 17:58:22 +08:00
|
|
|
/@prmt{/{
|
|
|
|
s/@prmt{<@path/@prmt{@path/
|
|
|
|
}
|
2014-08-02 11:51:43 +08:00
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
# Restore Paths
|
|
|
|
/@fsfo/ {
|
|
|
|
s/\(@fsfo{[^=]*\)=/\1 /
|
|
|
|
}
|
|
|
|
/@path/ {
|
|
|
|
:cleanpath
|
|
|
|
s/\(@path{[^:]*\):/\1/
|
|
|
|
s/\(@path{[^=]*\)=/\1\\ /
|
|
|
|
t cleanpath
|
|
|
|
s/@path{}//
|
|
|
|
}
|
|
|
|
#.
|
2014-08-02 11:51:43 +08:00
|
|
|
# Finally, restructure to follow Fish's command [arguments] semantics.
|
2014-08-03 00:10:28 +08:00
|
|
|
# Find the initial command, and change any others to arguments, up to a |, ( or ;
|
2014-08-02 11:51:43 +08:00
|
|
|
# Assumes that a valid line will start with either a builtin, a function or a binary.
|
|
|
|
#.
|
2014-08-03 09:22:23 +08:00
|
|
|
# 'if' and 'for' seem to be special cases
|
2014-08-08 10:44:37 +08:00
|
|
|
#.
|
2014-08-27 02:19:24 +08:00
|
|
|
# Uncomment the folowing two lines (ss) to log the buffer before semantic conversion.
|
|
|
|
s/^.*$/PreArgs : &/w lexicon.log
|
|
|
|
s/^PreArgs : //
|
2014-08-08 10:44:37 +08:00
|
|
|
#.
|
|
|
|
# Find initial commands/functions/binaries
|
|
|
|
#.
|
|
|
|
# Store prmt, if present
|
|
|
|
#.
|
|
|
|
/@prmt/ {
|
|
|
|
h
|
|
|
|
s/^\(@prmt *\).*$/\1/
|
|
|
|
x
|
|
|
|
s/^@prmt *//
|
2014-08-03 09:22:23 +08:00
|
|
|
}
|
2014-08-08 10:44:37 +08:00
|
|
|
#.
|
2014-08-27 07:30:08 +08:00
|
|
|
# Special case for optional commands
|
|
|
|
s/@args{\[@bltn/@args{[@xbln/g
|
2014-08-27 02:19:24 +08:00
|
|
|
# Special case for one-line 'if' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{if}/ {
|
|
|
|
s//@xbln{if}/
|
|
|
|
s/@bltn{set}/@xbln{set}/
|
|
|
|
s/@bltn{not}/@xbln{not}/
|
|
|
|
s/@bltn{else}/@xbln{else}/
|
|
|
|
s/@bltn{contains}/@xbln{contains}/
|
|
|
|
s/@bltn{test}/@xbln{test}/
|
|
|
|
s/@bltn{end}/@xbln{end}/
|
|
|
|
s/@cmnd{grep}/@xcmd{grep}/
|
2014-08-27 02:19:24 +08:00
|
|
|
}
|
|
|
|
# one-line 'for' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{for}/ {
|
|
|
|
s//@xbln{for}/
|
|
|
|
s/@args{in}/@xbln{in}/
|
2014-08-27 02:19:24 +08:00
|
|
|
}
|
|
|
|
# one-line 'begin' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{begin}/ {
|
|
|
|
s//@xbln{begin}/
|
|
|
|
s/@bltn{end}/@xbln{end}/
|
2014-08-27 02:19:24 +08:00
|
|
|
}
|
|
|
|
# one-line 'break' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{break}/ {
|
|
|
|
s//@xbln{break}/
|
|
|
|
s/@bltn{end}/@xbln{end}/
|
2014-08-27 02:19:24 +08:00
|
|
|
}
|
|
|
|
# one-line 'continue' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{continue}/ {
|
|
|
|
s//@xbln{continue}/
|
|
|
|
s/@bltn{end}/@xbln{end}/
|
2014-08-27 02:19:24 +08:00
|
|
|
}
|
|
|
|
# one-line 'switch' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{switch}/ {
|
|
|
|
s//@xbln{switch}/
|
|
|
|
s/@bltn{case}/@xbln{case}/
|
|
|
|
s/@bltn{end}/@xbln{end}/
|
2014-08-27 02:19:24 +08:00
|
|
|
}
|
|
|
|
# one-line 'function' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{function}/ {
|
|
|
|
s//@xbln{function}/
|
|
|
|
s/@bltn{return}/@xbln{return}/
|
|
|
|
s/@bltn{end}/@xbln{end}/
|
2014-08-27 02:19:24 +08:00
|
|
|
}
|
|
|
|
# one-line 'bind' statements - special input functions
|
2014-08-27 07:30:08 +08:00
|
|
|
/@bltn{bind}/ {
|
|
|
|
s//@xbln{bind}/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/@....{\([a-z]*\)}\(-[a-z-]*\)/@args{\1\2}/
|
|
|
|
}
|
|
|
|
# one-line 'builtin' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
s/@bltn{builtin} @bltn/@xbln{builtin} @xbln/g
|
|
|
|
s/@bltn{builtin} @cmnd/@xbln{builtin} @xcmd/g
|
|
|
|
s/@bltn{builtin} @func/@xbln{builtin} @xfnc/g
|
2014-08-27 02:19:24 +08:00
|
|
|
#.
|
|
|
|
# one-line 'command' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
s/@bltn{command} @bltn/@xbln{command} @xbln/g
|
|
|
|
s/@bltn{command} @cmnd/@xbln{command} @xcmd/g
|
|
|
|
s/@bltn{command} @func/@xbln{command} @xfnc/g
|
2014-08-27 02:19:24 +08:00
|
|
|
#.
|
|
|
|
# one-line 'and/or' statements
|
2014-08-27 07:30:08 +08:00
|
|
|
s/@bltn{and} @bltn/@xbln{and} @xbln/g
|
|
|
|
s/@bltn{and} @cmnd/@xbln{and} @xcmd/g
|
|
|
|
s/@bltn{and} @func/@xbln{and} @xfnc/g
|
|
|
|
s/@bltn{or} @bltn/@xbln{or} @xbln/g
|
|
|
|
s/@bltn{or} @cmnd/@xbln{or} @xcmd/g
|
|
|
|
s/@bltn{or} @func/@xbln{or} @xfnc/g
|
|
|
|
#.
|
2014-08-08 10:44:37 +08:00
|
|
|
s/^\( *\)@cmnd/\1@xcmd/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\( *[;()] *\)@cmnd/\1@xcmd/g
|
|
|
|
s/\( *@redr{|} *\)@cmnd/\1@xcmd/g
|
2014-08-27 07:30:08 +08:00
|
|
|
s/^\( *\)@bltn/\1@xbln/
|
|
|
|
s/\( *[;()] *\)@bltn/\1@xbln/g
|
|
|
|
s/\( *@redr{|} *\)@bltn/\1@xbln/g
|
2014-08-08 10:44:37 +08:00
|
|
|
s/^\( *\)@func/\1@xfnc/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\( *[;()] *\)@func/\1@xfnc/g
|
|
|
|
s/\( *@redr{|} *\)@func/\1@xfnc/g
|
2014-09-23 12:18:16 +08:00
|
|
|
s/ @bksl{\([^}]*\)} / @args{@bksl{\1}} /g
|
|
|
|
s/ @bksl{@bltn{\([^}]*\)}/ @args{@bksl{\1}/g
|
|
|
|
s/ @bksl{@func{\([^}]*\)}/ @args{@bksl{\1}/g
|
|
|
|
s/ @bksl{@cmnd{\([^}]*\)}/ @args{@bksl{\1}/g
|
2014-08-27 07:30:08 +08:00
|
|
|
s/@bltn/@args/g
|
2014-08-08 10:44:37 +08:00
|
|
|
s/@func/@args/g
|
2014-08-27 07:30:08 +08:00
|
|
|
s/@cmnd/@args/g
|
2014-08-27 02:19:24 +08:00
|
|
|
#.
|
|
|
|
s/^.*$/PostArgs: &/w lexicon.log
|
|
|
|
s/^PostArgs: //
|
2014-08-03 09:22:23 +08:00
|
|
|
#.
|
2014-08-27 07:30:08 +08:00
|
|
|
s/xbln/bltn/g
|
2014-08-02 11:51:43 +08:00
|
|
|
s/xfnc/func/g
|
2014-08-27 07:30:08 +08:00
|
|
|
s/xcmd/cmnd/g
|
2014-08-08 10:44:37 +08:00
|
|
|
x
|
|
|
|
/^@prmt/ {
|
|
|
|
G
|
|
|
|
s/^@prmt \n/@prmt /
|
|
|
|
}
|
|
|
|
/^@prmt/ ! {
|
|
|
|
x
|
2014-08-03 09:22:23 +08:00
|
|
|
}
|
|
|
|
#.
|
|
|
|
# Mark up sesitive character entities.
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
s/</\</g
|
|
|
|
s/>/\>/g
|
2016-04-04 20:43:37 +08:00
|
|
|
s/@amp/\&/g
|
|
|
|
s/@curlyL/\{/g
|
|
|
|
s/@curlyR/\}/g
|
|
|
|
s/@at/@atat{ }/g
|
2014-08-27 07:30:08 +08:00
|
|
|
#.
|
|
|
|
# Final post processing
|
|
|
|
s/};\([^]]\)/}@redr{;}\1/g
|
|
|
|
s/};$/}@redr{;}/
|
2016-04-04 20:43:37 +08:00
|
|
|
s/@sglq{}/''/
|
2014-08-27 07:30:08 +08:00
|
|
|
s/ \[\([@(]\)/ @args{[}\1/g
|
|
|
|
s/ \[\([A-Z]*\) / @args{[\1} /g
|
|
|
|
s/@args{\([a-zA-Z0-9_.]*\)}\]/@args{\1]}/g
|
|
|
|
s/@args{\([a-zA-Z0-9_.]*\)}: /@args{\1:} /g
|
|
|
|
s/@bltn{echo} @fsfo/@bltn{echo} @args/g
|
|
|
|
s/@bltn{echo}\([a-zA-Z0-9.@{} _-]*\)@fsfo/@bltn{echo}\1@args/g
|
|
|
|
s/ \] / @args{]} /g
|
|
|
|
s/ \]$/ @args{]}/g
|
|
|
|
s/\]}\]$/]]}/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\\\([()]\)/@optr{@bksl{\1}}/g
|
|
|
|
s/\([()]\)/@optr{\1}/g
|
2016-04-04 20:43:37 +08:00
|
|
|
s/\\\\\([cdgnstwx?]\)/@bksl{\1}/g
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\\n/@bksl{n}/
|
2016-04-04 20:43:37 +08:00
|
|
|
s/%\([diouxXfgGeEsbmy]\)/@pcnt{\1}/g
|
2014-08-27 07:30:08 +08:00
|
|
|
s/ \\$//
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Uncomment the folowing two lines (ss) to log the final output, sent to Doxygen.
|
2014-08-27 02:19:24 +08:00
|
|
|
s/^.*$/Output : &\
|
|
|
|
\
|
|
|
|
/w lexicon.log
|
|
|
|
s/^Output : //
|
|
|
|
s/\n\n$//
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Lines are reassembled, so branch to end
|
|
|
|
b
|
2014-08-08 10:44:37 +08:00
|
|
|
# === Main End ===
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
# === Subroutines ===
|
|
|
|
# Branched to when content requires.
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Move protected content to hold space and mark up other entities.
|
|
|
|
:protect
|
2016-04-04 20:43:37 +08:00
|
|
|
# Add an 'End of Line' marker
|
|
|
|
s/$/@EOL/
|
2014-08-27 02:19:24 +08:00
|
|
|
s/^.*$/Input : &/w lexicon.log
|
|
|
|
s/^Input : //
|
2014-08-01 10:37:32 +08:00
|
|
|
h
|
|
|
|
# Clear out any content that has already been marked up, to prevent futher
|
|
|
|
# markup on words that should be left alone.
|
|
|
|
#.
|
|
|
|
:patternflush
|
2014-08-08 10:44:37 +08:00
|
|
|
s/\n<@[^}]*[}\\]//
|
|
|
|
s/\\ [^\\]*$/\\/
|
2014-08-01 10:37:32 +08:00
|
|
|
t patternflush
|
2014-08-08 10:44:37 +08:00
|
|
|
s/\n$//g
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Swap the pattern and hold buffers and remove unmarked lines and extra
|
|
|
|
# characters. Basically the inverse of the 'patternflush' action, with
|
|
|
|
# additional trailing characters stripped.
|
|
|
|
x
|
2014-10-02 09:02:01 +08:00
|
|
|
/^<@[^}]*$/ ! {
|
2014-08-19 17:58:22 +08:00
|
|
|
s/[^\<]*//
|
2014-08-27 02:19:24 +08:00
|
|
|
s/^ *\\\n//g
|
|
|
|
s/\n *\\//g
|
2016-04-04 20:43:37 +08:00
|
|
|
s/\n@EOL//g
|
2014-08-27 02:19:24 +08:00
|
|
|
s/[()] \\//g
|
2014-08-19 17:58:22 +08:00
|
|
|
s/^[^\<][^@][^\\]*//
|
|
|
|
s/\n[]|;) ][^\\]*\\//
|
2014-09-04 18:32:22 +08:00
|
|
|
s/\n[]|;) a-zA-Z0-9-][^\\]*$//
|
2014-08-19 17:58:22 +08:00
|
|
|
s/\n[]|;)}]\\//
|
|
|
|
s/\n[]|;)}]\n//
|
|
|
|
s/\n[]|;)}]$//
|
|
|
|
s/[()]$//
|
|
|
|
s/}@curs/}/
|
|
|
|
s/\n@curs$//
|
|
|
|
s/\n[^\<@][^\\]*\\//
|
|
|
|
s/\n[^\<@][^\\]*//
|
|
|
|
s/^\\//
|
|
|
|
s/\n$//g
|
|
|
|
}
|
2014-08-16 17:36:34 +08:00
|
|
|
s/\\\n/\
|
|
|
|
/
|
2014-10-02 09:02:01 +08:00
|
|
|
s/< \n//
|
2014-08-27 02:19:24 +08:00
|
|
|
s/^[a-z][a-z]* \n//
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Swap the buffers back.
|
|
|
|
x
|
|
|
|
#.
|
2016-04-04 20:43:37 +08:00
|
|
|
# A special case. Tidy up after performing command substitution.
|
2014-08-01 10:37:32 +08:00
|
|
|
# Redirectors
|
|
|
|
s/\([^{|] *\)|/\1@redr{|}/g
|
2018-03-05 12:17:28 +08:00
|
|
|
#s/\&@EOL$/@redr{@amp}@EOL/g
|
|
|
|
#s/@amp@EOL$/@redr{@amp}@EOL/g
|
|
|
|
#s/\([<>]\)@amp\([0-9]\)/@redr{\1@amp\2}/g
|
|
|
|
s/@amp&/@optr{@amp@amp}/g
|
|
|
|
#s/\([^{&] *\)&[^@a-z]/\1@redr{\&}/g
|
2014-08-30 18:03:02 +08:00
|
|
|
s/\([^{<>^] *\)\([0-9]* *[<>^][<>^]*[^@][a-zA-Z0-9./_-]*\)/\1@redr{\2}/g
|
2014-08-16 17:36:34 +08:00
|
|
|
s/\\}/}\\/g
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Now we can add in 'unsafe' entities that would be too greedy.
|
2014-08-27 02:19:24 +08:00
|
|
|
# Arrays
|
|
|
|
s/[[][0-9$a-zA-Z_;. -]*]/@args{&}/g
|
|
|
|
#.
|
2014-08-01 10:37:32 +08:00
|
|
|
# Declared Variables
|
2014-08-27 02:19:24 +08:00
|
|
|
s/\($[$]*\)\([A-Za-z_0-9][A-Za-z_0-9]*\)/@vars{@optr{\1}\2}/g
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
# Files
|
2016-04-04 20:43:37 +08:00
|
|
|
/@at/ ! {
|
|
|
|
s/\([A-Za-z0-9_*-][A-Za-z0-9_*-]*\.[a-z0-9*][a-z0-9*]*\)/@fsfo{\1}/g
|
|
|
|
}
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
|
|
|
#### This section is built in the Makefile. Just some formatting examples. #####
|
|
|
|
#.
|
2014-08-27 07:30:08 +08:00
|
|
|
# Fish builtin (bltn) <- 4 character code that has a Doxygen alias counterpart
|
|
|
|
# template : s/[[:<:]]function[[:>:]]/@bltn{&}/
|
2014-08-01 10:37:32 +08:00
|
|
|
#.
|
2014-08-27 07:30:08 +08:00
|
|
|
# s,[[:<:]]function[[:>:]],@bltn{function},g
|
|
|
|
# s,[[:<:]]begin[[:>:]],@bltn{begin},g
|
2014-08-01 10:37:32 +08:00
|
|
|
# ...
|
|
|
|
#.
|
2014-08-27 07:30:08 +08:00
|
|
|
# Fish functions (func)
|
2014-08-01 10:37:32 +08:00
|
|
|
# Populated by 'public' functions' filename.
|
|
|
|
#.
|
|
|
|
# s,[[:<:]]fish_pwd[[:>:]],@func{fish_pwd},g
|
|
|
|
# s,[[:<:]]fish_prompt[[:>:]],@func{fish_prompt},g
|
|
|
|
# ...
|
|
|
|
#.
|
2014-08-27 07:30:08 +08:00
|
|
|
# Shell Command (cmnd)
|
2014-08-01 10:37:32 +08:00
|
|
|
# Populated from completion filenames
|
|
|
|
#.
|
2014-08-27 07:30:08 +08:00
|
|
|
# s,[[:<:]]seq[[:>:]],@cmnd{seq},g
|
|
|
|
# s,[[:<:]]rm[[:>:]],@cmnd{rm},g
|
2014-08-01 10:37:32 +08:00
|
|
|
# ...
|
|
|
|
#.
|
|
|
|
# Color Variable (clrv)
|
|
|
|
# Populated from __fish_config_interactive.fish
|
|
|
|
# Allows fish's 'special' color variables to be identified
|
|
|
|
#.
|
|
|
|
# s,[[:<:]]fish_color_normal[[:>:]],@clrv{fish_color_normal},g
|
|
|
|
# s,[[:<:]]fish_color_command[[:>:]],@clrv{fish_color_command},g
|
|
|
|
#.
|
|
|
|
# Once all of the commands/functions/variables/special's have been marked up,
|
|
|
|
# branch back to tidy up and collapse the pattern/hold buffers back to a
|
|
|
|
# single line.
|
|
|
|
#.
|
|
|
|
# b tidy
|
2014-08-27 02:19:24 +08:00
|
|
|
#.
|
|
|
|
#.
|
|
|
|
# Below is a special section that adds vocabuarly to the lexicon during 'make'.
|
|
|
|
# As the lexicon is written into the output lexicon_filter, portability is
|
|
|
|
# automatically handled.
|
|
|
|
#.
|
2014-09-04 17:54:18 +08:00
|
|
|
#.!# cmnd whoami
|
|
|
|
#.!# cmnd mkdir
|
|
|
|
#.!# cmnd basename
|
|
|
|
#.!# bltn sleep
|
|
|
|
#.!# args in
|