From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How does Ada.Text_IO.Enumeration_IO work?
Date: Sat, 5 Nov 2011 10:32:35 +0100
Date: 2011-11-05T10:32:35+01:00 [thread overview]
Message-ID: <16pu39ybbo1e0$.1iiitzyoxl0h4$.dlg@40tude.net> (raw)
In-Reply-To: ee2c351c-8fee-4e58-aaf3-1cfffd4dd311@p16g2000yqd.googlegroups.com
On Fri, 4 Nov 2011 16:31:33 -0700 (PDT), Adam Beneschan wrote:
> On Nov 4, 3:46�pm, Jerry <lancebo...@qwest.net> wrote:
>
>>> 'Cuz the rules say so. �A.10.6(5) is the important one here: "Next,
>>> characters are input only so long as the sequence input is an initial
>>> sequence of an identifier or of a character literal (in particular,
>>> input ceases when a line terminator is encountered). The character or
>>> line terminator that causes input to cease remains available for
>>> subsequent input." �A.10.6(10): "The exception Data_Error is
>>> propagated by a Get procedure if the sequence finally input is not a
>>> lexical element corresponding to the type, in particular if no
>>> characters were input ...". �That's the case when your input (skipping
>>> leading blanks) starts with an invalid character like a comma. �Since
>>> the comma can't be the first character of an enumeration literal, the
>>> comma "remains available for subsequent input", and thus "no
>>> characters are input" and Data_Error is raised.
>>
>> Thanks, Adam. I believe that the clue for me is that "remains
>> available for subsequent input" means that it is available only to non-
>> enumeration input, characters excepted.
>
> I'm not sure what you mean by this. If the first character in the
> input (other than space) cannot be the start of an enumeration
> literal, the input will stop right there; and that character remains
> available in the input. If you then try to perform input using
> Enumeration_IO (without any other input routines in between), that
> same character is "available" in the input but causes Enumeration_IO
> to fail again for the same reason. Perhaps there's some confusion
> about what the RM means by "available". "The character remains
> available for subsequent input" means that *any* input routine will
> see that character first (and could raise an exception if that
> character is not legal). It doesn't mean that the input routine will
> succeed. But you could suck the character up with Text_IO.Get (to get
> one character), and then the character isn't available for input any
> more. I hope this doesn't confuse you more, but I couldn't tell from
> your comment whether things were clear to you; and if not, I was
> hoping to try to make it clearer.
For what it is worth. Any scanner when detects an error has only two
options:
1. Consume input and then raise an exception
2. Leave input as is and raise
As a side note, it is unfortunate that Enumeration_IO uses the same
exception (Data_Error) in both cases. The behavior 1 means: input
recognized but illegal. The behavior 2 means: nothing there, repeat.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2011-11-05 9:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-03 8:52 How does Ada.Text_IO.Enumeration_IO work? Jerry
2011-11-03 9:27 ` AdaMagica
2011-11-03 10:18 ` Jerry
2011-11-03 14:52 ` Adam Beneschan
2011-11-04 22:46 ` Jerry
2011-11-04 23:31 ` Adam Beneschan
2011-11-05 9:32 ` Dmitry A. Kazakov [this message]
2011-11-06 22:42 ` Jerry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox