Exemple #1
0
 private ErrorExpression Error() {
     var res = new ErrorExpression();
     res.SetLoc(_globalParent, GetStart(), GetEnd());
     return res;
 }
Exemple #2
0
        // primary: atom | attributeref | subscription | slicing | call 
        // atom:    identifier | literal | enclosure 
        // enclosure: 
        //      parenth_form | 
        //      list_display | 
        //      generator_expression | 
        //      dict_display | 
        //      string_conversion | 
        //      yield_atom 
        private Expression ParsePrimary() {
            Token t = PeekToken();
            Expression ret;
            switch (t.Kind) {
                case TokenKind.LeftParenthesis: // parenth_form, generator_expression, yield_atom
                    NextToken();
                    return FinishTupleOrGenExp();
                case TokenKind.LeftBracket:     // list_display
                    NextToken();
                    return FinishListValue();
                case TokenKind.LeftBrace:       // dict_display
                    NextToken();
                    return FinishDictOrSetValue();
                case TokenKind.BackQuote:       // string_conversion
                    NextToken();
                    return FinishStringConversion();
                case TokenKind.Name:            // identifier
                    NextToken();
                    string name = (string)t.Value;
                    if (_sink != null) {
                        _sink.StartName(GetSourceSpan(), name);
                    }
                    ret = new NameExpression(FixName(name));
                    ret.SetLoc(_globalParent, GetStart(), GetEnd());
                    return ret;
                case TokenKind.Constant:        // literal
                    NextToken();
                    var start = GetStart();
                    object cv = t.Value;
                    string cvs = cv as string;
                    if (cvs != null) {
                        cv = FinishStringPlus(cvs);
                    } else {
                        Bytes bytes = cv as Bytes;
                        if (bytes != null) {
                            cv = FinishBytesPlus(bytes);
                        }
                    }

                    if (t is UnicodeStringToken) {
                        ret = ConstantExpression.MakeUnicode((string)cv);
                    } else {
                        ret = new ConstantExpression(cv);
                    }
                    ret.SetLoc(_globalParent, start, GetEnd());
                    return ret;
                default:
                    ReportSyntaxError(_lookahead.Token, _lookahead.Span, ErrorCodes.SyntaxError, _allowIncomplete || _tokenizer.EndContinues);

                    // error node
                    ret = new ErrorExpression();
                    ret.SetLoc(_globalParent, _lookahead.Span.Start, _lookahead.Span.End);
                    return ret;
            }
        }
Exemple #3
0
 // ErrorExpression
 public override bool Walk(ErrorExpression node)
 {
     node.Parent = _currentScope;
     return(base.Walk(node));
 }
Exemple #4
0
 //  parameter ::=
 //      identifier | "(" sublist ")"
 Expression ParseSublistParameter(Dictionary<string, object> names) {
     Token t = NextToken();
     Expression ret = null;
     switch (t.Kind) {
         case TokenKind.LeftParenthesis: // sublist
             ret = ParseSublist(names);
             Eat(TokenKind.RightParenthesis);
             break;
         case TokenKind.Name:  // identifier
             string name = FixName((string)t.Value);
             NameExpression ne = new NameExpression(name);
             CompleteParameterName(ne, name, names);
             return ne;
         default:
             ReportSyntaxError(_token);
             ret = new ErrorExpression();
             ret.SetLoc(GetStart(), GetEnd());
             break;
     }
     return ret;
 }
 public override bool Walk(ErrorExpression node)
 {
     CommonWalk(node);
     return true;
 }
 public override void PostWalk(ErrorExpression node)
 {
     CommonPostWalk(node);
 }
 public void PostWalk(ErrorExpression node)
 {
     PostProcess(node);
 }
 // ErrorExpression
 public bool Walk(ErrorExpression node)
 {
     return Process(node);
 }
 public virtual void PostWalk(ErrorExpression node)
 {
 }
 // ErrorExpression
 public override bool Walk(ErrorExpression node) {
     node.Parent = _currentScope;
     return base.Walk(node);
 }
 // ErrorExpression
 public virtual bool Walk(ErrorExpression node)
 {
     return true;
 }
Exemple #12
0
        // atom: '(' [testlist_gexp] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING+
        private Expression ParsePrimary()
        {
            Token t = NextToken();
            Expression ret;
            switch (t.Kind) {
                case TokenKind.LeftParenthesis:
                    return FinishTupleOrGenExp();
                case TokenKind.LeftBracket:
                    return FinishListValue();
                case TokenKind.LeftBrace:
                    return FinishDictValue();
                case TokenKind.BackQuote:
                    return FinishBackquote();
                case TokenKind.Name:
                    CodeSpan span = GetSpan();
                    SymbolId name = (SymbolId)t.Value;
                    context.Sink.StartName(span, name.GetString());
                    ret = new NameExpression(FixName(name));
                    ret.SetLoc(GetExternal(), GetStart(), GetEnd());
                    return ret;
                case TokenKind.Constant:
                    Location start = GetStart();
                    object cv = t.Value;
                    if (cv is String) {
                        cv = FinishStringPlus((string)cv);
                    }
                    // todo handle STRING+
                    ret = new ConstantExpression(cv);
                    ret.SetLoc(GetExternal(), start, GetEnd());
                    return ret;
                default:
                    ReportSyntaxError(t, ErrorCodes.SyntaxError, allowingIncomplete);

                    // error node
                    ret = new ErrorExpression();
                    ret.SetLoc(GetExternal(), GetStart(), GetEnd());
                    return ret;
            }
        }
Exemple #13
0
 //  parameter ::=
 //      identifier | "(" sublist ")"
 Expression ParseParameter(Dictionary<SymbolId, SymbolId> names)
 {
     Token t = NextToken();
     Expression ret = null;
     switch (t.Kind) {
         case TokenKind.LeftParenthesis: // sublist
             ret = ParseSublist(names);
             Eat(TokenKind.RightParenthesis);
             break;
         case TokenKind.Name:  // identifier
             CodeSpan span = GetSpan();
             SymbolId name = (SymbolId)t.Value;
             context.Sink.StartName(span, name.GetString());
             name = FixName(name);
             CheckUniqueParameter(names, name);
             ret = new NameExpression(name);
             ret.SetLoc(GetExternal(), span);
             break;
         default:
             ReportSyntaxError(t);
             ret = new ErrorExpression();
             ret.SetLoc(GetExternal(), GetStart(), GetEnd());
             break;
     }
     return ret;
 }
 public string Visit(PyAst.ErrorExpression node) => throw CreateNotImplementedEx();
Exemple #15
0
		public override bool Walk(ErrorExpression node)
		{
			writer.WriteLine("Error");
			return base.Walk(node);
		}