nixd
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
nixf::Parser Class Reference

#include <Parser.h>

Public Types

enum  ParserState { PS_Expr , PS_String , PS_IndString , PS_Path }
 

Public Member Functions

 Parser (std::string_view Src, std::vector< Diagnostic > &Diags)
 
std::shared_ptr< InterpolationparseInterpolation ()
 Parse interpolations.
 
std::shared_ptr< ExprparseExprPath ()
 Parse paths.
 
std::shared_ptr< InterpolatedPartsparseStringParts ()
 
std::shared_ptr< ExprStringparseString (bool IsIndented)
 
std::shared_ptr< ExprParenparseExprParen ()
 
std::shared_ptr< AttrNameparseAttrName ()
 
std::shared_ptr< AttrPathparseAttrPath ()
 
std::shared_ptr< BindingparseBinding ()
 
std::shared_ptr< InheritparseInherit ()
 
std::shared_ptr< BindsparseBinds ()
 
std::shared_ptr< ExprAttrsparseExprAttrs ()
 
std::shared_ptr< ExprparseExprSimple ()
 
std::shared_ptr< ExprparseExprSelect ()
 
std::shared_ptr< ExprparseExprApp (int Limit=INT_MAX)
 
std::shared_ptr< ExprListparseExprList ()
 
std::shared_ptr< FormalparseFormal ()
 
std::shared_ptr< FormalsparseFormals ()
 
std::shared_ptr< LambdaArgparseLambdaArg ()
 
std::shared_ptr< ExprLambdaparseExprLambda ()
 
std::shared_ptr< ExprparseExpr ()
 
std::shared_ptr< ExprparseExprOp ()
 Parse binary/unary operators.
 
std::shared_ptr< ExprIfparseExprIf ()
 
std::shared_ptr< ExprAssertparseExprAssert ()
 
std::shared_ptr< ExprLetparseExprLet ()
 
std::shared_ptr< ExprWithparseExprWith ()
 
std::shared_ptr< Exprparse ()
 Top-level parsing.
 

Detailed Description

Definition at line 31 of file src/Parse/Parser.h.

Member Enumeration Documentation

◆ ParserState

Enumerator
PS_Expr 
PS_String 
PS_IndString 
PS_Path 

Definition at line 33 of file src/Parse/Parser.h.

Constructor & Destructor Documentation

◆ Parser()

nixf::Parser::Parser ( std::string_view Src,
std::vector< Diagnostic > & Diags )
inline

Definition at line 153 of file src/Parse/Parser.h.

References PS_Expr.

Member Function Documentation

◆ parse()

std::shared_ptr< Expr > nixf::Parser::parse ( )

Top-level parsing.

Definition at line 43 of file ParseSupport.cpp.

References nixf::Token::kind().

Referenced by nixf::parse().

◆ parseAttrName()

std::shared_ptr< AttrName > Parser::parseAttrName ( )
attrname : ID
| string
| interpolation

Definition at line 6 of file ParseAttrs.cpp.

References nixf::Token::kind(), parseInterpolation(), and parseString().

Referenced by parseAttrPath(), and parseInherit().

◆ parseAttrPath()

std::shared_ptr< AttrPath > Parser::parseAttrPath ( )

◆ parseBinding()

std::shared_ptr< Binding > Parser::parseBinding ( )

◆ parseBinds()

std::shared_ptr< Binds > Parser::parseBinds ( )
binds : ( binding | inherit )*

Definition at line 160 of file ParseAttrs.cpp.

References nixf::Token::lCur(), parseBinding(), and parseInherit().

Referenced by parseExprAttrs(), and parseExprLet().

◆ parseExpr()

std::shared_ptr< Expr > Parser::parseExpr ( )

◆ parseExprApp()

std::shared_ptr< Expr > Parser::parseExprApp ( int Limit = INT_MAX)
expr_app : expr_app expr_select
| expr_select

Consume at most Limit number of expr_select as arguments e.g. Fn A1 A2 A3 with Limit = 2 will be parsed as ((Fn A1 A2) A3)

Definition at line 52 of file ParseExpr.cpp.

References nixf::LexerCursorRange::lCur(), and parseExprSelect().

◆ parseExprAssert()

std::shared_ptr< ExprAssert > Parser::parseExprAssert ( )

◆ parseExprAttrs()

std::shared_ptr< ExprAttrs > Parser::parseExprAttrs ( )

attrset_expr : REC? '{' binds '}'

Note: peek tok_kw_rec or tok_l_curly before calling this function.

Definition at line 193 of file ParseAttrs.cpp.

References nixf::Token::kind(), nixf::Token::lCur(), nixf::Sema::onExprAttrs(), parseBinds(), nixf::Token::range(), and nixf::tok::spelling().

Referenced by parseExprSimple().

◆ parseExprIf()

std::shared_ptr< ExprIf > Parser::parseExprIf ( )

◆ parseExprLambda()

std::shared_ptr< ExprLambda > Parser::parseExprLambda ( )
expr_lambda : lambda_arg ':' expr

Definition at line 132 of file ParseLambda.cpp.

References nixf::detail::diagNullExpr(), parseExpr(), and parseLambdaArg().

Referenced by parseExpr().

◆ parseExprLet()

std::shared_ptr< ExprLet > Parser::parseExprLet ( )
epxr_let : 'let' binds 'in' expr

Definition at line 246 of file ParseExpr.cpp.

References nixf::detail::diagNullExpr(), nixf::Token::kind(), nixf::Sema::onExprAttrs(), parseBinds(), parseExpr(), nixf::Node::range(), and nixf::Token::range().

Referenced by parseExpr().

◆ parseExprList()

std::shared_ptr< ExprList > Parser::parseExprList ( )
expr_list : '[' expr_select* ']'

Definition at line 81 of file ParseSimple.cpp.

References nixf::Token::kind(), nixf::Token::lCur(), parseExprSelect(), nixf::Token::range(), and nixf::tok::spelling().

Referenced by parseExprSimple().

◆ parseExprOp()

std::shared_ptr< Expr > nixf::Parser::parseExprOp ( )
inline

Parse binary/unary operators.

expr_op : '!' expr_op
| '-' expr_op
| expr_op BINARY_OP expr_op
| expr_app
%right ->
%left ||
%left &&
%nonassoc == !=
%nonassoc < > <= >=
%right //
%left NOT
%left + -
%left * /
%right ++
%nonassoc '?'
%nonassoc NEGATE

Definition at line 315 of file src/Parse/Parser.h.

Referenced by parseExpr().

◆ parseExprParen()

std::shared_ptr< ExprParen > Parser::parseExprParen ( )

◆ parseExprPath()

std::shared_ptr< Expr > Parser::parseExprPath ( )

Parse paths.

path : path_fragment (path_fragment)* path_end

The first token, path_fragment is lexed in PS_Expr context, then switch in "PS_Path" context. The ending token "path_end" shall be poped with context switching.

Definition at line 29 of file ParseStrings.cpp.

References nixf::Token::kind(), nixf::Token::lCur(), parseInterpolation(), PS_Path, nixf::Token::rCur(), and nixf::Token::view().

Referenced by parseExprSimple().

◆ parseExprSelect()

std::shared_ptr< Expr > Parser::parseExprSelect ( )
expr_select : expr_simple '.' attrpath
| expr_simple '.' attrpath 'or' expr_select
| expr_simple 'or' <-- special "apply", 'or' is argument
| expr_simple

Definition at line 6 of file ParseExpr.cpp.

References nixf::detail::diagNullExpr(), nixf::Fix::edit(), nixf::Diagnostic::fix(), nixf::Token::kind(), nixf::Node::lCur(), nixf::TextEdit::mkInsertion(), nixf::TextEdit::mkRemoval(), parseAttrPath(), parseExprSelect(), parseExprSimple(), nixf::Token::range(), and nixf::Token::rCur().

Referenced by parseExprApp(), parseExprList(), and parseExprSelect().

◆ parseExprSimple()

std::shared_ptr< Expr > Parser::parseExprSimple ( )
expr_simple : INT
| ID
| FLOAT
| string
| indented_string
| path
| spath
| hpath
| uri
| '(' expr ')'
| legacy_let
| attrset_expr
| list

Definition at line 107 of file ParseSimple.cpp.

References nixf::Fix::edit(), nixf::Diagnostic::fix(), nixf::Token::kind(), nixf::Token::lCur(), nixf::TextEdit::mkInsertion(), parseExprAttrs(), parseExprList(), parseExprParen(), parseExprPath(), parseString(), nixf::Token::range(), nixf::Token::rCur(), and nixf::Token::view().

Referenced by parseExprSelect().

◆ parseExprWith()

std::shared_ptr< ExprWith > Parser::parseExprWith ( )
expr_with : 'with' expr ';' expr

Definition at line 285 of file ParseExpr.cpp.

References nixf::detail::diagNullExpr(), nixf::Token::kind(), nixf::Diagnostic::note(), parseExpr(), nixf::Token::range(), and nixf::tok::spelling().

Referenced by parseExpr().

◆ parseFormal()

std::shared_ptr< Formal > Parser::parseFormal ( )
formal : ,? ID
| ,? ID '?' expr
| ,? ...

Definition at line 6 of file ParseLambda.cpp.

References nixf::detail::diagNullExpr(), nixf::Token::kind(), and parseExpr().

Referenced by parseFormals().

◆ parseFormals()

std::shared_ptr< Formals > Parser::parseFormals ( )

◆ parseInherit()

std::shared_ptr< Inherit > Parser::parseInherit ( )
inherit : 'inherit' '(' expr ')' inherited_attrs ';'
| 'inherit' inherited_attrs ';'
inherited_attrs: attrname*

Definition at line 103 of file ParseAttrs.cpp.

References nixf::detail::diagNullExpr(), nixf::Fix::edit(), nixf::Faded, nixf::Diagnostic::fix(), nixf::Token::kind(), nixf::Token::lCur(), nixf::TextEdit::mkRemoval(), nixf::Diagnostic::note(), parseAttrName(), parseExpr(), nixf::Token::range(), nixf::tok::spelling(), and nixf::PartialDiagnostic::tag().

Referenced by parseBinds().

◆ parseInterpolation()

std::shared_ptr< Interpolation > Parser::parseInterpolation ( )

Parse interpolations.

interpolation : "${" expr "}"

Definition at line 6 of file ParseStrings.cpp.

References nixf::detail::diagNullExpr(), nixf::Token::kind(), nixf::Token::lCur(), parseExpr(), PS_Expr, nixf::Token::range(), and nixf::tok::spelling().

Referenced by parseAttrName(), parseExprPath(), and parseStringParts().

◆ parseLambdaArg()

std::shared_ptr< LambdaArg > Parser::parseLambdaArg ( )

◆ parseString()

std::shared_ptr< ExprString > Parser::parseString ( bool IsIndented)
string : " string_part* "
| '' string_part* ''

Definition at line 88 of file ParseStrings.cpp.

References nixf::Token::kind(), nixf::Token::lCur(), parseStringParts(), PS_IndString, PS_String, nixf::Token::range(), and nixf::tok::spelling().

Referenced by parseAttrName(), and parseExprSimple().

◆ parseStringParts()

std::shared_ptr< InterpolatedParts > Parser::parseStringParts ( )
string_part : interpolation
| STRING_PART
| STRING_ESCAPE

Definition at line 58 of file ParseStrings.cpp.

References nixf::Token::kind(), nixf::Token::lCur(), and parseInterpolation().

Referenced by parseString().


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