Represents an expression enclosed in parenthesis, but not a tuple.
Inheritance: NodeExpr
Esempio n. 1
0
 public void Visit(NodeEnclosed enc)
 {
     log.Error(enc.Span, "A string literal is not valid in this placement. Perhaps you meant to put it in a function?");
 }
Esempio n. 2
0
 public void Visit(NodeEnclosed enc)
 {
     throw new NotImplementedException();
 }
Esempio n. 3
0
 public void Visit(NodeEnclosed enc)
 {
     Write("'(' ");
     enc.expr.Accept(this);
     Write(" ')'");
 }
Esempio n. 4
0
 public void Visit(NodeEnclosed enc)
 {
     enc.expr.Accept(this);
 }
Esempio n. 5
0
        private NodeExpr ParsePrimaryExpr(bool isEnclosed, bool doError = true)
        {
            if (!HasCurrent)
            {
                log.Error(GetLastSpan(), "Expected a primary expression, got end of file.");
                return null;
            }

            NodeExpr result;
            switch (Current.type)
            {
                case IF:
                {
                    var @if = new NodeIf();
                    while (Check(IF))
                    {
                        Advance();
                        @if.conditions.Add(new NodeIf.IfBlock(ParseExpr(), ParseBlock()));
                        if (Check(EL))
                        {
                            if (!Check(IF))
                            {
                                @if.fail = ParseBlock();
                                break;
                            }
                            else Advance();
                        }
                    }
                    result = @if;
                } break;
                case LPAREN:
                    var lparen = Current;
                    Advance();
                    if (Check(RPAREN))
                    {
                        result = new NodeTuple(lparen, Current, new List<NodeExpr>());
                        Advance();
                        break;
                    }
                    bool trailingComma;
                    var exprs = ParseCommaList(out trailingComma);
                    if (exprs.Count == 1 && !trailingComma)
                    {
                        Expect(RPAREN, "Expected ')' to match opening '('.");
                        result = new NodeEnclosed(lparen, Last, exprs[0]);
                    }
                    else
                    {
                        Expect(RPAREN, "Expected ')' to close tuple.");
                        result = new NodeTuple(lparen, Last, exprs);
                    }
                    break;
                case TRUE: case FALSE:
                {
                    result = new NodeBool(Current);
                    Advance();
                } break;
                case INT:
                {
                    result = new NodeInt(Current);
                    Advance();
                } break;
                case STR:
                {
                    result = new NodeStr(Current);
                    Advance();
                } break;
                case IDENT:
                {
                    result = new NodeId(Current);
                    Advance();
                } break;
                default:
                    if (doError)
                    {
                        log.Error(GetLastSpan(), "Unexpected token '{0}' when parsing primary expression.", Current);
                        Advance();
                    }
                    return null;
            }

            // TODO(kai): check field index.
            while (Check(DOT))
            {
                var dot = Current;
                Advance();
                result = new NodeIndex(result, dot, new NodeId(ExpectIdent("Identifier expected for type index.")));
            }

            return ParseInvoke(result, isEnclosed);
        }