--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
with Objects; use Objects;
with Scripting.Expressions; use Scripting.Expressions;
with Scripting.Scripts; use Scripting.Scripts;
with Tokens.Scanners; use Tokens.Scanners;
package Scripting.Parsers is
-- A Parser parses input from a token scanner. Given a token scanner loaded
-- with an input stream, the parser will read tokens from the scanner and
-- create a corresponding abstract syntax tree.
type Parser is new Limited_Object with private;
type A_Parser is access all Parser'Class;
-- Creates and returns a new Parser.
function Create_Parser return A_Parser;
pragma Postcondition( Create_Parser'Result /= null );
-- Scans an expression or raises Parse_Exception if one is not found.
-- Parse_Exception will be raised if a parsing error occurs. Token_Exception
-- will be raised if an unrecognized token is encountered by the scanner.
function Expect_Expression( this : not null access Parser'Class;
scanner : not null A_Token_Scanner ) return A_Expression;
pragma Postcondition( Expect_Expression'Result /= null );
-- Scans an expression or returns null if one is not found. Parse_Exception
-- will be raised if a parsing error occurs. Token_Exception will be raised
-- if an unrecognized token is encountered by the scanner.
function Scan_Expression( this : not null access Parser'Class;
scanner : not null A_Token_Scanner ) return A_Expression;
-- Scans a script or returns null if one is not found. Parse_Exception will
-- be raised if a parsing error occurs. Token_Exception will be raised if an
-- unrecognized token is encounter by the scanner.
--
-- The grammar implemented by this function is:
-- script := <statement_list>
function Scan_Script( this : not null access Parser'Class;
scanner : not null A_Token_Scanner ) return A_Script;
-- Deletes the Parser.
procedure Delete( this : in out A_Parser );
pragma Postcondition( this = null );
private
type Parser is new Limited_Object with null record;
end Scripting.Parsers;