public SprocketScript(string source, string descriptiveName, string scriptIdentificationString) { this.source = source; this.identifier = new ExecutionState.ScriptRecursionIdentifier(descriptiveName, scriptIdentificationString); TokenList tokens; try { tokens = Tokeniser.Extract(source); } catch (TokeniserException ex) { Token falseToken = new Token(source.Substring(ex.Position, 1), TokenType.FreeText, ex.Position); Token token = new Token(GetErrorHTML(ex.Message, falseToken, null), TokenType.FreeText, 0); tokens = new TokenList(new List<Token>(new Token[] { token })); instruction = new ShowInstruction(); instruction.Build(tokens); hasError = true; exception = ex; return; } try { instruction = TokenParser.BuildInstruction(tokens); } catch (TokenParserException ex) { Token token = new Token(GetErrorHTML(ex.Message, ex.Token, null), TokenType.FreeText, 0); tokens = new TokenList(new List<Token>(new Token[] { token })); instruction = new ShowInstruction(); instruction.Build(tokens); hasError = true; } }
public SprocketScript(string source) { this.source = source; List<Token> tokens = Tokeniser.Extract(source); try { instruction = TokenParser.BuildInstruction(tokens); } catch (TokenParserException ex) { tokens.Clear(); tokens.Add(new Token(GetErrorHTML(ex.Message, ex.Token), TokenType.StringLiteral, 0)); instruction = new ShowInstruction(); int n = 0; instruction.Build(tokens, ref n); } }
public SprocketScript(string source) { this.source = source; List <Token> tokens = Tokeniser.Extract(source); try { instruction = TokenParser.BuildInstruction(tokens); } catch (TokenParserException ex) { tokens.Clear(); tokens.Add(new Token(GetErrorHTML(ex.Message, ex.Token), TokenType.StringLiteral, 0)); instruction = new ShowInstruction(); int n = 0; instruction.Build(tokens, ref n); } }
public static IInstruction BuildInstruction(TokenList tokens) { Token token = tokens.Current; // special case: if free text is found, create a "show" instruction to process it if (token.TokenType == TokenType.FreeText) { return(new ShowInstruction(BuildExpression(tokens))); } // find the relevant creator/processor for the instruction if (token.TokenType == TokenType.Word || token.TokenType == TokenType.OtherSymbolic) { if (instructionCreators.ContainsKey(token.Value)) { IInstruction instruction = instructionCreators[token.Value].Create(); instruction.Build(tokens); return(instruction); } } if (token.TokenType == TokenType.GroupStart || token.TokenType == TokenType.GroupEnd) { throw new TokenParserException("Not sure why there is a bracket here.", token); } if (token.Value == "end" && token.TokenType == TokenType.Word && tokens.Next == null) { throw new TokenParserException("The end of the script has been reached prematurely.", tokens.Peek(-1)); } if (expressionCreators.ContainsKey(token.Value)) { throw new TokenParserException("\"" + token.Value + "\" can't stand by itself, as it is only designed to equate to a value. If you want to display the value, precede the keyword with a \"show\" instruction.", token); } throw new TokenParserException("I have no idea what \"" + token.Value + "\" means.", token); }
public static IInstruction BuildInstruction(List <Token> tokens, ref int index) { // if we're just starting, encase the root-level instructions with a section statement if (index == 0) { tokens.Insert(0, new Token(InstructionList.Keyword, TokenType.Word, 0)); tokens.Add(new Token("end", TokenType.Word, 0)); index++; InstructionList il = new InstructionList(); il.Build(tokens, ref index); return(il); } Token token = tokens[index]; // special case: if a standalone literal is found, create a "show" instruction to process it if (token.TokenType == TokenType.StringLiteral) { ShowInstruction si = new ShowInstruction(); si.Build(tokens, ref index, true); return(si); } // find the relevant creator/processor for the instruction if (token.TokenType == TokenType.Word) { if (instructionCreators.ContainsKey(token.Value)) { IInstruction instruction = instructionCreators[token.Value].Create(); index++; instruction.Build(tokens, ref index); return(instruction); } } throw new TokenParserException("I have no idea what \"" + token.Value + "\" means or at least what I'm supposed to do with it here.", token); }
public SprocketScript(string source, string descriptiveName, string scriptIdentificationString) { this.source = source; this.identifier = new ExecutionState.ScriptRecursionIdentifier(descriptiveName, scriptIdentificationString); TokenList tokens; try { tokens = Tokeniser.Extract(source); } catch (TokeniserException ex) { Token falseToken = new Token(source.Substring(ex.Position, 1), TokenType.FreeText, ex.Position); Token token = new Token(GetErrorHTML(ex.Message, falseToken, null), TokenType.FreeText, 0); tokens = new TokenList(new List <Token>(new Token[] { token })); instruction = new ShowInstruction(); instruction.Build(tokens); hasError = true; exception = ex; return; } try { instruction = TokenParser.BuildInstruction(tokens); } catch (TokenParserException ex) { Token token = new Token(GetErrorHTML(ex.Message, ex.Token, null), TokenType.FreeText, 0); tokens = new TokenList(new List <Token>(new Token[] { token })); instruction = new ShowInstruction(); instruction.Build(tokens); hasError = true; } }