summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/packrat-lexer-combinators.adb190
-rw-r--r--src/packrat-lexer-combinators.ads187
-rw-r--r--src/packrat-lexer.ads30
-rw-r--r--src/packrat.ads7
4 files changed, 413 insertions, 1 deletions
diff --git a/src/packrat-lexer-combinators.adb b/src/packrat-lexer-combinators.adb
new file mode 100644
index 0000000..ef53bb1
--- /dev/null
+++ b/src/packrat-lexer-combinators.adb
@@ -0,0 +1,190 @@
+
+
+package body Packrat.Lexer.Combinators is
+
+
+ function Sequence
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Sequence;
+
+
+ function Count
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Count;
+
+
+ function Many
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Many;
+
+
+ function Many_Until
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Many_Until;
+
+
+
+
+
+ function Satisfy
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Satisfy;
+
+
+ function Satisfy_With
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Satisfy_With;
+
+
+ function Match
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Match;
+
+
+ function Match_With
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Match_With;
+
+
+ function Multimatch
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Multimatch;
+
+
+ function Take
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Take;
+
+
+ function Take_While
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Take_While;
+
+
+ function Take_Until
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Take_Until;
+
+
+
+
+
+ function Start_Of_Line
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Start_Of_Line;
+
+
+ function End_Of_Line
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end End_Of_Line;
+
+
+ function Start_Of_Input
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end Start_Of_Input;
+
+
+ function End_Of_Input
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result is
+ begin
+ return Failure;
+ end End_Of_Input;
+
+
+end Packrat.Lexer.Combinators;
+
+
diff --git a/src/packrat-lexer-combinators.ads b/src/packrat-lexer-combinators.ads
new file mode 100644
index 0000000..764887c
--- /dev/null
+++ b/src/packrat-lexer-combinators.ads
@@ -0,0 +1,187 @@
+
+
+generic
+package Packrat.Lexer.Combinators is
+
+
+ generic
+ Params : in Combinator_Array;
+ function Sequence
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ with function Param
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+ Number : in Positive;
+ function Count
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ with function Param
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+ Minimum : in Natural := 0;
+ function Many
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ with function Param
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+ with function Test
+ (Item : in Element)
+ return Boolean;
+ Minimum : in Natural := 0;
+ function Many_Until
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+
+
+
+ generic
+ with function Test
+ (Item : in Element)
+ return Boolean;
+ function Satisfy
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ with function Test
+ (Item : in Element)
+ return Boolean;
+ with function Change
+ (From : in Element)
+ return Element;
+ function Satisfy_With
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ Item : in Element;
+ function Match
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ Item : in Element;
+ with function Change
+ (From : in Element)
+ return Element;
+ function Match_With
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ Items : in Element_Array;
+ function Multimatch
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ Number : in Positive := 1;
+ function Take
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ with function Test
+ (Item : in Element)
+ return Boolean;
+ function Take_While
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ generic
+ with function Test
+ (Item : in Element)
+ return Boolean;
+ function Take_Until
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+
+
+
+ function Start_Of_Line
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ function End_Of_Line
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ function Start_Of_Input
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+ function End_Of_Input
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+
+end Packrat.Lexer.Combinators;
+
+
diff --git a/src/packrat-lexer.ads b/src/packrat-lexer.ads
new file mode 100644
index 0000000..611a407
--- /dev/null
+++ b/src/packrat-lexer.ads
@@ -0,0 +1,30 @@
+
+
+generic
+
+ type Label_Enum is (<>);
+ type Element is private;
+ type Element_Array is array (Positive range <>) of Element;
+
+ with package Gen_Tokens is new Tokens (Label_Enum, Element, Element_Array);
+
+package Packrat.Lexer is
+
+
+ type Combinator is access function
+ (Input : in Element_Array;
+ Start : in Positive;
+ Length : out Natural;
+ Value : out Element_Array)
+ return Result;
+
+
+ type Combinator_Array is array (Positive range <>) of Combinator;
+
+
+private
+
+
+end Packrat.Lexer;
+
+
diff --git a/src/packrat.ads b/src/packrat.ads
index a17e499..467c463 100644
--- a/src/packrat.ads
+++ b/src/packrat.ads
@@ -9,7 +9,11 @@ with
package Packrat is
- Parse_Error : exception;
+ type Result is (Failure, Partial, Success);
+
+
+ Parser_Error : exception;
+ Lexer_Error : exception;
@@ -103,6 +107,7 @@ package Packrat is
type Token is new Ada.Finalization.Controlled with private;
+ type Token_Array is array (Positive range <>) of Token;
function Create