Esempio n. 1
0
        //

        public static string GetString(SNodeBase baseNode)
        {
            if (baseNode is SExpression)
            {
                SExpression expr = baseNode as SExpression;
                if ((expr.Items != null) && (expr.Items.Count > 0) && (expr.Items[0] is SNodeAtom))
                {
                    return((expr.Items[0] as SNodeAtom).Value);
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("");  // error
            }
        }
Esempio n. 2
0
        private SNodeBase ParseNode(CLex lexer)
        {
            if ((lexer.CurToken.Type == TokenType.Symbol) &&
                (lexer.CurToken.Value == "("))
            {
                //return ParseList(lexer);
                SNodeBase node = ParseList(lexer);

                if (node is SNodeList)
                {
                    SNodeList list = node as SNodeList;
                    //
                    if (list.Items.Count > 0)
                    {
                        SExpression sexpr = new SExpression();

                        if (list.Items[0] is SNodeAtom)
                        {
                            SNodeAtom value = list.Items[0] as SNodeAtom;
                            sexpr.Name = value.Value;
                        }

                        sexpr.Items = new List <SNodeBase>();
                        for (int index = 1; index < list.Items.Count; index++)
                        {
                            sexpr.Items.Add(list.Items[index]);
                        }

                        //
                        return(sexpr);
                    }
                    else
                    {
                        return(node);
                    }
                }
                else
                {
                    return(node);
                }
            }
            else
            {
                // string
                SNodeAtom node;

                if (lexer.CurToken.Type == TokenType.StringLiteral)
                {
                    string value = lexer.CurToken.Value;

                    if (value.StartsWith("\"") && value.EndsWith("\""))
                    {
                        value = value.Substring(1, value.Length - 2);
                        // descape " and \
                    }

                    node = new SNodeAtom(value);
                }
                else
                {
                    node = new SNodeAtom(lexer.CurToken.Value);
                }
                lexer.GetToken();
                return(node);
            }
        }