For example I define \fpeval in Plain LuaTeX:
\begingroup
\catcode`\%=12
\directlua{
function math.round_int ( x )
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
function math.round ( x , n )
return math.round_int ( x*10^n ) / 10^n
end
function gobblezero(x)
local y = math.round ( x , 8 )
if y == math.floor(y) then
return string.format ( "%.0f", y )
else
return math.round(y, 7)
end
end}
\endgroup
\def\fpeval#1{\directlua{tex.print(gobblezero(#1))}}
\directlua{%
p = 68
P = 80}
You have \fpeval{p} of \fpeval{P} points, this makes $\fpeval{p * 100/P},%$.
\bye
But I would like to have a macro called \fpexpr that behaves like \numexpr, so that I can write:
You have \fpexpr p of \fpexpr P points, this makes $\fpexpr p * 100/P \,\%$.
In the first case \fpexpr should take only p as the argument because of has never been defined to be a number or a function like \directlua{of = ...}. The second and the third case are similar as points and \, are undefined in the Lua interpreter.
So \fpexpr should add everything to the lua code until something would be added that would cause an error.
Is this possible?

\fpeval 3+ zzzyou would presumably need to consume the + then see zzz and back up and just take a 3. – David Carlisle Jul 15 '21 at 20:14\numexpris very hard. See Phelype's answer at https://tex.stackexchange.com/questions/492443/understanding-implicit-delimiters-terminators – Steven B. Segletes Jul 15 '21 at 20:14\fpexpr perror-free,fpexpr p *error\fpexpr p * 100error-free\fpexpr p * 100 /error,\fpexpr p * 100/Perror-free,\fpexpr p * 100/P \,how do you know to stop here? – David Carlisle Jul 15 '21 at 20:18\directluaa "mechanism" that in all aspects behaves like\numexprwill be difficult, to say the least: Behaving like\numexprimplies that evaluability depends on the same conditions as the evaluability of\numexpr. For example,\numexpris not expandable, but can be evaluated by prepending\the(or\number) or when assigning values to count registers or TeX integer parameters and the like. :-) – Ulrich Diez Nov 02 '21 at 23:54