public List <AsbtractRenderCommand> Parse(FileLine line, IMessageHandler messageHandler) { var commands = new List <AsbtractRenderCommand>(); var script = line.CreateOriginalTextSpan(line.Begin, line.End); if (script.IsEmpty == false) { var scriptEnd = line.CreateOriginalTextSpan(line.End, line.End); commands.Add(new ScriptCommand(script, scriptEnd)); } return(commands); }
public override List <AsbtractRenderCommand> Parse(FileLine line, IMessageHandler messageHandler) { List <AsbtractRenderCommand> commands = base.Parse(line, messageHandler); var newLineSpan = line.CreateOriginalTextSpan(line.BeginNonSpace, line.BeginNonSpace + 1); commands.Add(new NewLineCommand(newLineSpan)); return(commands); }
public List <AsbtractRenderCommand> Parse(FileLine line, IMessageHandler messageHandler) { var commands = new List <AsbtractRenderCommand>(); // var beginSpan = line.CreateOriginalTextSpan(line.BeginNonSpace, line.BeginNonSpace + 1); //skip matched character var scriptBegin = line.Text.IndexOfNot(beginSpan.End, line.End, CharExtensions.IsSpace); var indentationSpan = line.CreateOriginalTextSpan(beginSpan.End, scriptBegin); if (indentationSpan.IsEmpty == false) { var endSpan = line.CreateOriginalTextSpan(indentationSpan.End, indentationSpan.End); commands.Add(new PushIndentationCommand(beginSpan, indentationSpan, endSpan)); } // var statementSpan = line.CreateOriginalTextSpan(indentationSpan.End, line.End); var statementEndSpan = line.CreateOriginalTextSpan(statementSpan.End, statementSpan.End); if (statementSpan.IsEmpty == false) { commands.Add(new StatementCommand(statementSpan, statementEndSpan)); } // if (indentationSpan.IsEmpty == false) { var popIndentationSpan = line.CreateOriginalTextSpan(line.End, line.End); commands.Add(new PopIndentationCommand(popIndentationSpan)); } return(commands); }
public virtual List <AsbtractRenderCommand> Parse(FileLine line, IMessageHandler messageHandler) { var commands = new List <AsbtractRenderCommand>(); var beginSpan = line.CreateOriginalTextSpan(line.BeginNonSpace, line.BeginNonSpace + 1); //skip matched character var index = line.Text.IndexOfNot(beginSpan.End, line.End, CharExtensions.IsSpace); var indentationSpan = line.CreateOriginalTextSpan(beginSpan.End, index); if (indentationSpan.IsEmpty == false) { var endSpan = line.CreateOriginalTextSpan(indentationSpan.End, indentationSpan.End); commands.Add(new PushIndentationCommand(beginSpan, indentationSpan, endSpan)); } var end = index; while (index < line.End) { index = line.Text.IndexOf(index, line.End, (ch) => ch == '#'); if (index == line.End) { // reached line end break; } if ((index + 1) >= line.End) { break; } switch (line.Text[index + 1]) { case '#': { var textSpan = line.CreateOriginalTextSpan(end, index); if (textSpan.IsEmpty == false) { var textEndSpan = line.CreateOriginalTextSpan(index, index); commands.Add(new TextCommand(textSpan, textEndSpan)); } var escapeBegin = (index + 1); //skip # var escapeSpan = line.CreateOriginalTextSpan(escapeBegin, escapeBegin + 1); if (escapeSpan.IsEmpty == false) { var escapeEndSpan = line.CreateOriginalTextSpan(escapeSpan.End, escapeSpan.End); commands.Add(new TextCommand(escapeSpan, escapeEndSpan)); } index = end = (escapeBegin + 1); continue; } case '{': { var textSpan = line.CreateOriginalTextSpan(end, index); if (textSpan.IsEmpty == false) { var textEndSpan = line.CreateOriginalTextSpan(index, index); commands.Add(new TextCommand(textSpan, textEndSpan)); } var expressionBegin = (index + 1); var expressionEnd = BraceCounter.MatchBraces(line.Text, expressionBegin, line.End); if (expressionEnd == line.End) { index = end = line.End; var errorPosition = new TextPosition(line.Position.Line, 1 + (line.End - line.Begin)); messageHandler.Message(TraceLevel.Error, "Missing '}'.", line.Position.Name, errorPosition); break; } var expressionBeginSpan = line.CreateOriginalTextSpan(index, expressionBegin + 1); var expressionSpan = line.CreateOriginalTextSpan(expressionBeginSpan.End, expressionEnd); if (expressionSpan.IsEmpty == false) { var expressionEndSpan = line.CreateOriginalTextSpan(expressionSpan.End, expressionEnd + 1); commands.Add(new ExpressionCommand(expressionBeginSpan, expressionSpan, expressionEndSpan)); } index = end = (expressionEnd + 1); continue; } default: { index = end = (index + 2); continue; } } } var lastTextSpan = line.CreateOriginalTextSpan(end, line.End); if (lastTextSpan.IsEmpty == false) { var textEndSpan = line.CreateOriginalTextSpan(line.End, line.End); commands.Add(new TextCommand(lastTextSpan, textEndSpan)); } if (indentationSpan.IsEmpty == false) { var popIndentationSpan = line.CreateOriginalTextSpan(line.End, line.End); commands.Add(new PopIndentationCommand(popIndentationSpan)); } return(commands); }
public List <AsbtractRenderCommand> Parse(FileLine line, IMessageHandler messageHandler) { var commands = new List <AsbtractRenderCommand>(); while (true) { var index = (line.BeginNonSpace + 1); // Skip # // Find 'pragma' string preproDirective; index = this.MatchNextToken(line.Text, index, line.End, out preproDirective); if (index == line.End) { break; } if (string.Compare(preproDirective, "pragma", StringComparison.Ordinal) != 0) { break; } // Find 'include' string pragmaName; index = this.MatchNextToken(line.Text, index, line.End, out pragmaName); if (index == line.End) { break; } if (string.Compare(pragmaName, "include", StringComparison.Ordinal) != 0) { break; } // Find '"<Filename>"' var pragmaArgBegin = line.Text.IndexOf(index, line.End, ch => ch == '"'); if (pragmaArgBegin == line.End) { break; } var pragmaArgEnd = BraceCounter.FindQuoteEnd(line.Text, index, line.End); if (pragmaArgEnd == line.End) { break; } // Extract <Filename> from '"<Filename>"' string pragmaArgument = line.Text.Substring(pragmaArgBegin + 1, (pragmaArgEnd - pragmaArgBegin - 1)); var pragmaSpan = line.CreateOriginalTextSpan(line.Begin, line.End); if (pragmaSpan.IsEmpty == false) { var endSpan = line.CreateOriginalTextSpan(line.End, line.End); commands.Add(new PragmaCommand(pragmaSpan, endSpan, pragmaName, pragmaArgument)); } index = (pragmaArgEnd + 1); break; } // No pragma detected, pass line through if (commands.Count == 0) { var scriptSpan = line.CreateOriginalTextSpan(line.Begin, line.End); if (scriptSpan.IsEmpty == false) { var scriptEndSpan = line.CreateOriginalTextSpan(line.End, line.End); commands.Add(new ScriptCommand(scriptSpan, scriptEndSpan)); } } return(commands); }