Make punctuation active characters and map them to the \nogloss macro (XeTeX)

This is a follow-up to this answer and comment. Does anyone have an idea how to automate the \nogloss macro so that I don't have to label every punctuation mark (or at least ! ? " , .) with it?

EDIT: Thanks to @Alan Munn, I now realize that I'm looking for a XeTeX-compatible solution.

MWE:

\documentclass{book}
\usepackage{expex}
\lingset{glwordalign=center}

\begin{document}
\exdisplay
\begingl
\gla \nogloss{} @ aaaaa aaaaaaa @ \nogloss{!''} aaaa aaaa aaaa @ \nogloss{\ldots} //
\glb bbbbb bbbbbbb bbbb bbbb bbbb //
\glc ccccc ccccccc cccc cccc cccc //
\endgl
\xe
\end{document}


EDIT: To clarify, I want my input to be like the MWE below but for the automation to yield the MWE above, or at least the output of what the above code would yield.

\documentclass{book}
\usepackage{expex}
\lingset{glwordalign=center}

\begin{document}
\exdisplay
\begingl
\gla "aaaaa aaaaaaa!" aaaa aaaa aaaa... //
\glb bbbbb bbbbbbb bbbb bbbb bbbb //
\glc ccccc ccccccc cccc cccc cccc //
\endgl
\xe
\end{document}


Using the technique explained in Mico's answer here:

We can do the same thing for your cases. This requires compilation with LuaLaTeX.

Note: This answer was added before we discovered that a XeLaTeX solution was required, but I will leave it here since many (but not all) XeLaTeX documents can be compiled with LuaLaTeX as well.

This is lightly tested. The function checks for opening quotes and trailing punctuation followed by a space, so it should work as intended if your input looks like that. For example, it won't include word internal punctuation marks like a colon marking vowel length.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{expex}
\lingset{glwordalign=center}

\usepackage{luacode}
\begin{luacode*}

function replace_punc ( buff )
if string.find ( buff , "\\gla" ) then
buff = string.gsub ( buff , " ()" ,
"\\nogloss{%1} @ " )
buff = string.gsub ( buff, "([:.,;'!?]+)( )" ,
" @ \\nogloss{%1}%2" )

end
return ( buff )
end

luatexbase.add_to_callback ( "process_input_buffer", replace_punc, "replace_punc" )
\end{luacode*}

\begin{document}
\exdisplay
\begingl
\gla aaaaa aaaaaaa!?:!'' aaaa aaaa aaaa. //
\glb a bbbbbbb bbbb bbbb bbbb //
\glc ccccc ccccccc cccc cccc cccc //
\endgl
\xe

\end{document}


• This does indeed work (in LuaLaTex). The only problem is that I use a XeLaTex environment. Is there a fix for that? I didn't realize that would be an issue when I first posed the question. – AML Jul 29 '17 at 0:04
• This is a LuaTeX only solution, I'm afraid. But for most things, any document that compiles with XeLaTeX will also compile with LuaLaTeX without any changes, unless your're using XeTeX specific stuff (e.g. xeCJK for Chinese). – Alan Munn Jul 29 '17 at 0:10
• I do seem to be using XeTeX specific stuff. Should I post this same question again but make it XeTeX specific, or can you edit your answer to give a XeTex solution as well? – AML Jul 29 '17 at 0:24
• No, there's no way to do what I did with any other TeX engine. This is using Lua to preprocess the document before TeX even sees it, which only LuaTeX can do. Are you sure that you are using XeTeX specific code in your documents? Most normal XeLaTeX documents won't use it. If you take one of your existing documents and compile it with LuaLaTeX, what happens? As for asking another question, I don't think there's much sense in that. You're welcome to "unaccept" this answer for a while to see if another kind of solution is possible, although I'm skeptical of that. – Alan Munn Jul 29 '17 at 0:32
• When I compile my document with LuaLaTex, it fails. The packages I'm using are microtype, geometry, expex, polyglossia with Hebrew script, fontenc, ifoddpage. I'm unclear which of those are XeLaTeX-only. I think maybe the fontenc. – AML Jul 29 '17 at 0:46