From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx18.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:32.0) Gecko/20100101 Thunderbird/32.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Weird error with Dynamic_Predicate References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Tue, 13 May 2014 04:59:22 UTC Organization: TeraNews.com Date: Mon, 12 May 2014 22:59:28 -0600 X-Received-Bytes: 3224 X-Received-Body-CRC: 883526555 Xref: news.eternal-september.org comp.lang.ada:19795 Date: 2014-05-12T22:59:28-06:00 List-Id: 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.