Esempio n. 1
0
        public static SprakBoolean IsKeyPressed(
            ExecutionContext context, SprakString key)
        {
            bool result = context.Computer?.Screen.IsKeyPressed(key.Value) ?? false;

            return(SprakBoolean.From(result));
        }
Esempio n. 2
0
        // I

        public static SprakString Input(
            ExecutionContext context, SprakString promt)
        {
            string result = context.Computer.Screen?.Input(promt.Value);

            return(new SprakString(result));
        }
Esempio n. 3
0
        // H

        public static SprakBoolean HasFunction(ExecutionContext context,
                                               SprakString name)
        {
            bool exists = context.SignatureResolver
                          .FindFunctions(name.Value)
                          .Any();

            return(SprakBoolean.From(exists));
        }
Esempio n. 4
0
        // B

        // What does the broadcast function do?

        // C

        public static SprakNumber CharToInt(SprakString text)
        {
            if (double.TryParse(text.Value, out double result))
            {
                return(new SprakNumber(result));
            }
            else
            {
                return(new SprakNumber(double.NaN));
            }
        }
Esempio n. 5
0
 public static SprakString Add(SprakString left, SprakString right)
 {
     return(new SprakString(left.Value + right.Value));
 }
Esempio n. 6
0
 public static SprakBoolean NotEqual(SprakString left, SprakString right)
 {
     return(SprakBoolean.From(left != right));
 }
Esempio n. 7
0
 public static SprakUnit CopyToClipboard(
     ExecutionContext context, SprakString content)
 {
     context.Computer.Screen?.CopyToClipboard(content.Value);
     return(SprakUnit.Value);
 }
Esempio n. 8
0
        // T

        public static SprakUnit Text(ExecutionContext context,
                                     SprakNumber x, SprakNumber y, SprakString text)
        {
            context.Computer.Screen?.Text(text.Value, x.Value, y.Value);
            return(SprakUnit.Value);
        }
Esempio n. 9
0
 public static SprakUnit PrintS(ExecutionContext context, SprakString input)
 {
     context.Computer.Screen?.PrintS(input.Value);
     return(SprakUnit.Value);
 }
Esempio n. 10
0
        private static bool TryParse(IList <RawToken> tokens, out Value result)
        {
            result = null;

            if (tokens.Count == 0)
            {
                return(false);
            }

            else if (tokens.Count == 1)
            {
                RawToken token   = tokens[0];
                string   content = token.Content;

                switch (token.Type)
                {
                case TokenType.Boolean
                    when SprakBoolean.TryParse(content, out SprakBoolean raw):
                    result = raw;

                    return(true);

                case TokenType.Number
                    when SprakNumber.TryParse(content, out SprakNumber raw):
                    result = raw;

                    return(true);

                case TokenType.String:
                    result = new SprakString(content);
                    return(true);
                }
            }
            else
            {
                if (tokens[0].Type != TokenType.KeySymbol || tokens[0].Content[0] != Symbols.OpenSquareBracket)
                {
                    return(false);
                }

                if (tokens[0].Type != TokenType.KeySymbol || tokens[0].Content[0] != Symbols.CloseSquareBracket)
                {
                    return(false);
                }

                List <Value>    items   = new List <Value>();
                List <RawToken> current = new List <RawToken>();

                for (int i = 1; i < tokens.Count - 1; i++)
                {
                    if (tokens[i].Type == TokenType.KeySymbol && tokens[i].Content[0] == Symbols.Comma)
                    {
                        if (!TryParse(tokens, out Value item))
                        {
                            return(false);
                        }

                        items.Add(item);
                        current.Clear();
                    }
                    else
                    {
                        current.Add(tokens[i]);
                    }
                }
            }

            return(false);
        }