From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: Weird error with Dynamic_Predicate
Date: Mon, 12 May 2014 22:59:28 -0600
Date: 2014-05-12T22:59:28-06:00 [thread overview]
Message-ID: <KEhcv.16152$to2.7354@fx18.iad> (raw)
In-Reply-To: <e4d8e3db-99b6-49d4-85f3-839f178d4047@googlegroups.com>
On 12-May-14 13:47, mockturtle wrote:
> Any ideas?
-- Identifier:
Type Identifier is new String
with Dynamic_Predicate =>
Validate_Identifier_String( String(Identifier) )
or Validate_Qualified_Identifier_String( String(Identifier) );
-- Typecasting is desired so that the predicate doesn't depend on
-- the input checking the predicate and thereby infinite-looping.
-- ...
-- Ensures conformance of identifiers.
--
-- EBNF:
-- identifier ::= identifier_letter {[ "_" ] ( identifier_letter |
digit )}
-- identifier_letter ::= upper_case_letter | lower_case_letter
-- digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
Function Validate_Identifier_String ( Input : String ) return Boolean;
-- body
Function Validate_Identifier_String ( Input : String ) return
Boolean is
Use Ada.Characters.Handling;
Head : Character renames Input(Input'First);
Function Underscore_Alphanumeric(C : Character) return Boolean is
( C = '_' or else Is_Alphanumeric(C) );
Subtype Tail is Positive Range Input'First+1..Input'Last;
Begin
Return Result : Boolean := True do
-- Ensure that Input's first character is a letter.
-- (Implicit: that there is a first character.)
-- (Implicit: that there is a last character.)
Result:= Result
and then Input'Length in Positive
and then Is_Letter(Head);
-- All subsequent characters must be underscor or alphanumeric;
-- also, there can be no double underscore.
For Index in Tail loop
Exit when not Result;
declare
C : Character renames Input(Index);
begin
Result := Result and Underscore_Alphanumeric( C ) and
(if C = '_' then Input(Index-1) /= '_');
end;
end loop;
-- The last character cannot be an underscore.
Result:= Result and Input(Input'Last) /= '_';
End return;
End Validate_Identifier_String;
--------
Validate_Qualified_Identifier_String would take its input and, upon
detection of '.' pass the two substrings to Validate_Identifier_String
since both would have to be valid identifiers.
next prev parent reply other threads:[~2014-05-13 4:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-12 19:47 Weird error with Dynamic_Predicate mockturtle
2014-05-12 20:45 ` Peter Chapin
2014-05-12 20:52 ` mockturtle
2014-05-12 21:01 ` Adam Beneschan
2014-05-12 22:17 ` Randy Brukardt
2014-05-13 4:40 ` Simon Wright
2014-05-13 20:50 ` Simon Wright
2014-05-13 4:59 ` Shark8 [this message]
2014-05-13 12:46 ` G.B.
2014-05-13 17:04 ` Martin
2014-05-13 18:55 ` mockturtle
2014-05-13 21:39 ` Georg Bauhaus
2014-05-14 7:30 ` mockturtle
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox