Top Prev Next Up Down TEST
ExFi.adb
Example getting patterns from input file (default file ExFi.prop)
and publishing the syntax tree to standard output
001| with
Ada.Text_IO; use Ada.Text_IO;
002| with Ada.Command_Line;
003| with Y2018.Text.Core; use
Y2018.Text.Core;
004| with Y2018.Text.Core.Str; use
Y2018.Text.Core.Str;
005| with Ada.Command_Line;
006| with Y2018.Text.Core.CVarPack; use
Y2018.Text.Core.CVarPack;
007| with Y2018.Text.Jets; use
Y2018.Text.Jets;
008| with Y2018.Text.Jets.MatchPack;
009| with Y2018.Text.Jets.PatternPack;
010| --with DSECT;
011| procedure ExFi is
012| __arg:CVar;
013| __inFile : File_Type;
014| __patternvalue : CVar;
015| __sourcevalue : CVar;
016| __p:PatternPack.Pattern_AC:=new
PatternPack.Pattern;
017| __m : MatchPack.Match_TY;
018| __cp:PatternPack.Pattern_AC:=new
PatternPack.Pattern;
019| __nextPos : Integer:=0;
020| __Qmap:CList.map; -- used by
MatchPack.updClist
021| __this:Clist.Cursor; -- used by
MatchPack.updClist
022| __val:Celem; -- used by
MatchPack.updClist
023| begin
024| __if
Ada.Command_Line.Argument_Count = 0 then
025| _____arg:=Null_CVar &
"ExFi.prop";
026| __else
027| _____arg:=Null_CVar &
Ada.Command_Line.Argument(1);
028| __end if;
029| __declare
030| _____readFrom : String := "" &
arg;--"ExFi.prop";
031| __begin
032| _____Open (File => inFile,Mode
=> In_File,Name => readFrom);
033| __exception
034| _____when others =>
035| ________Put_Line
(Standard_Error,"Can not open file '" & readFrom & "'.");
036|
________Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
037| ________return;
038| __end;
039|
__PatternPack.compileU(cp,"^[\s]*(pattern)[\s]*=(.*)"c);
040| __while not End_Of_File(inFile)
loop
041| _____declare
042| ________line:CFix:= ""c &
Get_Line(inFile);
043| _____begin
044| ________if
PatternPack.matches(cp,1,nextPos,line,m) then
045| ___________declare
046|
______________r:I_A_ARRAY:=MatchPack.getMatch(m);
047|
______________com:CFix:=To_UC(subIA(line,r(1)));
048| ___________begin
049| ______________if com = "PATTERN"c
then
050| _________________Put_Line
(Standard_Output,"LINE " & line);
051|
_________________patternvalue:=Null_CVar &
stripC(subIA(line,r(2)));
052|
_________________PatternPack.compileM(p,To_CFix(patternvalue));
053|
_________________Qmap:=PatternPack.nodeClist(p);
054|
_________________this:=CList.First(Qmap);
055| _________________while
Clist.Has_Element(this) loop
056|
____________________val:=CList.Element(this);
057| ____________________Put_Line
(Standard_Output,CVarPack.To_String(val.s));
058|
____________________Clist.Next(this);
059| _________________end loop;
060| ______________end if;
061| ___________end;
062| ________elsif line'Length(1) >
1 and then line(1) = '>'c then
063| ___________Put_Line
(Standard_Output,"" & subC(line,2));
064| ________end if;
065| _____end;
066| __end loop; -- while not
End_Of_File(inFile)
067| __close(inFile);
068| end ExFi;
Input, ExFi.prop-file
> -- ExFi 1 --
pattern=^.*?(ABC)
pattern=.*[\d]A
pattern=N[\w]B
> == BOTTOM ==
Result
Running export LD_LIBRARY_PATH=lib;bin/exfi in
TEST directory.
-- ExFi 1 --
LINE pattern=^.*?(ABC)
== 0 REQ_BEGIN[1] right[2] circumflex=TRUE dollar=FALSE
left<NULL>
== 0 REQ_PALCAP[2] right<NULL> down[3] min=1 max=1
greedy=TRUE up<NULL> left[1]
== 1 REQ_UPDOWN[3] right[4] down<NULL> up[2]
left<NULL>
== 1 REQ_PERIOD[4] right[5] min=0 max=1 greedy=FALSE left[3]
== 1 REQ_PALCAP[5] right<NULL> down[6] min=1 max=1
greedy=TRUE up<NULL> left[4]
== 2 REQ_UPDOWN[6] right[7] down<NULL> up[5]
left<NULL>
== 2 REQ_CHAR[7] right[8] value=A min=1 max=1 greedy=TRUE
negative=FALSE left[6]
== 2 REQ_CHAR[8] right[9] value=B min=1 max=1 greedy=TRUE
negative=FALSE left[7]
== 2 REQ_CHAR[9] right<NULL> value=C min=1 max=1
greedy=TRUE negative=FALSE left[8]
LINE pattern=.*[\d]A
== 0 REQ_BEGIN[1] right[2] circumflex=FALSE dollar=FALSE
left<NULL>
== 0 REQ_PERIOD[2] right[3] min=0 max=1 greedy=FALSE left[1]
== 0 REQ_PALCAP[3] right<NULL> down[4] min=1 max=1
greedy=TRUE up<NULL> left[2]
== 1 REQ_UPDOWN[4] right[5] down<NULL> up[3]
left<NULL>
== 1 REQ_PERIOD[5] right[11] min=0 max=1 greedy=TRUE left[4]
== 1 REQ_CHAR[10] right<NULL> value=A min=1 max=1
greedy=TRUE negative=FALSE left[11]
== 1 REQ_CLASS[11] right[10] min=1 max=1 greedy=TRUE left[5]
REQ_CLASS[ 11].class_pos
______30 .. ______39
REQ_CLASS[ 11].class_neg
LINE pattern=N[\w]B
== 0 REQ_BEGIN[1] right[2] circumflex=FALSE dollar=FALSE
left<NULL>
== 0 REQ_PERIOD[2] right[3] min=0 max=1 greedy=FALSE left[1]
== 0 REQ_PALCAP[3] right<NULL> down[4] min=1 max=1
greedy=TRUE up<NULL> left[2]
== 1 REQ_UPDOWN[4] right[5] down<NULL> up[3]
left<NULL>
== 1 REQ_CHAR[5] right[11] value=N min=1 max=1 greedy=TRUE
negative=FALSE left[4]
== 1 REQ_CHAR[10] right<NULL> value=B min=1 max=1
greedy=TRUE negative=FALSE left[11]
== 1 REQ_CLASS[11] right[10] min=1 max=1 greedy=TRUE left[5]
REQ_CLASS[ 11].class_pos
______30 .. ______39
______41 .. ______5A
______5F .. ______5F
______61 .. ______7A
______AA .. ______AA
______B2 .. ______B3
______B5 .. ______B5
______B9 .. ______BA
______BC .. ______BE
______C0 .. ______D6
REQ_CLASS[ 11].class_neg
== BOTTOM ==