summaryrefslogtreecommitdiff
path: root/src/packrat-lexer.ads
diff options
context:
space:
mode:
Diffstat (limited to 'src/packrat-lexer.ads')
-rw-r--r--src/packrat-lexer.ads129
1 files changed, 86 insertions, 43 deletions
diff --git a/src/packrat-lexer.ads b/src/packrat-lexer.ads
index 2d152bf..0cd5c78 100644
--- a/src/packrat-lexer.ads
+++ b/src/packrat-lexer.ads
@@ -2,7 +2,8 @@
private with
- Ada.Containers.Vectors;
+ Ada.Containers.Vectors,
+ Ada.Containers.Ordered_Sets;
generic
@@ -16,7 +17,7 @@ generic
package Packrat.Lexer is
- type Combinator_Result is new Ada.Finalization.Controlled with private;
+ type Combinator_Result is private;
type Combinator is access function
(Input : in Element_Array;
@@ -25,10 +26,6 @@ package Packrat.Lexer is
type Combinator_Array is array (Positive range <>) of Combinator;
- function "="
- (Left, Right : in Combinator_Result)
- return Boolean;
-
@@ -39,16 +36,19 @@ package Packrat.Lexer is
- type Lexer_Component is access procedure
+ type Component_Result is private;
+
+ type Component is access function
(Input : in Element_Array;
- Context : in out Lexer_Context);
+ Context : in out Lexer_Context)
+ return Component_Result;
- type Component_Array is array (Positive range <>) of Lexer_Component;
+ type Component_Array is array (Positive range <>) of Component;
- type Lexer_With_Input is access function
+ type With_Input is access function
return Element_Array;
@@ -60,9 +60,10 @@ package Packrat.Lexer is
(Input : in Element_Array;
Start : in Positive)
return Combinator_Result;
- procedure Stamp
+ function Stamp
(Input : in Element_Array;
- Context : in out Lexer_Context);
+ Context : in out Lexer_Context)
+ return Component_Result;
generic
Label : in Label_Enum;
@@ -70,9 +71,10 @@ package Packrat.Lexer is
(Input : in Element_Array;
Start : in Positive)
return Combinator_Result;
- procedure Ignore
+ function Ignore
(Input : in Element_Array;
- Context : in out Lexer_Context);
+ Context : in out Lexer_Context)
+ return Component_Result;
@@ -94,7 +96,7 @@ package Packrat.Lexer is
generic
Components : in Component_Array;
function Scan_With
- (Input : in Lexer_With_Input;
+ (Input : in With_Input;
Context : in out Lexer_Context)
return Gen_Tokens.Token_Array;
@@ -112,7 +114,7 @@ package Packrat.Lexer is
Pad_In : in Element;
Pad_Out : in Gen_Tokens.Token;
procedure Scan_Set_With
- (Input : in Lexer_With_Input;
+ (Input : in With_Input;
Context : in out Lexer_Context;
Output : out Gen_Tokens.Token_Array);
@@ -256,55 +258,96 @@ package Packrat.Lexer is
private
- type Element_Array_Access is access Element_Array;
+ package Token_Vectors is new Ada.Containers.Vectors
+ (Index_Type => Positive,
+ Element_Type => Gen_Tokens.Token,
+ "=" => Gen_Tokens."=");
+
+
+
+
+ type Element_Array_Access is access all Element_Array;
Empty_Array : Element_Array (1 .. 0);
- type Combinator_Result is new Ada.Finalization.Controlled with record
- Length : Natural;
+ package Label_Vectors is new Ada.Containers.Vectors
+ (Index_Type => Positive,
+ Element_Type => Label_Enum);
+
+
+
+
+ package Label_Sets is new Ada.Containers.Ordered_Sets
+ (Element_Type => Label_Enum);
+
+
+
+
+ type Combinator_Result is record
+ Finish : Natural;
Status : Result_Status;
- Value : Element_Array_Access;
end record;
- overriding procedure Initialize
- (This : in out Combinator_Result);
+ Empty_Fail : constant Combinator_Result :=
+ (Finish => 0,
+ Status => Failure);
- overriding procedure Adjust
- (This : in out Combinator_Result);
- overriding procedure Finalize
- (This : in out Combinator_Result);
- Empty_Fail : constant Combinator_Result :=
- (Ada.Finalization.Controlled with
- Length => 0,
- Status => Failure,
- Value => null);
+ type Component_Result is (Component_Failure, Component_Success);
- package Token_Vectors is new Ada.Containers.Vectors
- (Index_Type => Positive,
- Element_Type => Gen_Tokens.Token,
- "=" => Gen_Tokens."=");
type Lexer_Context is new Ada.Finalization.Controlled with record
- Result_So_Far : Token_Vectors.Vector;
- Position : Positive;
- Status : Result_Status;
- Pass_Forward : Element_Array_Access;
+ Result_So_Far : Token_Vectors.Vector;
+ Position : Positive;
+ Offset : Natural;
+ Status : Result_Status;
+ Pass_Forward : Element_Array_Access;
+ Empty_Labels : Label_Sets.Set;
+ Error_Labels : Label_Vectors.Vector;
+ Allow_Incomplete : Boolean;
end record;
+ overriding procedure Initialize
+ (This : in out Lexer_Context);
+
+ overriding procedure Adjust
+ (This : in out Lexer_Context);
+
+ overriding procedure Finalize
+ (This : in out Lexer_Context);
+
Empty_Context : constant Lexer_Context :=
(Ada.Finalization.Controlled with
- Result_So_Far => Token_Vectors.Empty_Vector,
- Position => 1,
- Status => Success,
- Pass_Forward => null);
+ Result_So_Far => Token_Vectors.Empty_Vector,
+ Position => 1,
+ Offset => 0,
+ Status => Success,
+ Pass_Forward => null,
+ Empty_Labels => Label_Sets.Empty_Set,
+ Error_Labels => Label_Vectors.Empty_Vector,
+ Allow_Incomplete => True);
+
+
+
+
+ type Input_Container is new Ada.Finalization.Limited_Controlled with record
+ Data : Element_Array_Access;
+ Dealloc : Boolean;
+ end record;
+
+ overriding procedure Finalize
+ (This : in out Input_Container);
+
+ function Pass_Input
+ (Passed, Continuing : in Element_Array_Access)
+ return Input_Container;
end Packrat.Lexer;