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 TypeParseDefinitions (const std::vector< std::string > &defs)
 Parse Fabrique fragments defined at, e.g., the command line.
 
std::unique_ptr< ScopeParseFile (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.
 
ScopeEnterScope (const std::string &name, const Type &argumentsType, SourceRange src=SourceRange::None())
 Enter an AST Scope. More...
 
ScopeEnterScope (const std::string &name)
 A convenience wrapper around EnterScope with no 'args' type.
 
ScopeEnterScope (Scope &&s)
 Take an AST Scope and push it on the stack.
 
const TypegetType (const std::string &name, const SourceRange &begin, const SourceRange &end, const PtrVec< Type > &params=PtrVec< Type >())
 Find or create a Type.
 
const TypegetType (UniqPtr< Identifier > &&, UniqPtr< const PtrVec< Type >> &&params=nullptr)
 
const FunctionTypeFnType (const PtrVec< Type > &inputs, const Type &output, SourceRange)
 
const StructureTypeStructType (UniqPtr< UniqPtrVec< Identifier >> &fields, SourceRange)
 
ActionDefineAction (UniqPtr< UniqPtrVec< Argument >> &args, const SourceRange &, UniqPtr< UniqPtrVec< Parameter >> &&params=nullptr)
 Define a build Action.
 
ArgumentArg (UniqPtr< Expression > &value, UniqPtr< Identifier > &&=nullptr)
 Parse an Argument to a Function, build Action, etc.
 
BinaryOperationBinaryOp (BinaryOperation::Operator, UniqPtr< Expression > &, UniqPtr< Expression > &)
 Create a BinaryOperation (+, ::, ...).
 
CallCreateCall (UniqPtr< Expression > &, UniqPtr< UniqPtrVec< Argument >> &, const SourceRange &end)
 A call to an Action or Function.
 
CompoundExpressionCompoundExpr (UniqPtr< Expression > &result, SourceRange beg=SourceRange::None(), SourceRange end=SourceRange::None())
 An expression that can (optionally) include intermediate values.
 
FieldAccessFieldAccess (UniqPtr< Expression > &structure, UniqPtr< Identifier > &field)
 An expression that indirects into a structure.
 
FieldQueryFieldQuery (UniqPtr< Expression > &structure, UniqPtr< Identifier > &field, UniqPtr< Expression > &defaultValue, SourceRange)
 A test to see if a structure contains a field.
 
FilenameFile (UniqPtr< Expression > &name, const SourceRange &src, UniqPtr< UniqPtrVec< Argument >> &&arguments=nullptr)
 A Filename that is part of the build DAG.
 
FileListFiles (const SourceRange &, UniqPtr< UniqPtrVec< Filename >> &, UniqPtr< UniqPtrVec< Argument >> &&args=nullptr)
 Create a list of files, which may have shared arguments. More...
 
ForeachExprForeach (UniqPtr< Mapping > &, UniqPtr< Expression > &body, const SourceRange &start)
 An expression for mapping list elements into another list: foreach x in some_list: x + 1.
 
FunctionDefineFunction (const SourceRange &begin, UniqPtr< UniqPtrVec< Parameter >> &params, UniqPtr< Expression > &body, const Type *ty=nullptr)
 
IdentifierId (UniqPtr< Token > &&)
 An untyped ast::Identifier: just a name.
 
IdentifierId (UniqPtr< Identifier > &&untyped, const Type *)
 A typed ast::Identifier.
 
ImportImportModule (UniqPtr< StringLiteral > &name, UniqPtrVec< Argument > &arguments, SourceRange)
 An expression that imports a Fabrique module.
 
ConditionalIfElse (const SourceRange &ifLocation, UniqPtr< Expression > &condition, UniqPtr< Expression > &thenResult, UniqPtr< Expression > &elseResult)
 A conditional if-then-else expression (not a statement, an expression). More...
 
ListListOf (UniqPtrVec< Expression > &, const SourceRange &)
 Define a List of expressions.
 
MappingMap (UniqPtr< Expression > &source, UniqPtr< Identifier > &target)
 Define a mapping from a sequence to a name.
 
SomeValueSome (UniqPtr< Expression > &, SourceRange)
 Create a SomeValue (populated maybe object).
 
StructInstantiationStructInstantiation (SourceRange)
 Turn the current scope into a structure instantiation.
 
BoolLiteralTrue ()
 
BoolLiteralFalse ()
 
IntLiteralParseInt (int)
 
StringLiteralParseString (UniqPtr< Token > &&)
 
ParameterParam (UniqPtr< Identifier > &&name, UniqPtr< Expression > &&defaultValue=nullptr)
 Parse a function Parameter.
 
SymbolReferenceReference (UniqPtr< Identifier > &&)
 Reference a Value in scope.
 
SymbolReferenceReference (UniqPtr< class FieldAccess > &&)
 
DebugTracePointTracePoint (UniqPtr< Expression > &, SourceRange)
 Create a DebugTracePoint.
 
UnaryOperationUnaryOp (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 TokenParseToken (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: