Abbreviations, simple: Difference between revisions
Ada: Simplify using Find_Token
(Ada version) |
(Ada: Simplify using Find_Token) |
||
Line 617:
with Ada.Containers.Vectors;
with Ada.Strings.Fixed;
with Ada.Strings.Maps.Constants;
with Ada.Strings.Unbounded;
with Ada.
procedure Abbreviations_Simple is
Line 624 ⟶ 625:
use Ada.Strings.Unbounded;
subtype Ustring is Unbounded_String;
type Word_Entry is record
Line 631:
end record;
package
is new Ada.Containers.Vectors (Index_Type => Positive,
Element_Type => Word_Entry);
Commands : Command_Vectors.Vector;
Last_Was_Word : Boolean := False;
procedure Append (Word_List : String) is
▲ Word : Ustring;
is (Fixed.Count (Item, Maps.Constants.Letter_Set) /= 0);
procedure
then Length (Word)▼
else Natural'Value (To_String (Count)));▼
begin
if
if Last_Was_Word then
Last_Word := To_Unbounded_String (Token);
else -- Token is expected to be decimal
Commands.Append ((Word => Last_Word,
end if;
end
Token_First : Positive := Word_List'First;
Token_Last : Natural;
begin
Fixed.Find_Token (Word_List, Maps.Constants.Alphanumeric_Set,
exit when Token_Last =
▲ end case;
▲ Append (Word, Char);
Process (Word_List
Token_First := Token_Last
▲ State := Idle;
end loop;
▲ State := Idle;
end Append;
Line 718 ⟶ 689:
end if;
for Candidate of
declare
Upper_Cand : constant String := To_Upper (To_String (Candidate.Word));
Line 743 ⟶ 714:
procedure Put_Match (To : String) is
use Ada.
begin
Put ("Match to '"); Put (To);
Line 761 ⟶ 732:
A ("2 save set shift 2 si sort sos stack 3 status 4 top transfer 3 type 1 up 1");
Put_Match ("riG");
Put_Match ("rePEAT");
Put_Match ("copies");
Line 775 ⟶ 747:
{{out}}
<pre>
Match to 'riG' is 'RIGHT'
Match to 'rePEAT' is 'REPEAT'
Match to 'copies' is '*error*'
|