Fabrique

A build language for complex systems

 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
fabrique::ast::Parser Class Reference

Parses Fabrique files as driven by flex/byacc. More...

#include <Parser.h>

Public Member Functions

 Parser (TypeContext &, plugin::Registry &, plugin::Loader &, std::string srcroot)
 
const Type & ParseDefinitions (const std::vector< std::string > &defs)
 Parse Fabrique fragments defined at, e.g., the command line.
 
std::unique_ptr< Scope > ParseFile (std::istream &input, const Type &arguments, std::string name="", StringMap< std::string > builtins=StringMap< std::string >(), SourceRange openedFrom=SourceRange::None())
 Parse Fabrique input (usually a file) into a Scope.
 
const UniqPtrVec< ErrorReport > & errors () const
 Errors encountered during parsing.
 
const std::vector< std::string > & files () const
 Input files encountered during parsing.
 
Scope & EnterScope (const std::string &name, const Type &argumentsType, SourceRange src=SourceRange::None())
 Enter an AST Scope. More...
 
Scope & EnterScope (const std::string &name)
 A convenience wrapper around EnterScope with no 'args' type.
 
Scope & EnterScope (Scope &&s)
 Take an AST Scope and push it on the stack.
 
const Type & getType (const std::string &name, const SourceRange &begin, const SourceRange &end, const PtrVec< Type > &params=PtrVec< Type >())
 Find or create a Type.
 
const Type & getType (UniqPtr< Identifier > &&, UniqPtr< const PtrVec< Type >> &&params=nullptr)
 
const FunctionType & FnType (const PtrVec< Type > &inputs, const Type &output, SourceRange)
 
const StructureType * StructType (UniqPtr< UniqPtrVec< Identifier >> &fields, SourceRange)
 
Action * DefineAction (UniqPtr< UniqPtrVec< Argument >> &args, const SourceRange &, UniqPtr< UniqPtrVec< Parameter >> &&params=nullptr)
 Define a build Action.
 
Argument * Arg (UniqPtr< Expression > &value, UniqPtr< Identifier > &&=nullptr)
 Parse an Argument to a Function, build Action, etc.
 
BinaryOperation * BinaryOp (BinaryOperation::Operator, UniqPtr< Expression > &, UniqPtr< Expression > &)
 Create a BinaryOperation (+, ::, ...).
 
Call * CreateCall (UniqPtr< Expression > &, UniqPtr< UniqPtrVec< Argument >> &, const SourceRange &end)
 A call to an Action or Function.
 
CompoundExpression * CompoundExpr (UniqPtr< Expression > &result, SourceRange beg=SourceRange::None(), SourceRange end=SourceRange::None())
 An expression that can (optionally) include intermediate values.
 
FieldAccess * FieldAccess (UniqPtr< Expression > &structure, UniqPtr< Identifier > &field)
 An expression that indirects into a structure.
 
FieldQuery * FieldQuery (UniqPtr< Expression > &structure, UniqPtr< Identifier > &field, UniqPtr< Expression > &defaultValue, SourceRange)
 A test to see if a structure contains a field.
 
Filename * File (UniqPtr< Expression > &name, const SourceRange &src, UniqPtr< UniqPtrVec< Argument >> &&arguments=nullptr)
 A Filename that is part of the build DAG.
 
FileList * Files (const SourceRange &, UniqPtr< UniqPtrVec< Filename >> &, UniqPtr< UniqPtrVec< Argument >> &&args=nullptr)
 Create a list of files, which may have shared arguments. More...
 
ForeachExpr * Foreach (UniqPtr< Mapping > &, UniqPtr< Expression > &body, const SourceRange &start)
 An expression for mapping list elements into another list: foreach x in some_list: x + 1.
 
Function * DefineFunction (const SourceRange &begin, UniqPtr< UniqPtrVec< Parameter >> &params, UniqPtr< Expression > &body, const Type *ty=nullptr)
 
Identifier * Id (UniqPtr< Token > &&)
 An untyped ast::Identifier: just a name.
 
Identifier * Id (UniqPtr< Identifier > &&untyped, const Type *)
 A typed ast::Identifier.
 
Import * ImportModule (UniqPtr< StringLiteral > &name, UniqPtrVec< Argument > &arguments, SourceRange)
 An expression that imports a Fabrique module.
 
Conditional * IfElse (const SourceRange &ifLocation, UniqPtr< Expression > &condition, UniqPtr< Expression > &thenResult, UniqPtr< Expression > &elseResult)
 A conditional if-then-else expression (not a statement, an expression). More...
 
List * ListOf (UniqPtrVec< Expression > &, const SourceRange &)
 Define a List of expressions.
 
Mapping * Map (UniqPtr< Expression > &source, UniqPtr< Identifier > &target)
 Define a mapping from a sequence to a name.
 
SomeValue * Some (UniqPtr< Expression > &, SourceRange)
 Create a SomeValue (populated maybe object).
 
StructInstantiation * StructInstantiation (SourceRange)
 Turn the current scope into a structure instantiation.
 
BoolLiteral * True ()
 
BoolLiteral * False ()
 
IntLiteral * ParseInt (int)
 
StringLiteral * ParseString (UniqPtr< Token > &&)
 
Parameter * Param (UniqPtr< Identifier > &&name, UniqPtr< Expression > &&defaultValue=nullptr)
 Parse a function Parameter.
 
SymbolReference * Reference (UniqPtr< Identifier > &&)
 Reference a Value in scope.
 
SymbolReference * Reference (UniqPtr< class FieldAccess > &&)
 
DebugTracePoint * TracePoint (UniqPtr< Expression > &, SourceRange)
 Create a DebugTracePoint.
 
UnaryOperation * UnaryOp (UnaryOperation::Operator, const SourceRange &operatorLocation, UniqPtr< Expression > &)
 Create a UnaryOperation (currently just 'not').
 
bool DefineValue (UniqPtr< Identifier > &, UniqPtr< Expression > &, bool builtin=false)
 Define a Value in the current scope.
 
bool DefineValue (UniqPtr< Expression > &)
 Define an unnamed Value in the current scope.
 

Static Public Member Functions

static Token * ParseToken (YYSTYPE &)
 
static bool Set (YYSTYPE &, Node *)
 

Detailed Description

Parses Fabrique files as driven by flex/byacc.

Definition at line 61 of file Parser.h.

Member Function Documentation

Scope & Parser::EnterScope ( const std::string &  name,
const Type &  argumentsType,
SourceRange  src = SourceRange::None() 
)

Enter an AST Scope.

Should be called before parsing anything that belongs in the scope, e.g. parameters:

[EnterScope] function (x:int [Parameter]) { ... } [ExitScope]

Parameters
namea name used to describe the scope (for debugging)
argumentsTypethe type of the arguments (if any) being passed into the scope: either a StructureType or else TypeContext::nilType()
srcthe entire extent of the scope in source

Definition at line 183 of file Parser.cc.

References fabrique::Bytestream::Debug().

FileList * Parser::Files ( const SourceRange &  begin,
UniqPtr< UniqPtrVec< Filename >> &  files,
UniqPtr< UniqPtrVec< Argument >> &&  args = nullptr 
)

Create a list of files, which may have shared arguments.

Definition at line 479 of file Parser.cc.

Conditional * Parser::IfElse ( const SourceRange &  ifLocation,
UniqPtr< Expression > &  condition,
UniqPtr< Expression > &  thenResult,
UniqPtr< Expression > &  elseResult 
)

A conditional if-then-else expression (not a statement, an expression).

The expression (if condition foo else bar) evaluates to either foo or bar, depending on condition. It can also be writen as:

if (condition) foo else bar

Definition at line 679 of file Parser.cc.

References fabrique::SourceRange::Over().


The documentation for this class was generated from the following files: