Example #1
0
 protected bool Equals(FunctionNode other)
 {
     return base.Equals(other)
            && string.Equals(Name, other.Name)
            && IsPure.Equals(other.IsPure)
            && Equals(ReturnTypeSignature, other.ReturnTypeSignature);
 }
Example #2
0
        /// <summary>
        /// fun_def                                     = [ "pure" ] "fun" identifier [ ":" type ] fun_args "->" block
        /// </summary>
        private FunctionNode parseFunDef()
        {
            var node = new FunctionNode();
            node.IsPure = check(LexemType.Pure);

            if (!check(LexemType.Fun))
            {
                if (node.IsPure)
                    error(ParserMessages.FunctionDefExpected);
                else
                    return null;
            }

            node.Name = ensure(LexemType.Identifier, ParserMessages.FunctionIdentifierExpected).Value;
            if (check(LexemType.Colon))
                node.ReturnTypeSignature = ensure(parseType, ParserMessages.FunctionReturnExpected);

            node.Arguments = attempt(() => parseFunArgs(true)) ?? new List<FunctionArgument>();
            ensure(LexemType.Arrow, ParserMessages.SymbolExpected, "->");
            node.Body = ensure(parseBlock, ParserMessages.FunctionBodyExpected);

            return node;
        }