dlang-community / SDLang-D

An SDLang (Simple Declarative Language) library for D

Home Page:http://sdlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Outputs certain floating point numbers in unsupported scientific notation

MaksimZh opened this issue · comments

Scientific notation of floating point numbers is used for output but not recognized on input.

Consider the following program:

import std.stdio;
import sdlang;

void main()
{
    Tag root = parseSource("foo 420000000000000000000f");
    string output = root.toSDLDocument();
    writeln(output);
    Tag root2 = parseSource(output);
}

The output is

foo 4.200000014e+20F

sdlang.exception.ParseException@../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/lexer.d(177): (1:16): Error: Invalid floating point suffix.
----------------
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/lexer.d:177 void sdlang.lexer.Lexer.error(sdlang.util.Location, immutable(char)[]) [0x522840]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/lexer.d:171 void sdlang.lexer.Lexer.error(immutable(char)[]) [0x5227ba]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/lexer.d:927 void sdlang.lexer.Lexer.lexFloatingPoint(immutable(char)[]) [0x52579e]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/lexer.d:851 void sdlang.lexer.Lexer.lexNumeric(sdlang.lexer.Lexer.LookaheadTokenInfo) [0x5251f3]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/lexer.d:441 void sdlang.lexer.Lexer.popFront() [0x5233dc]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/parser.d:378 sdlang.parser.PullParser.IDFull sdlang.parser.PullParser.parseIDFull() [0x52a287]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/parser.d:347 void sdlang.parser.PullParser.parseTag() [0x52a030]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/parser.d:315 void sdlang.parser.PullParser.parseTags() [0x529f4f]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/parser.d:279 void sdlang.parser.PullParser.parseRoot() [0x529d45]
../../.dub/packages/sdlang-d-0.10.0/sdlang-d/src/sdlang/parser.d:265 void sdlang.parser.PullParser.visit(libInputVisitor.InputVisitor!(sdlang.parser.PullParser, taggedalgebraic.TaggedAlgebraic!(sdlang.parser.ParserEventUnion).TaggedAlgebraic).InputVisitor) [0x529cdb]
../../.dub/packages/libinputvisitor-1.2.2/libinputvisitor/libInputVisitor.d:63 void libInputVisitor.InputVisitor!(sdlang.parser.PullParser, taggedalgebraic.TaggedAlgebraic!(sdlang.parser.ParserEventUnion).TaggedAlgebraic).InputVisitor.run() [0x52ad42]
??:? void core.thread.Fiber.run() [0x56f5a1]
??:? fiber_entryPoint [0x56f48b]
??:? [0xffffffff]
Program exited with code 1

Ouch, yea,that definitely needs fixed.

The spec doesn't permit scientific notation, which makes this a bug in outputting SDLang. But support for scientific notation (maybe even hex float literals) would be nice in a new version of the spec, so I'll open tickets for that.

I'm also going to double-check that the original Java SDL library actually does disallows scientific notation according to the documentaion. If by chance it does accept it, that would give me sufficient justification to simply permit them in SDLang-D as well, without holding it back for a spec v2.

Consistent with the documentation, the original Java implementation rejects SDLang that contains scientific notation. So SDLang-D needs to reject it too, and stop outputting it. This is now fixed in SDLang-D v0.10.1