Exemple #1
0
 public static Value Include(List args, Preprocessor preprocessor)
 {
     return(Value.Load(args.GetValue(0).AsString(), preprocessor));
 }
Exemple #2
0
 public static Value Load(string filename, string fullScript, Preprocessor preprocessor)
 {
     return(Lexer.Parse(fullScript, filename).DequeueValue(preprocessor));
 }
Exemple #3
0
 public static Value DequeueValue(this Queue <Token> tokens, Preprocessor preprocessor)
 {
     if (tokens.CheckNext <Token.Number>())
     {
         var value = tokens.Dequeue <Token.Number>();
         return(new NumericValue(value.Value));
     }
     else if (tokens.CheckNext <Token.String>())
     {
         var value = tokens.Dequeue <Token.String>();
         return(new StringValue(value.Value));
     }
     else if (tokens.CheckNext <Token.StartTable>())
     {
         return(tokens.DequeueTable(preprocessor));
     }
     else if (tokens.CheckNext <Token.StartList>())
     {
         return(tokens.DequeueList(preprocessor));
     }
     else if (tokens.CheckNext <Token.StartFunction>())
     {
         return(tokens.DequeueFunction(preprocessor));
     }
     else if (tokens.CheckNext <Token.VariablePrefix>())
     {
         tokens.Dequeue <Token.VariablePrefix>();
         var parts = new List <string>();
         parts.Add(tokens.Dequeue <Token.Identifier>().Name);
         while (tokens.CheckNext <Token.KeyDelimiter>())
         {
             tokens.Dequeue <Token.KeyDelimiter>();
             parts.Add(tokens.Dequeue <Token.Identifier>().Name);
         }
         return(new Variable(parts.ToArray()));
     }
     else if (tokens.CheckNext <Token.MacroPrefix>())
     {
         tokens.Dequeue <Token.MacroPrefix>();
         var identifier = tokens.Dequeue <Token.Identifier>();
         var args       = new List();
         tokens.Dequeue <Token.StartList>();
         while (!tokens.CheckNext <Token.EndList>())
         {
             args.Add(tokens.DequeueValue(preprocessor));
             if (!tokens.CheckNext <Token.Delimiter>())
             {
                 break;
             }
             else
             {
                 tokens.Dequeue <Token.Delimiter>();
             }
         }
         tokens.Dequeue <Token.EndList>();
         var macro = preprocessor.GetMacro(identifier.Name, identifier.Source);
         return(macro(args, preprocessor));
     }
     else if (tokens.CheckNext <Token.Identifier>())
     {
         return(DequeueExpression(tokens, preprocessor));
     }
     else
     {
         var token = tokens.Peek();
         throw new ParserScriptException($"{token.GetType().Name} is not a value", token.Source);
     }
 }
Exemple #4
0
 public static Value Load(string filename, Preprocessor preprocessor)
 {
     return(Load(filename, File.ReadAllText(filename), preprocessor));
 }