//if_statement ::= 'if' '(' expression ')' statement ('else' statement)? public override Node Make(Parser parser) { //if Token t = parser.AssertOperator(Operator.Tag._if); TextRegion region = t.Region; // ( t = parser.AssertOperator(Operator.Tag.LeftPar); Expression condition = parser.AssertNode <Expression>(); region = condition.Region | region | t.Region; // ) t = parser.AssertOperator(Operator.Tag.RightPar); //body Statement yesBranch = parser.AssertNode <Statement>(); region = t.Region | region | yesBranch.Region; //else Statement noBranch = null; t = parser.TryGetOperator(Operator.Tag._else); if (t != null) { noBranch = parser.AssertNode <Statement>(); region = region | noBranch.Region | t.Region; } return(new IfStatement(condition, yesBranch, noBranch, region)); }
// function_call ::= identifier '(' expression? {',' expression} ')' public override Node Make(Parser parser) { //name IdentifierToken name = parser.AssertToken <IdentifierToken>(); TextRegion region = name.Region; //( region = region | parser.AssertOperator(Operator.Tag.LeftPar).Region; List <Expression> args = new List <Expression>(); try { while (true) { Expression expr = parser.AssertNode <Expression>(); region = region | expr.Region; args.Add(expr); Operator comma = parser.TryGetOperator(Operator.Tag.Comma); if (comma == null) { break; } region = region | comma.Region; } } catch { } //) region = region | parser.AssertOperator(Operator.Tag.RightPar).Region; return(new FunctionCall(name, args, region)); }
public Token(TextRegion range, string text, string name = null, TokenType type = TokenType.None) { Range = range; Text = text; Name = name; Type = type; }
/// <summary> /// Skips tokens to the end of specified region. /// </summary> /// <param name="region">The region.</param> private void Skip(TextRegion region) { while (position < tokens.Length && tokens[position].Region.End <= region.End) { position++; } }
public Link GetLink(IDocument document, TextLocation location) { if (location.Line >= document.TotalNumberOfLines) { return(Link.Empty); } var line = TextUtilities.GetLineAsString(document, location.Line); string fileName = null; int hoverColumn = 0; if (FLocalIncludePattern.IsMatch(line)) { fileName = FLocalIncludePattern.Match(line).Groups[1].Value; hoverColumn = line.Length - fileName.Length - 1; fileName = FLocalIncludePath.ConcatPath(fileName.Replace("/", @"\")); } else if (FGlobalIncludePattern.IsMatch(line)) { fileName = FGlobalIncludePattern.Match(line).Groups[1].Value; hoverColumn = line.Length - fileName.Length - 1; fileName = FGlobalIncludePath.ConcatPath(fileName.Replace("/", @"\")); } if (!string.IsNullOrEmpty(fileName)) { var hoverRegion = new TextRegion(location.Line, hoverColumn, location.Line, line.Length - 1); return(new Link(hoverRegion, fileName, new TextLocation(0, 0))); } return(Link.Empty); }
/// <summary> /// tries to close region /// </summary> /// <param name="parser">parser</param> /// <returns>whether region was closed</returns> protected override bool TryComplete(TextRegion r, SnapshotParser parser) { ClassificationSpan span = parser.CurrentSpan; SnapshotPoint point = parser.CurrentPoint; if (span != null) { string text = span.Span.GetText(); if (span.ClassificationType.Classification == "punctuation") { char c = point.GetChar(); //text can be "};", not just "}" if (r.RegionType == TextRegionType.Block && c == '}' || r.RegionType == TextRegionType.Array && c == ']') { r.EndPoint = span.Span.Start + 1; } } else if (span.ClassificationType.Classification == "comment" && r.RegionType == TextRegionType.Region) { Match m = RegionEndRegex.Match(text); if (m.Success) r.EndPoint = span.Span.End; } } return r.Complete; }
public TokenizeException(string s, TextRegion region, Token lastToken, string message) : base("Error after: '" + lastToken + "' and near:\n" + new string(' ', region.Start) + new string('v', region.End - region.Start) + "\n" + s + "\n\n" + message) { String = s; Region = region; LastToken = lastToken; ExceptionMessage = message; }
//for_statement ::= 'for' '(' expression? ';' expression? ';' expression? ')' statement public override Node Make(Parser parser) { //for Token t = parser.AssertOperator(Operator.Tag._for); TextRegion region = t.Region; // ( t = parser.AssertOperator(Operator.Tag.LeftPar); region = region | t.Region; //init; conditioin; loop; Expression init = GetExpression(parser, true, ref region); Expression condition = GetExpression(parser, true, ref region); Expression loop = GetExpression(parser, false, ref region); // ) t = parser.AssertOperator(Operator.Tag.RightPar); region = region | t.Region; //body Statement body = parser.AssertNode <Statement>(); region = region | body.Region; return(new ForStatement(init, condition, loop, body, region)); }
/// <summary> /// tries to close region /// </summary> /// <param name="parser">parser</param> /// <returns>whether region was closed</returns> protected override bool TryComplete(TextRegion r, SnapshotParser parser) { ClassificationSpan span = parser.CurrentSpan; SnapshotPoint point = parser.CurrentPoint; if (span != null) { string text = span.Span.GetText(); if (span.ClassificationType.Classification == "punctuation") { char c = point.GetChar(); //text can be "};", not just "}" if (r.RegionType == TextRegionType.Block && c == '}' || r.RegionType == TextRegionType.Array && c == ']') { r.EndPoint = span.Span.Start + 1; } } else if (span.ClassificationType.Classification == "comment" && r.RegionType == TextRegionType.Region) { Match m = RegionEndRegex.Match(text); if (m.Success) { r.EndPoint = span.Span.End; } } } return(r.Complete); }
private WhileStatement(Expression condition, Statement body, TextRegion region) { this.body = body; this.condition = condition; this.region = region; body.Parent = this; condition.Parent = this; }
protected override List<TextRegion> GetRegionList(TextRegion tree) { //Visual Studio outlines functions itself, let's not conflict with it return VsVersion.Major < 14 ? base.GetRegionList(tree).FindAll(r => r.RegionSubType != TextRegionSubType.Function) //VS 2015 outlines blocks and arrays on its own : base.GetRegionList(tree).FindAll(r => r.RegionType != TextRegionType.Block && r.RegionType != TextRegionType.Array); }
protected override List <TextRegion> GetRegionList(TextRegion tree) { //Visual Studio outlines functions itself, let's not conflict with it return(VsVersion.Major < 14 ? base.GetRegionList(tree).FindAll(r => r.RegionSubType != TextRegionSubType.Function) //VS 2015 outlines blocks and arrays on its own : base.GetRegionList(tree).FindAll(r => r.RegionType != TextRegionType.Block && r.RegionType != TextRegionType.Array)); }
protected override void OnRegionFound(TextRegion r) { base.OnRegionFound(r); if (r.RegionType == TextRegionType.Block && FunctionOccured) { r.RegionSubType = TextRegionSubType.Function; } FunctionOccured = false; }
private ReturnStatement(Expression result, TextRegion region) { this.result = result; this.region = region; if (result != null) { result.Parent = this; } }
private ArgListDefinition(List <ArgumentDefinition> list) { this.list = list; region = new TextRegion(); foreach (ArgumentDefinition arg in list) { region = region | arg.Region; arg.Parent = this; } }
public void PushStackFrame(string name, string text, TextRegion textRegion, TextRegion?contextTextRegion, string originalText = null, Value @this = null) { if (callstack.Count > 1024) { throw new ExpressionException(this, "Too many Stackframes."); } callstack.Push(new StackFrame() { Name = name, Text = text, OriginalText = originalText, RegionInfo = new RegionInfo(textRegion, contextTextRegion), This = @this }); }
private FunctionCall(IdentifierToken name, List <Expression> args, TextRegion region) { this.name = name; this.args = args; foreach (Expression expr in args) { expr.Parent = this; } this.region = region; }
public override Node Make(Parser parser) { TypeNode type = parser.AssertNode <TypeNode>(); TextRegion region = type.Region; region = region | parser.AssertOperator(Operator.Tag.LeftPar).Region; Expression expr = parser.AssertNode <Expression>(); region = region | expr.Region; region = region | parser.AssertOperator(Operator.Tag.RightPar).Region; return(new TypeCast(type, expr, region)); }
public override Node Make(Parser parser) { //continue Token t = parser.AssertOperator(Operator.Tag._continue); TextRegion region = t.Region; //; t = parser.AssertOperator(Operator.Tag.Semicolon); region = t.Region | region; return(new ContinueStatement(region)); }
public override Node Make(Parser parser) { //break Token t = parser.AssertOperator(Operator.Tag._break); TextRegion region = t.Region; //; t = parser.AssertOperator(Operator.Tag.Semicolon); region = t.Region | region; return(new BreakStatement(region)); }
private void FireMissingError(TokenType expected) { if (_parseErrorHandler != null) { // need to tweak the current location, since it points to the last consumed token, // but there's something missing AFTER that token... var loc = new TextRegion( _genericTokens.CurrentLocation.Line, _genericTokens.CurrentLocation.PositionInLine + _genericTokens.CurrentLocation.Length, 0); _parseErrorHandler.Missing(expected, loc); } }
private Expression GetExpression(Parser parser, bool semicolon, ref TextRegion region) { Expression expr = parser.TryGetNode <Expression>(); if (semicolon) { region = parser.AssertOperator(Operator.Tag.Semicolon).Region | region; } if (expr != null) { region = region | expr.Region; } return(expr); }
/// <summary> /// tries to close region /// </summary> /// <param name="parser">parser</param> /// <returns>whether region was closed</returns> protected override bool TryComplete(TextRegion r, SnapshotParser parser) { ClassificationSpan span = parser.CurrentSpan; SnapshotPoint point = parser.CurrentPoint; if (span != null) { if (span.ClassificationType.Classification == "punctuation") { char c = point.GetChar(); //text can be "};", not just "}" if (r.RegionType == TextRegionType.Block && c == '}' || r.RegionType == TextRegionType.Array && c == ']') { r.EndPoint = span.Span.Start + 1; } } } return r.Complete; }
private ProgramNode(List <Declare> declares, List <FunctionDefinition> functions) { region = new TextRegion(); this.declares = declares; this.functions = functions; foreach (FunctionDefinition function in functions) { region = region | function.Region; function.Parent = this; } foreach (Declare declare in declares) { region = region | declare.Region; declare.Parent = this; } }
public override Node Make(Parser parser) { TypeNode type = parser.AssertNode <TypeNode>(); IdentifierToken nameToken = parser.AssertToken <IdentifierToken>(); TextRegion region = type.Region | nameToken.Region; region = region | parser.AssertOperator(Operator.Tag.LeftPar).Region; ArgListDefinition args = parser.AssertNode <ArgListDefinition>(); region = region | args.Region; region = region | parser.AssertOperator(Operator.Tag.RightPar).Region; Statement body = parser.AssertNode <Block>(); region = region | body.Region; return(new FunctionDefinition(type, nameToken.Text, args, body, region)); }
//declare ::= type identifier ('=' expression)? {',' identifier ('=' expression)? } ';' public override Node Make(Parser parser) { // type TypeNode type = parser.AssertNode <TypeNode>(); TextRegion region = type.Region; // id List <Variable> IdList = new List <Variable>(); List <Expression> InitList = new List <Expression>(); Variable id = parser.AssertNode <Variable>(); Expression init = null; Token eq = parser.TryGetOperator(Operator.Tag.Assignment); if (eq != null) { init = parser.AssertNode <Expression>(); } InitList.Add(init); region = region | id.Region; IdList.Add(id); // {, id} try { while (true) { region = region | parser.AssertOperator(Operator.Tag.Comma).Region; id = parser.AssertNode <Variable>(); init = null; eq = parser.TryGetOperator(Operator.Tag.Assignment); if (eq != null) { init = parser.AssertNode <Expression>(); } InitList.Add(init); region = region | id.Region; IdList.Add(id); } } catch (ParseException) { } //; Operator semicolon = parser.AssertOperator(Operator.Tag.Semicolon); region = region | semicolon.Region; return(new Declare(type, IdList, InitList, region)); }
/// <summary> /// tries to merge sequential comments /// </summary> /// <returns>true, if merged. In this case newRegion is not added to Children</returns> protected override bool TryMergeComments(TextRegion r, TextRegion newRegion) { if (r.Children.Count > 0) { TextRegion last = r.Children[r.Children.Count - 1]; //merge conditions if (last.RegionType == TextRegionType.Comment && newRegion.RegionType == TextRegionType.Comment && newRegion.StartLine.LineNumber <= last.EndLine.LineNumber + 1 && string.IsNullOrWhiteSpace(new SnapshotSpan(last.EndPoint, newRegion.StartPoint).GetText())) { //instead of adding newRegion, we just move last child's end last.EndPoint = newRegion.EndPoint; return(true); } } return(false); }
public void OutputStackposition(string originalText = null) { originalText = originalText ?? GetLocalText(); if (originalText == null) { Console.WriteLine("Can´t output Stackposition. No original Text found."); } StackFrame currentFrame = callstack.Peek(); if (currentFrame.RegionInfo.ContextTextRegion is TextRegion contextRegion) { TextRegion region = currentFrame.RegionInfo.TextRegion; Console.ForegroundColor = ConsoleColor.White; Console.Write(originalText.Substring(0, contextRegion.Start)); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(originalText.Substring(contextRegion.Start, region.Start - contextRegion.Start)); Console.ForegroundColor = ConsoleColor.Red; Console.Write(region.Apply(originalText)); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(originalText.Substring(region.End, contextRegion.End - region.End)); Console.ForegroundColor = ConsoleColor.White; Console.Write(originalText.Substring(contextRegion.End)); } else { TextRegion region = currentFrame.RegionInfo.TextRegion; Console.ForegroundColor = ConsoleColor.White; Console.Write(originalText.Substring(0, region.Start)); Console.ForegroundColor = ConsoleColor.Red; Console.Write(region.Apply(originalText)); Console.ForegroundColor = ConsoleColor.White; Console.Write(originalText.Substring(region.End)); } }
public override Node Make(Parser parser) { //return Token t = parser.AssertOperator(Operator.Tag._return); TextRegion region = t.Region; //value Expression result = parser.TryGetNode <Expression>(); //; t = parser.AssertOperator(Operator.Tag.Semicolon); region = t.Region | region; if (result != null) { region = region | result.Region; } return(new ReturnStatement(result, region)); }
/// <summary> /// Find bounding boxes of text words given an input image. /// </summary> /// <param name="inputImage">An image expected to be a CV_U8C3 of any size</param> /// <returns>The text regions found.</returns> public TextRegion[] Detect(IInputArray inputImage) { using (InputArray iaImage = inputImage.GetInputArray()) using (VectorOfRect vr = new VectorOfRect()) using (VectorOfFloat vf = new VectorOfFloat()) { TextInvoke.cveTextDetectorCNNDetect(_ptr, iaImage, vr, vf); Rectangle[] bboxes = vr.ToArray(); float[] confidents = vf.ToArray(); TextRegion[] regions = new TextRegion[bboxes.Length]; for (int i = 0; i < regions.Length; i++) { TextRegion tr = new TextRegion(); tr.BBox = bboxes[i]; tr.Confident = confidents[i]; regions[i] = tr; } return(regions); } }
/// <summary> /// tries to close region /// </summary> /// <param name="parser">parser</param> /// <returns>whether region was closed</returns> protected override bool TryComplete(TextRegion r, SnapshotParser parser) { ClassificationSpan span = parser.CurrentSpan; SnapshotPoint point = parser.CurrentPoint; if (span != null) { if (span.ClassificationType.Classification == "punctuation") { char c = point.GetChar(); //text can be "};", not just "}" if (r.RegionType == TextRegionType.Block && c == '}' || r.RegionType == TextRegionType.Array && c == ']') { r.EndPoint = span.Span.Start + 1; } } } return(r.Complete); }
//while_statement ::= 'while' '(' expression ')' statement public override Node Make(Parser parser) { //while Token t = parser.AssertOperator(Operator.Tag._while); TextRegion region = t.Region; // ( t = parser.AssertOperator(Operator.Tag.LeftPar); Expression condition = parser.AssertNode <Expression>(); region = condition.Region | region | t.Region; // ) t = parser.AssertOperator(Operator.Tag.RightPar); //body Statement body = parser.AssertNode <Statement>(); region = t.Region | region | body.Region; return(new WhileStatement(condition, body, region)); }
static RectRegion BuildUI() { var fs = new FontSource(); var tr = new TextRegion() { Text = Lorem.Text, GridColor = new Color4(0.7f, 0.7f, 0.7f, 1.0f), FontSize = 36, }; var list = new ListRegion <FontInfo>(fs); list.SelectionChanged += () => { tr.Style.Font = list.Selected; }; return(new HorizontalSplitter { Left = list, Right = tr, }); }
protected override List<TextRegion> GetRegionList(TextRegion tree) { //Visual Studio outlines functions itself, let's not conflict with it return base.GetRegionList(tree).FindAll(r => r.RegionSubType != TextRegionSubType.Function); }
/// <summary> /// tries to merge sequential comments /// </summary> /// <returns>true, if merged. In this case newRegion is not added to Children</returns> protected override bool TryMergeComments(TextRegion r, TextRegion newRegion) { if (r.Children.Count > 0) { TextRegion last = r.Children[r.Children.Count - 1]; //merge conditions if (last.RegionType == TextRegionType.Comment && newRegion.RegionType == TextRegionType.Comment && newRegion.StartLine.LineNumber <= last.EndLine.LineNumber + 1 && string.IsNullOrWhiteSpace(new SnapshotSpan(last.EndPoint, newRegion.StartPoint).GetText())) { //instead of adding newRegion, we just move last child's end last.EndPoint = newRegion.EndPoint; return true; } } return false; }
protected override List<TextRegion> GetRegionList(TextRegion tree) { //VS 2015 outlines blocks and arrays on its own return base.GetRegionList(tree).FindAll(r => r.RegionType != TextRegionType.Array); }
internal static void press_any_key(string text, bool clearArea, int fgColor, TextRegion region) { int r = (int)region; press_any_key(text, clearArea, fgColor, bounds[r, 0], bounds[r, 1], bounds[r, 2], bounds[r, 3]); }
protected override TextRegion ParseBuffer(SnapshotParser parser, TextRegion parent) { FunctionOccured = false; return base.ParseBuffer(parser, parent); }
internal static void draw8x8_clear_area(TextRegion region) { int r = (int)region; draw8x8_clear_area(seg041.bounds[r, 0], seg041.bounds[r, 1], seg041.bounds[r, 2], seg041.bounds[r, 3]); }