Skip to content

Commit

Permalink
Feature #6: support for custom yylineno variable type
Browse files Browse the repository at this point in the history
- update parser to recognize %yydfa code block,
- handle %option name=value with a value as a string,
- update template expander for %yydfa and yylinenotype variable,
- rebuild the templates by using the generator
  • Loading branch information
stcarrez committed Feb 11, 2024
1 parent b88a36c commit c530fa5
Show file tree
Hide file tree
Showing 8 changed files with 950 additions and 874 deletions.
6 changes: 5 additions & 1 deletion src/ascan.l
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ DOT "."
UNAME {NAME}({DOT}{NAME})+

SCNAME {NAME}
OPTVAR {NAME}={NUM}
OPTVAR {NAME}=({NUM}|{NAME})

ESCSEQ \\([^\n]|[0-9]{1,3})

Expand All @@ -75,6 +75,10 @@ ESCSEQ \\([^\n]|[0-9]{1,3})

{WS} { return WHITESPACE; }
{OPTVAR} { nmstr := vstr(yytext(1..YYLength)); return OPTVAR; }
^%yydfa{WS}?"{"{WS}? {
Open_Code_Block (Template_Manager.Get_Filename (Template_Manager.YYDFA_CODE));
ENTER(CODEBLOCK_MATCH_BRACE);
}
^%yytype{WS}?"{"{WS}? {
Open_Code_Block (Template_Manager.Get_Filename (Template_Manager.YYTYPE_CODE));
ENTER(CODEBLOCK_MATCH_BRACE);
Expand Down
2 changes: 1 addition & 1 deletion src/main_body.adb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ package body Main_Body is
-- Print aflex usage.
procedure Usage is
begin
Put_Line (Standard_Error, "aflex version 1.6");
Put_Line (Standard_Error, "aflex version 1.7");
Put_Line (Standard_Error, "");
Put_Line
(Standard_Error,
Expand Down
13 changes: 13 additions & 0 deletions src/misc.adb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ package body Misc is
Lex_Filename : Vstring;
YYDecl_Name : Vstring;
YYVar_Name : Vstring;
YYLineno_Type_Name : Vstring;

procedure Action_Out is
Buf : Vstring;
Expand Down Expand Up @@ -340,6 +341,8 @@ package body Misc is
if Pos > 0 then
if Option (Option'First .. Pos) = "bufsize=" then
Misc_Defs.YYBuf_Size := Natural'Value (Option (Pos + 1 .. Option'Last));
elsif Option (Option'First .. Pos) = "yylinenotype=" then
YYLineno_Type_Name := Vstr (Option (Pos + 1 .. Option'Last));
else
Synerr ("variable option '" & Option & "' is not recognized");
end if;
Expand Down Expand Up @@ -440,6 +443,16 @@ package body Misc is
end if;
end Get_YYVar_Name;

function Get_YYLineno_Type_Name return String is
Name : constant String := Str (YYLineno_Type_Name);
begin
if Name'Length = 0 then
return "Natural";
else
return Name;
end if;
end Get_YYLineno_Type_Name;

-- basename - find the basename of a file
function Package_Name return String is
Name : String := Str (Basename);
Expand Down
1 change: 1 addition & 0 deletions src/misc.ads
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ package Misc is
function Get_YYLex_Declaration return String;
function Get_YYLex_Name return String;
function Get_YYVar_Name return String;
function Get_YYLineno_Type_Name return String;
end Misc;
1,073 changes: 551 additions & 522 deletions src/scanner.adb

Large diffs are not rendered by default.

706 changes: 357 additions & 349 deletions src/template_manager-templates.ads

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/template_manager.adb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ package body Template_Manager is
Has_Code : array (Code_Filename) of Boolean := (others => False);

YYTYPE_CODE_FILENAME : constant String := "yytype.miq";
YYDFA_CODE_FILENAME : constant String := "yydfa.miq";
YYINIT_CODE_FILENAME : constant String := "yyinit.miq";
YYACTION_CODE_FILENAME : constant String := "yyaction.miq";
YYWRAP_CODE_FILENAME : constant String := "yywrap.miq";
Expand All @@ -54,6 +55,9 @@ package body Template_Manager is
when YYTYPE_CODE =>
return YYTYPE_CODE_FILENAME;

when YYDFA_CODE =>
return YYDFA_CODE_FILENAME;

when YYINIT_CODE =>
return YYINIT_CODE_FILENAME;

Expand Down Expand Up @@ -122,6 +126,12 @@ package body Template_Manager is
Text_IO.Put (Outfile, Bufsize (Bufsize'First + 1 .. Bufsize'Last));
Start := Pos + 12;
end;

elsif Line (Pos .. Pos + 14) = "${YYLINENOTYPE}" then
Text_IO.Put (Outfile, Line (Start .. Pos - 1));
Text_IO.Put (Outfile, Misc.Get_YYLineno_Type_Name);
Start := Pos + 15;

else
Text_IO.Put_Line (Outfile, Line (Start .. Line'Last));
exit;
Expand Down Expand Up @@ -165,6 +175,7 @@ package body Template_Manager is
S_IF_YYWRAP_CODE,
S_IF_YYACTION,
S_IF_YYTYPE,
S_IF_YYDFA,
S_IF_REENTRANT,
S_IF_MINIMALIST_WITH,
S_IF_UNPUT);
Expand Down Expand Up @@ -241,6 +252,8 @@ package body Template_Manager is
Push_Condition (S_IF_YYACTION);
elsif Line = "%if yytype" then
Push_Condition (S_IF_YYTYPE);
elsif Line = "%if yydfa" then
Push_Condition (S_IF_YYDFA);
elsif Line = "%if echo" then
Push_Condition (S_IF_ECHO);
elsif Line = "%if reentrant" then
Expand Down Expand Up @@ -273,6 +286,10 @@ package body Template_Manager is
if Is_Visible and Parent_Visible then
Include_File (Outfile, YYTYPE_CODE_FILENAME);
end if;
elsif Line = "%yydfa" then
if Is_Visible and Parent_Visible then
Include_File (Outfile, YYDFA_CODE_FILENAME);
end if;
elsif Line = "%yyaction" then
if Is_Visible and Parent_Visible then
Include_File (Outfile, YYACTION_CODE_FILENAME);
Expand Down Expand Up @@ -306,6 +323,7 @@ package body Template_Manager is
or else (Current = S_IF_YYWRAP_CODE and then Has_Code (YYWRAP_CODE))
or else (Current = S_IF_YYACTION and then Has_Code (YYACTION_CODE))
or else (Current = S_IF_YYTYPE and then Has_Code (YYTYPE_CODE))
or else (Current = S_IF_YYDFA and then Has_Code (YYDFA_CODE))
or else (Current = S_IF_REENTRANT and then Reentrant)
or else (Current = S_IF_ECHO and then not Spprdflt)
or else (Current = S_IF_MINIMALIST_WITH and then Minimalist_With)
Expand Down Expand Up @@ -383,6 +401,9 @@ package body Template_Manager is
if Ada.Directories.Exists (YYTYPE_CODE_FILENAME) then
Ada.Directories.Delete_File (YYTYPE_CODE_FILENAME);
end if;
if Ada.Directories.Exists (YYDFA_CODE_FILENAME) then
Ada.Directories.Delete_File (YYDFA_CODE_FILENAME);
end if;
if Ada.Directories.Exists (YYINIT_CODE_FILENAME) then
Ada.Directories.Delete_File (YYINIT_CODE_FILENAME);
end if;
Expand Down
2 changes: 1 addition & 1 deletion src/template_manager.ads
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ package Template_Manager is
type Content_Array is array (Positive range <>) of access constant String;
type Content_Access is access constant Content_Array;

type Code_Filename is (YYTYPE_CODE, YYINIT_CODE, YYACTION_CODE, YYWRAP_CODE);
type Code_Filename is (YYTYPE_CODE, YYDFA_CODE, YYINIT_CODE, YYACTION_CODE, YYWRAP_CODE);

function Get_Filename (Code : in Code_Filename) return String;

Expand Down

0 comments on commit c530fa5

Please sign in to comment.