Discussion:
[e-lang] Patch to the lexer to accept "1e+1"
Thomas Leonard
2011-09-29 08:22:57 UTC
Permalink
JSON allows "1e+1" as well as "1e1":

http://www.json.org/

However, E's JSON parser rejects it:

? def surgeon := <elib:serial.deJSONKit>.makeSurgeon()
? surgeon.unserialize("1e+1")
# value: 10.0

new syntax error: Missing exponent
# 1e+1
# ^^

This patch fixes it:

http://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/a2bf52beff24defc63bd8fe5cf1f8cfe85547c23

Note: a side-effect is that it also allows this syntax in regular E
code. I assume that's not a problem?
--
Dr Thomas Leonard
IT Innovation Centre
Gamma House, Enterprise Road,
Southampton SO16 7NS, UK


tel: +44 23 8059 8866

mailto:***@it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk/
Kevin Reid
2011-09-29 11:50:15 UTC
Permalink
Post by Thomas Leonard
new syntax error: Missing exponent
# 1e+1
# ^^
http://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/a2bf52beff24defc63bd8fe5cf1f8cfe85547c23
Note: a side-effect is that it also allows this syntax in regular E
code. I assume that's not a problem?
Given that '-' is allowed I see no problem with '+'. I also see that C, for example, accepts a '+' in float syntax.

It is in general a good thing to improve the similarity of E's syntax for values such as strings (backslash escapes) and floats (exponent syntax) to the syntax used by many other programming languages, except where E deliberately is restrictive for robustness reasons ("make the programmer clarify what they meant").

Go ahead with this.
--
Kevin Reid <http://switchb.org/kpreid/>
Loading...