public SymbolTable Analyse(AstRoot ast) { SymbolTable retTable = new SymbolTable (); RootAnalyser visitor = new RootAnalyser (errorLog, retTable); ast.Visit (visitor); return retTable; }
public IodineModule CompileAst(IodineModule module, AstRoot ast) { ModuleCompiler compiler = new ModuleCompiler (errorLog, symbolTable, module); ast.Visit (compiler); module.Initializer.FinalizeLabels (); optimizeObject (module); return module; }
public AstRoot Parse () { try { AstRoot root = new AstRoot (tokenStream.Location); while (!tokenStream.EndOfStream) { root.Add (ParseStatement (tokenStream)); } return root; } catch (Exception) { return new AstRoot (tokenStream.Location); } finally { if (tokenStream.ErrorLog.ErrorCount > 0) { throw new SyntaxException (tokenStream.ErrorLog); } } }
public virtual void ComputeCurrentParameter(AstRoot ast, int position) { if (Parameters == null || Parameters.Count == 0 || SubjectBuffer == null) { this.CurrentParameter = null; return; } var parameterIndex = ComputeCurrentParameter(SubjectBuffer.CurrentSnapshot, ast, position); if (parameterIndex < Parameters.Count) { this.CurrentParameter = Parameters[parameterIndex]; } else { //too many commas, so use the last parameter as the current one. this.CurrentParameter = Parameters[Parameters.Count - 1]; } }
public async Task QuickInfoSourceTest01() { string content = @"x <- as.matrix(x)"; AstRoot ast = RParser.Parse(content); int caretPosition = 6; ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); QuickInfoSource quickInfoSource = new QuickInfoSource(textBuffer); QuickInfoSessionMock quickInfoSession = new QuickInfoSessionMock(textBuffer, caretPosition); List <object> quickInfoContent = new List <object>(); quickInfoSession.TriggerPoint = new SnapshotPoint(textBuffer.CurrentSnapshot, caretPosition); var applicableSpan = await quickInfoSource.AugmentQuickInfoSessionAsync(ast, caretPosition, quickInfoSession, quickInfoContent); ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 10); applicableSpan.Should().NotBeNull(); quickInfoContent.Should().ContainSingle() .Which.ToString().Should().StartWith("as.matrix(x, data, nrow, ncol, byrow, dimnames, rownames.force, ...)"); }
public void ParameterTest02() { string content = @"x <- foo(,,,)"; AstRoot ast = RParser.Parse(content); ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 9); parametersInfo.Should().NotBeNull() .And.HaveFunctionCall() .And.HaveFunctionName("foo") .And.HaveParameterIndex(0); parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 10); parametersInfo.Should().HaveParameterIndex(1); parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 11); parametersInfo.Should().HaveParameterIndex(2); parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 12); parametersInfo.Should().HaveParameterIndex(3); }
public async Task SignatureHelpSourceTest01() { string content = @"x <- as.matrix(x)"; AstRoot ast = RParser.Parse(content); int caretPosition = 15; ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); SignatureHelpSource signatureHelpSource = new SignatureHelpSource(textBuffer, _editorShell); SignatureHelpSessionMock signatureHelpSession = new SignatureHelpSessionMock(textBuffer, caretPosition); List <ISignature> signatures = new List <ISignature>(); signatureHelpSession.TrackingPoint = new TrackingPointMock(textBuffer, caretPosition, PointTrackingMode.Positive, TrackingFidelityMode.Forward); await signatureHelpSource.AugmentSignatureHelpSessionAsync(signatureHelpSession, signatures, ast); signatures.Should().ContainSingle(); signatures[0].Parameters.Should().HaveCount(8); signatures[0].CurrentParameter.Name.Should().Be("x"); signatures[0].Content.Should().Be("as.matrix(x, ..., data, nrow, ncol, byrow, dimnames, rownames.force)"); signatures[0].Documentation.Should().NotBeEmpty(); }
public IDisposable AstReadLock() { lock (_lock) { var guid = Guid.NewGuid(); if (_lockedAstRoot == null) { _lockedAstRoot = _editorTree.AcquireReadLock(guid); } _lockCount++; return(Disposable.Create(() => { _lockCount--; if (_lockCount == 0) { _editorTree?.ReleaseReadLock(guid); _lockedAstRoot = null; } })); } }
/// <summary> /// Formats specific scope /// </summary> private static void FormatScope(ITextView textView, ITextBuffer textBuffer, AstRoot ast, IScope scope, int baseIndentPosition, bool indentCaret) { ICompoundUndoAction undoAction = EditorShell.Current.CreateCompoundAction(textView, textView.TextBuffer); undoAction.Open(Resources.AutoFormat); bool changed = false; try { // Now format the scope changed = RangeFormatter.FormatRangeExact(textView, textBuffer, scope, ast, REditorSettings.FormatOptions, baseIndentPosition, indentCaret); if (indentCaret) { IndentCaretInNewScope(textView, textBuffer, scope, REditorSettings.FormatOptions); changed = true; } } finally { undoAction.Close(!changed); } }
public void AstShiftTest2() { AstRoot ast = RParser.Parse(new TextStream(" a()")); var scope = ast.Children[0].Should().BeAssignableTo <IScope>().Which; scope.Children[0].Start.Should().Be(1); var expression = scope.Children[0].Should().BeAssignableTo <IStatement>() .Which.Children[0].Should().BeAssignableTo <IExpression>() .Which; expression.Children[0].Start.Should().Be(1); var func = expression.Children[0].Should().BeAssignableTo <IFunction>() .Which; func.OpenBrace.Start.Should().Be(2); ast.ShiftStartingFrom(2, 1); func.OpenBrace.Start.Should().Be(3); }
public void ParseIfElseTest04() { string expected = @"GlobalScope [Global] If [] TokenNode [if [0...2)] TokenNode [( [2...3)] Expression [x < y] TokenOperator [< [5...6)] Variable [x] TokenNode [< [5...6)] Variable [y] TokenNode [) [8...9)] SimpleScope [10...18) ExpressionStatement [x <- x+1] Expression [x <- x+1] TokenOperator [<- [12...14)] Variable [x] TokenNode [<- [12...14)] TokenOperator [+ [16...17)] Variable [x] TokenNode [+ [16...17)] NumericalValue [1 [17...18)] KeywordScopeStatement [] TokenNode [else [19...23)] Scope [] TokenNode [{ [24...25)] ExpressionStatement [x <- x + 2] Expression [x <- x + 2] TokenOperator [<- [28...30)] Variable [x] TokenNode [<- [28...30)] TokenOperator [+ [33...34)] Variable [x] TokenNode [+ [33...34)] NumericalValue [2 [35...36)] TokenNode [} [37...38)] "; AstRoot ast = ParserTest.VerifyParse(expected, "if(x < y) x <- x+1 else { x <- x + 2 }"); }
public void ParseIfElseTest12() { string expected = @"GlobalScope [Global] ExpressionStatement [x <- func(a = if(x < y) 1 \n else 2)] Expression [x <- func(a = if(x < y) 1 \n else 2)] TokenOperator [<- [2...4)] Variable [x] TokenNode [<- [2...4)] FunctionCall [5...35) Variable [func] TokenNode [( [9...10)] ArgumentList [10...34) NamedArgument [10...34) TokenNode [a [10...11)] TokenNode [= [12...13)] Expression [if(x < y) 1 \n else 2] InlineIf [] TokenNode [if [14...16)] TokenNode [( [16...17)] Expression [x < y] TokenOperator [< [19...20)] Variable [x] TokenNode [< [19...20)] Variable [y] TokenNode [) [22...23)] SimpleScope [24...25) ExpressionStatement [1] Expression [1] NumericalValue [1 [24...25)] KeywordScopeStatement [] TokenNode [else [28...32)] SimpleScope [33...34) ExpressionStatement [2] Expression [2] NumericalValue [2 [33...34)] TokenNode [) [34...35)] "; AstRoot ast = ParserTest.VerifyParse(expected, "x <- func(a = if(x < y) 1 \n else 2)"); }
public void ParseIfElseTest06() { string expected = @"GlobalScope [Global] If [] TokenNode [if [0...2)] TokenNode [( [2...3)] Expression [x < y] TokenOperator [< [5...6)] Variable [x] TokenNode [< [5...6)] Variable [y] TokenNode [) [8...9)] SimpleScope [12...20) ExpressionStatement [x <- x+1] Expression [x <- x+1] TokenOperator [<- [14...16)] Variable [x] TokenNode [<- [14...16)] TokenOperator [+ [18...19)] Variable [x] TokenNode [+ [18...19)] NumericalValue [1 [19...20)] KeywordScopeStatement [] TokenNode [else [21...25)] Scope [] TokenNode [{ [28...29)] ExpressionStatement [x <- x + 2] Expression [x <- x + 2] TokenOperator [<- [32...34)] Variable [x] TokenNode [<- [32...34)] TokenOperator [+ [37...38)] Variable [x] TokenNode [+ [37...38)] NumericalValue [2 [39...40)] TokenNode [} [41...42)] "; AstRoot ast = ParserTest.VerifyParse(expected, "if(x < y) \n x <- x+1 else \n { x <- x + 2 }"); }
/// <summary> /// Launches AST and file validation / syntax check. /// The process runs asyncronously. /// </summary> public Task RunAsync(AstRoot ast, bool projectedBuffer, bool linterEnabled, ConcurrentQueue <IValidationError> results, CancellationToken ct) { _tcs = new TaskCompletionSource <bool>(); try { BeginValidation(_settings, projectedBuffer, linterEnabled); _validationTask = Task.Run(() => { var outcome = Validate(ast, ct); foreach (var o in outcome) { results.Enqueue(o); } }).ContinueWith(t => { EndValidation(); _tcs.TrySetResult(true); }); } catch (OperationCanceledException) { EndValidation(); _tcs.TrySetCanceled(); } return(_tcs.Task); }
public override bool BuildRegions(OutlineRegionCollection newRegions) { lock (_threadLock) { if (IsDisposed || !EditorTree.IsReady) { return(false); } AstRoot rootNode = null; try { // We are in a background thread so in order to walk the tree // we must obtain the read lock first. rootNode = EditorTree.AcquireReadLock(_treeUserId); if (rootNode != null) { OutliningContext context = new OutliningContext(); context.Regions = newRegions; // Walk the tree and construct new regions rootNode.Accept(this, context); OutlineSections(rootNode, context); } } catch (Exception ex) { var message = Invariant($"Exception in R outliner: {ex.Message}"); Debug.Assert(false, message); GeneralLog.Write(message); } finally { if (rootNode != null) { EditorTree.ReleaseReadLock(_treeUserId); } else { // Tree was busy. Will try again later. GuardedOperations.DispatchInvoke(() => BackgroundTask.DoTaskOnIdle(), DispatcherPriority.Normal); } } return(true); } }
private static void ParseFileImplementation(CoreTestFilesFixture fixture, string name) { string testFile = fixture.GetDestinationPath(name); string baselineFile = testFile + ".tree"; string text = fixture.LoadDestinationFile(name); AstRoot actualTree = RParser.Parse(text); AstWriter astWriter = new AstWriter(); string actual = astWriter.WriteTree(actualTree); if (_regenerateBaselineFiles) { // Update this to your actual enlistment if you need to update baseline baselineFile = Path.Combine(fixture.SourcePath, name) + ".tree"; TestFiles.UpdateBaseline(baselineFile, actual); } else { TestFiles.CompareToBaseLine(baselineFile, actual); } }
public async Task QuickInfoSourceTest02() { // 'as.Date.character' RD contains no function info for 'as.Date.character', but the one for 'as.Date' // then, the current code expects to add 'as.Date' quick info, which is the first function info for as.Date.character string content = @"x <- as.Date.character(x)"; AstRoot ast = RParser.Parse(content); int caretPosition = 23; // in arguments ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); QuickInfoSource quickInfoSource = new QuickInfoSource(textBuffer, EditorShell); QuickInfoSessionMock quickInfoSession = new QuickInfoSessionMock(textBuffer, caretPosition); List <object> quickInfoContent = new List <object>(); quickInfoSession.TriggerPoint = new SnapshotPoint(textBuffer.CurrentSnapshot, caretPosition); var applicableSpan = await quickInfoSource.AugmentQuickInfoSessionAsync(ast, caretPosition, quickInfoSession, quickInfoContent); ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 10); applicableSpan.Should().NotBeNull(); quickInfoContent.Should().ContainSingle() .Which.ToString().Should().StartWith("as.Date(x, ...)"); }
public void ParseIfElseTest08() { string expected = @"GlobalScope [Global] ExpressionStatement [func(if(x < y) 1 \n else \n 2, a)] Expression [func(if(x < y) 1 \n else \n 2, a)] FunctionCall [0...31) Variable [func] TokenNode [( [4...5)] ArgumentList [5...30) ExpressionArgument [5...28) Expression [if(x < y) 1 \n else \n 2] InlineIf [] TokenNode [if [5...7)] TokenNode [( [7...8)] Expression [x < y] TokenOperator [< [10...11)] Variable [x] TokenNode [< [10...11)] Variable [y] TokenNode [) [13...14)] SimpleScope [15...16) ExpressionStatement [1] Expression [1] NumericalValue [1 [15...16)] KeywordScopeStatement [] TokenNode [else [19...23)] SimpleScope [26...27) ExpressionStatement [2] Expression [2] NumericalValue [2 [26...27)] TokenNode [, [27...28)] ExpressionArgument [29...30) Expression [a] Variable [a] TokenNode [) [30...31)] "; AstRoot ast = ParserTest.VerifyParse(expected, "func(if(x < y) 1 \n else \n 2, a)"); }
public void ParseIfElseTest07() { string expected = @"GlobalScope [Global] If [] TokenNode [if [0...2)] TokenNode [( [2...3)] Expression [x < y] TokenOperator [< [5...6)] Variable [x] TokenNode [< [5...6)] Variable [y] TokenNode [) [8...9)] Scope [] TokenNode [{ [10...11)] ExpressionStatement [x <- x+1] Expression [x <- x+1] TokenOperator [<- [14...16)] Variable [x] TokenNode [<- [14...16)] TokenOperator [+ [18...19)] Variable [x] TokenNode [+ [18...19)] NumericalValue [1 [19...20)] TokenNode [} [21...22)] ExpressionStatement [x <- x + 2] Expression [x <- x + 2] TokenOperator [<- [34...36)] Variable [x] TokenNode [<- [34...36)] TokenOperator [+ [39...40)] Variable [x] TokenNode [+ [39...40)] NumericalValue [2 [41...42)] UnexpectedToken Token [25...29) "; AstRoot ast = ParserTest.VerifyParse(expected, "if(x < y) { x <- x+1 } \n else \n x <- x + 2"); }
internal static Task <ITrackingSpan> AugmentQuickInfoSessionAsync( this QuickInfoSource quickInfoSource , AstRoot ast , ITextBuffer textBuffer , int position , IQuickInfoSession quickInfoSession , IList <object> quickInfoContent) { var tcs = new TaskCompletionSource <ITrackingSpan>(); var ready = quickInfoSource.AugmentQuickInfoSession(ast, textBuffer, position, quickInfoSession, quickInfoContent, out ITrackingSpan applicableSpan, (infos, o) => { QuickInfoSource.GetCachedSignatures(quickInfoContent, textBuffer, position, infos, out ITrackingSpan result); tcs.TrySetResult(result); }); if (ready) { tcs.TrySetResult(applicableSpan); } return(tcs.Task); }
/// <summary> /// Given position in a text buffer finds method name, /// parameter index as well as where method signature ends. /// </summary> public static ParameterInfo GetParametersInfoFromBuffer(AstRoot astRoot, ITextSnapshot snapshot, int position) { FunctionCall functionCall; Variable functionVariable; int parameterIndex = -1; string parameterName; bool namedParameter = false; if (!GetFunction(astRoot, ref position, out functionCall, out functionVariable)) { return(null); } parameterIndex = functionCall.GetParameterIndex(position); parameterName = functionCall.GetParameterName(parameterIndex, out namedParameter); if (!string.IsNullOrEmpty(functionVariable.Name) && functionCall != null && parameterIndex >= 0) { return(new ParameterInfo(functionVariable.Name, functionCall, parameterIndex, parameterName, namedParameter)); } return(null); }
public static void FormatScope(ITextView textView, ITextBuffer textBuffer, int position, bool indentCaret) { IREditorDocument document = REditorDocument.TryFromTextBuffer(textBuffer); if (document != null) { document.EditorTree.EnsureTreeReady(); int baseIndentPosition = -1; ITextSnapshot snapshot = textBuffer.CurrentSnapshot; AstRoot ast = document.EditorTree.AstRoot; IScope scope = ast.GetNodeOfTypeFromPosition <IScope>(position); // Scope indentation is defined by its parent statement. IAstNodeWithScope parentStatement = ast.GetNodeOfTypeFromPosition <IAstNodeWithScope>(position); if (parentStatement != null && parentStatement.Scope == scope) { ITextSnapshotLine baseLine = snapshot.GetLineFromPosition(parentStatement.Start); baseIndentPosition = baseLine.Start; } FormatScope(textView, textBuffer, ast, scope, baseIndentPosition, indentCaret); } }
/// <summary> /// Given position over function name retrieves name range and the function call. /// </summary> public static string GetFunctionName(this AstRoot ast, int position, out FunctionCall functionCall, out Variable functionVariable) { functionVariable = null; functionCall = null; ast.GetPositionNode(position, out var node); if (node == null) { return(null); } // In abc(de|f(x)) first find inner function, then outer. if (node is TokenNode && node.Parent is FunctionCall) { functionCall = (FunctionCall)node.Parent; } else { functionCall = ast.GetNodeOfTypeFromPosition <FunctionCall>(position); } functionVariable = functionCall?.RightOperand as Variable; return(functionVariable?.Name); }
/// <summary> /// Determines if a given position is in area where user /// specified indentation must be respected. For example, /// in multi-line list of function arguments, /// multi-line expressions and so on. /// </summary> private static bool RespectUserIndent(ITextBuffer textBuffer, AstRoot ast, int position) { // Look up nearest expression IAstNode node = ast.GetNodeOfTypeFromPosition <Expression>(position); if (IsMultilineNode(textBuffer, node)) { return(true); } node = ast.GetNodeOfTypeFromPosition <FunctionDefinition>(position); if (IsMultilineNode(textBuffer, node)) { return(true); } node = ast.GetNodeOfTypeFromPosition <FunctionCall>(position); if (IsMultilineNode(textBuffer, node)) { return(true); } return(false); }
public async Task SignatureHelpSourceTest02() { string content = @" x <- function(a, b = TRUE, c = 12/7) { } x( ) "; AstRoot ast = RParser.Parse(content); int caretPosition = content.IndexOf("( )") + 1; ITextBuffer textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); SignatureHelpSource signatureHelpSource = new SignatureHelpSource(textBuffer, EditorShell); SignatureHelpSessionMock signatureHelpSession = new SignatureHelpSessionMock(textBuffer, caretPosition); List <ISignature> signatures = new List <ISignature>(); signatureHelpSession.TrackingPoint = new TrackingPointMock(textBuffer, caretPosition, PointTrackingMode.Positive, TrackingFidelityMode.Forward); await signatureHelpSource.AugmentSignatureHelpSessionAsync(signatureHelpSession, signatures, ast); signatures.Should().ContainSingle(); signatures[0].Parameters.Should().HaveCount(3); signatures[0].CurrentParameter.Name.Should().Be("a"); signatures[0].Content.Should().Be("x(a, b = TRUE, c = 12/7)"); signatures[0].Documentation.Should().BeEmpty(); }
/// <summary> /// Removes all elements from the tree /// </summary> /// <returns>Number of removed elements</returns> public int Invalidate() { // make sure not to use RootNode property since // calling get; causes parse List <IAstNode> removedNodes = new List <IAstNode>(); foreach (var child in _astRoot.Children) { removedNodes.Add(child); } if (_astRoot.Children.Count > 0) { PreviousAstRoot = _astRoot; } _astRoot = new AstRoot(_astRoot.TextProvider); if (removedNodes.Count > 0) { FireOnNodesRemoved(removedNodes); } return(removedNodes.Count); }
public void AstNode_RemoveChildrenTest() { AstRoot ast = RParser.Parse(new TextStream(" x <- a+b")); IOperator op = ast.Children[0].Should().BeAssignableTo <IScope>() .Which.Children[0].Should().BeAssignableTo <IStatement>() .Which.Children[0].Should().BeAssignableTo <IExpression>() .Which.Children[0].Should().BeAssignableTo <IOperator>() .Which; op.Children.Should().HaveCount(3); op.RemoveChildren(1, 0); op.Children.Should().HaveCount(3); op.RemoveChildren(0, 1); op.Children.Should().HaveCount(2); op.RemoveChildren(0, 0); op.Children.Should().HaveCount(2); op.RemoveChildren(1, 1); op.Children.Should().HaveCount(1); }
public EditorTreeMock(ITextBuffer textBuffer, AstRoot ast) { TextBuffer = textBuffer; AstRoot = ast; }
public static ITextView MakeTextView(string content, out AstRoot ast) { return(MakeTextView(content, 0, out ast)); }
private static IKeywordScopeStatement GetFormatScope(ITextView textView, ITextBuffer textBuffer, AstRoot ast) { SnapshotPoint?caret = REditorDocument.MapCaretPositionFromView(textView); if (caret.HasValue) { try { int lineNumber = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(caret.Value.Position); ITextSnapshotLine line = textBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber); string lineText = line.GetText(); if (lineText.TrimEnd().EndsWith("}", StringComparison.Ordinal)) { IKeywordScopeStatement scopeStatement = ast.GetNodeOfTypeFromPosition <IKeywordScopeStatement>(caret.Value); return(scopeStatement); } } catch (Exception) { } } return(null); }
public RIntellisenseContext(IEditorIntellisenseSession session, IEditorBuffer editorBuffer, AstRoot ast, int position, bool autoShown = true, bool isRHistoryRequest = false) : base(session, editorBuffer, position) { AstRoot = ast; AutoShownCompletion = autoShown; IsRHistoryRequest = isRHistoryRequest; }
public void Accept(AstRoot ast) { }
public virtual void Accept(AstRoot ast) { }
private static AstNode ParseGiven(TokenStream stream) { GivenStatement switchStmt = new GivenStatement (stream.Location); stream.Expect (TokenClass.Keyword, "given"); stream.Expect (TokenClass.OpenParan); switchStmt.Add (ParseExpression (stream)); stream.Expect (TokenClass.CloseParan); stream.Expect (TokenClass.OpenBrace); AstNode defaultBlock = new AstRoot (stream.Location); AstRoot caseStatements = new AstRoot (stream.Location); while (!stream.EndOfStream && !stream.Match (TokenClass.CloseBrace)) { caseStatements.Add (ParseWhen (stream)); if (stream.Accept (TokenClass.Keyword, "default")) { defaultBlock = ParseStatement (stream); } } switchStmt.Add (caseStatements); switchStmt.Add (defaultBlock); stream.Expect (TokenClass.CloseBrace); return switchStmt; }
private static AstNode ParseFunction(TokenStream stream, bool prototype = false, ClassDeclaration cdecl = null) { if (stream.Accept (TokenClass.Operator, "@")) { /* * Function decorators in the form of * @myDecorator * func foo () { * } * are merely syntatic sugar for * func foo () { * } * foo = myDecorator (foo) */ AstNode expr = ParseExpression (stream); // Decorator expression /* This is the original function which is to be decorated */ FunctionDeclaration idecl = ParseFunction (stream, prototype, cdecl) as FunctionDeclaration; /* We must construct an arglist which will be passed to the decorator */ ArgumentList args = new ArgumentList (stream.Location); args.Add (new NameExpression (stream.Location, idecl.Name)); /* * Since two values can not be returned, we must return a single node containing both * the function declaration and call to the decorator */ AstRoot nodes = new AstRoot (stream.Location); nodes.Add (idecl); nodes.Add (new Expression (stream.Location, new BinaryExpression (stream.Location, BinaryOperation.Assign, new NameExpression (stream.Location, idecl.Name), new CallExpression (stream.Location, expr, args)))); return nodes; } stream.Expect (TokenClass.Keyword, "func"); bool isInstanceMethod; bool isVariadic; bool hasKeywordArgs; Token ident = stream.Expect (TokenClass.Identifier); List<string> parameters = ParseFuncParameters (stream, out isInstanceMethod, out isVariadic, out hasKeywordArgs); FunctionDeclaration decl = new FunctionDeclaration (stream.Location, ident != null ? ident.Value : "", isInstanceMethod, isVariadic, hasKeywordArgs, parameters); if (!prototype) { if (stream.Accept (TokenClass.Operator, "=>")) { decl.Add (new ReturnStatement (stream.Location, ParseExpression (stream))); } else { stream.Expect (TokenClass.OpenBrace); CodeBlock scope = new CodeBlock (stream.Location); if (stream.Match (TokenClass.Keyword, "super")) { scope.Add (ParseSuperCall (stream, cdecl)); } while (!stream.Match (TokenClass.CloseBrace)) { scope.Add (ParseStatement (stream)); } decl.Add (scope); stream.Expect (TokenClass.CloseBrace); } } return decl; }
public override void Accept (AstRoot ast) { ast.VisitChildren (this); }
public AstRoot Parse() { try { AstRoot root = new AstRoot (tokenStream.Location); while (!tokenStream.EndOfStream) { root.Add (ParseStatement (tokenStream)); } return root; } catch (Exception) { //this.tokenStream.ErrorLog.AddError (ErrorType.ParserError, ""); return new AstRoot (tokenStream.Location); } }
public void Accept(AstRoot ast) { visitSubnodes (ast); }
private void AddRankingSubGraphs(AstRoot ast) { _namespacesSubGraphs.Clear(); var maxNamespaceDepth = 1 + ast.Namespaces.Select(n => n.ParentSymbolsCount).Max(); Graph .AddSubGraph() .AddEdge( Enumerable .Range(1, maxNamespaceDepth) .Select(n => "Namespaces " + n) ) .AddSides( "Frames", "Basis Vectors", "Structures", "Subspaces", "Constants", "Macros" ) .SetPenWdith(0) .SetArrowSize(0); for (var i = 1; i <= maxNamespaceDepth; i++) { var subGraph = Graph .AddSubGraph("GMacAST Namespaces " + i) .SetRank(DotRankType.Same); subGraph .AddNode("Namespaces " + i) .SetLabel( Graph.Table("Namespace", "Namespaces " + i) ); _namespacesSubGraphs.Add(subGraph); } _framesSubGraph = Graph .AddSubGraph("GMacAST Frames") .SetRank(DotRankType.Same); _basisVectorsSubGraph = Graph .AddSubGraph("GMacAST Basis Vectors") .SetRank(DotRankType.Same); _subspacesSubGraph = Graph .AddSubGraph("GMacAST Subspaces") .SetRank(DotRankType.Same); _constsSubGraph = Graph .AddSubGraph("GMacAST Constants") .SetRank(DotRankType.Same); _structsSubGraph = Graph .AddSubGraph("GMacAST Structures") .SetRank(DotRankType.Same); _macrosSubGraph = Graph .AddSubGraph("GMacAST Macros") .SetRank(DotRankType.Same); _framesSubGraph.AddNode("Frames").SetLabel(Graph.Table("Frame", "Frames")); _basisVectorsSubGraph.AddNode("Basis Vectors").SetLabel(Graph.Table("BasisVector", "Basis Vectors")); _subspacesSubGraph.AddNode("Subspaces").SetLabel(Graph.Table("Subspace", "Subspaces")); _constsSubGraph.AddNode("Subspaces").SetLabel(Graph.Table("Constant", "Constants")); _structsSubGraph.AddNode("Subspaces").SetLabel(Graph.Table("Structure", "Structures")); _macrosSubGraph.AddNode("Macros").SetLabel(Graph.Table("Macro", "Macros")); }
public static IodineCompiler CreateCompiler (IodineContext context, AstRoot root) { SemanticAnalyser analyser = new SemanticAnalyser (context.ErrorLog); SymbolTable table = analyser.Analyse (root); return new IodineCompiler (context, table, root); }
internal void PopulateCompletionList(int position, ICompletionSession session, IList <CompletionSet> completionSets, AstRoot ast) { RCompletionContext context = new RCompletionContext(session, _textBuffer, ast, position); bool autoShownCompletion = true; if (session.TextView.Properties.ContainsProperty(CompletionController.AutoShownCompletion)) { autoShownCompletion = session.TextView.Properties.GetProperty <bool>(CompletionController.AutoShownCompletion); } IReadOnlyCollection <IRCompletionListProvider> providers = RCompletionEngine.GetCompletionForLocation(context, autoShownCompletion); Span applicableSpan = GetApplicableSpan(position, session); ITrackingSpan trackingSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(applicableSpan, SpanTrackingMode.EdgeInclusive); List <RCompletion> completions = new List <RCompletion>(); bool sort = true; foreach (IRCompletionListProvider provider in providers) { IReadOnlyCollection <RCompletion> entries = provider.GetEntries(context); Debug.Assert(entries != null); if (entries.Count > 0) { completions.AddRange(entries); } sort &= provider.AllowSorting; } if (sort) { completions.Sort(RCompletion.Compare); completions.RemoveDuplicates(); } CompletionSet completionSet = new RCompletionSet(_textBuffer, trackingSpan, completions); completionSets.Add(completionSet); }
private IodineCompiler (IodineContext context, SymbolTable symbolTable, AstRoot root) { this.context = context; this.symbolTable = symbolTable; this.root = root; }