Module:Rational: Difference between revisions
m Code reorganised |
mNo edit summary |
||
Line 328: | Line 328: | ||
function p.parse(unparsed) | function p.parse(unparsed) | ||
-- rational form | -- rational form | ||
local sign, n, _m, m = unparsed:match('(%-?)%s*(%d+)%s*(/%s*(%d+))') | local sign, n, _m, m = unparsed:match('^%s*(%-?)%s*(%d+)%s*(/%s*(%d+))%s*$') | ||
if n == nil then | if n == nil then | ||
-- integer form | -- integer form | ||
sign, n = unparsed:match('(%-?)%s*(%d+)') | sign, n = unparsed:match('^%s*(%-?)%s*(%d+)%s*$') | ||
if n == nil then | if n == nil then | ||
-- parsing failure | -- parsing failure |