public static TokenWalker GetWalker(string source) { IEnumerable <Token> Tokens = GetTokens(source); TokenWalker Walker = new TokenWalker(Tokens); return(Walker); }
public SolutionParser(TokenWalker tokenWalker, HeaderParser headerParser, ProjectParser projectParser, GlobalSectionParser globalSectionParser) { _tokenWalker = tokenWalker; _headerParser = headerParser; _projectParser = projectParser; _globalSectionParser = globalSectionParser; }
/// <summary> /// Parsing the following Production: /// Factor := Tag | BoolConstant | Not Factor | "(" Expression ") /// </summary> public IParseNode Parse(TokenWalker walker) { if (walker.NextIs <TagToken>()) { var lexem = walker.Pop(); if (lexem.Token is TagToken tagToken && tagToken.Value is { } value) { return(new TagNode(value)); } } if (walker.NextIs <BoolConstantToken>()) { var lexem = walker.Pop(); if (lexem.Token is BoolConstantToken boolToken) { return(new BooleanNode(boolToken.Value)); } } if (walker.NextIs <NotToken>()) { walker.Pop(); return(new NotOperatorNode(Parse(walker))); } walker.ExpectOpeningParenthesis(); var result = _expressionParser.Parse(walker); walker.ExpectClosingParenthesis(); return(result); }
private void ParseProjects(TokenWalker tokenWalker, Solution solution) { while (tokenWalker.NextIs <BeginProjectToken>()) { _projectParser.Parse(tokenWalker, solution); } }
public void InitialTest() { TokenFactory elems = new TokenFactory(new SourceCode("instance class Dog{}")); TokenWalker walker = new TokenWalker(elems); Assert.AreEqual(walker.CurrentElement.Kind, SyntaxKeyword.Instance); }
public IParseNode Parse(TokenWalker walker) { Debug.Assert(TermParser != null); IParseNode result; if (walker.NextIs <MinusToken>()) { var lexem = walker.Pop(); result = new UnaryMinusOperator(TermParser.Parse(walker), lexem.Position); } else { result = TermParser.Parse(walker); } while (walker.NextIsLineOperator()) { var lexem = walker.Pop(); result = lexem.Token switch { MinusToken _ => new MinusOperator(result, TermParser.Parse(walker), lexem.Position), PlusToken _ => new PlusOperator(result, TermParser.Parse(walker), lexem.Position), _ => result }; } return(result); } }
public void Parse(TokenWalker tokenWalker, Solution solution) { ParseFormatVersion(tokenWalker, solution); ParseVersionComment(tokenWalker); solution.VisualStudioVersion = ParseVariable(tokenWalker, "VisualStudioVersion"); solution.MinimumVisualStudioVersion = ParseVariable(tokenWalker, "MinimumVisualStudioVersion"); }
public static void ExpectClosingParenthesis(this TokenWalker walker) { if (!walker.NextIs <ClosedParenthesisToken>()) { throw new ExpectedTokenException(new ClosedParenthesisToken(), walker.Peek().Token ?? new EpsilonToken()); } walker.Pop(); }
public static void ExpectClosingParenthesis(this TokenWalker walker) { if (!(walker.NextIs <ClosedParenthesisToken>())) { throw new Exception("Expecting ')' in expression, instead got: " + (walker.Peek() != null ? walker.Peek().Token.ToString() : "End of expression")); } walker.Pop(); }
public static void ExpectOpeningParenthesis(this TokenWalker walker) { if (!walker.NextIs <OpenParenthesisToken>()) { throw new Exception("Expecting Real number or '(' in expression, instead got : " + (walker.Peek() != null ? walker.Peek().Token.ToString() : "End of expression")); } walker.Pop(); }
public void Parse(TokenWalker tokenWalker, Solution solution) { while (tokenWalker.NextIs <EndGlobalSectionToken>() == false) { var property = tokenWalker.ConsumeVariable(); solution.TfsControlProperties.Add(new TfsControlProperty(property.Key, property.Value)); } }
public void Parse(TokenWalker tokenWalker, Solution solution) { while (tokenWalker.NextIs <EndGlobalSectionToken>() == false) { var variable = tokenWalker.ConsumeVariable(); solution.Platforms.Add(new PlatformConfiguration(variable.Key, variable.Value)); tokenWalker.ConsumeAllWhiteSpace(); } }
public void MoveWalkerTest() { TokenFactory elems = new TokenFactory(new SourceCode("instance class Dog{}")); TokenWalker walker = new TokenWalker(elems); walker.GetNext(); walker.GetNext(); Assert.AreEqual(walker.CurrentElement.Kind, SyntaxKeyword.Class); }
public FolderScanner(IConsoleWriter consoleWriter) { _consoleWriter = consoleWriter; var lexerRules = new LexerRules(); var tokenizer = new Tokenizer(lexerRules, e => new LexerReader(e), lexems => new LinePositionCalculator(lexems)); _tokenWalker = new TokenWalker(tokenizer, () => new EpsilonToken(), lexems => new LinePositionCalculator(lexems)); _wordCount = new Dictionary <string, int>(); }
public void Parse(TokenWalker tokenWalker, Solution solution) { while (tokenWalker.NextIs <EndGlobalSectionToken>() == false) { var config = tokenWalker.ConsumeVariable(); SetProjectConfiguration(ExtractProject(config.Key, solution), ExtractPlatform(config.Key, solution), ExtractConfig(config.Key), config.Value); } }
public void Parse(TokenWalker tokenWalker, Project project) { while (tokenWalker.NextIs <EndProjectSectionToken>() == false) { var variable = tokenWalker.ConsumeVariable(); tokenWalker.ConsumeAllWhiteSpace(); project.SolutionItems.Add(new SolutionItem(variable.Key, variable.Value)); } }
public void Parse(TokenWalker tokenWalker, Project project) { while (tokenWalker.NextIs <EndProjectSectionToken>() == false) { var variable = tokenWalker.ConsumeVariable(); tokenWalker.ConsumeAllWhiteSpace(); project.Dependencies.Add(new Dependency(Guid.Parse(variable.Key), Guid.Parse(variable.Value))); } }
private Version ParseVariable(TokenWalker tokenWalker, string variableName) { var variable = _variableParser.ParseVersion(tokenWalker); if (variable.Name != variableName) { throw new ParseException($"Expected Variable {variableName} but got {variable.Name}"); } return(variable.Value); }
private static NumberNode CreateNumberNode(TokenWalker walker) { var lexem = walker.Pop(); if (lexem.Token is NumberToken) { return(new NumberNode(lexem)); } throw new Exception("Expecting Real number but got something else"); }
/// <summary> /// Overloaded Parse function to parse a Function /// </summary> /// <param name="walker">Lexer input</param> /// <returns></returns> public IParseNode Parse(TokenWalker walker) { var lexem = walker.Pop(); if (lexem.Token is IdentifierToken) { return(new VariableNode(lexem)); } throw new ArgumentNullException(); }
private void ParseGlobalSections(TokenWalker tokenWalker, Solution solution) { tokenWalker.Consume <BeginGlobalToken>(); tokenWalker.ConsumeAllWhiteSpace(); while (tokenWalker.NextIs <BeginGlobalSectionToken>()) { _globalSectionParser.Parse(tokenWalker, solution); } tokenWalker.Consume <EndGlobalToken>(); }
private void Parse(TokenWalker tokenWalker, Solution solution) { _headerParser.Parse(tokenWalker, solution); ParseProjects(tokenWalker, solution); ParseGlobalSections(tokenWalker, solution); // any whitespace left... tokenWalker.ConsumeAllWhiteSpace(); // Verify that we are at the end of the file tokenWalker.Consume <EpsilonToken>(); }
public IParseNode Parse(TokenWalker walker) { var result = _factorParser.Parse(walker); while (walker.NextIs <PowerToken>()) { var lexem = walker.Pop(); result = new PowerOperator(result, _factorParser.Parse(walker), lexem.Position); } return(result); }
public void IsBack_goNext() { List <Token> rawTokens; var tkns = TokenWalker.WrapWalker(rawTokens = new List <Token>() { Token.A, Token.B, Token.C, Token.D, Token.E }); tkns.Next(2); tkns.IsBack(Token.B, gotNextIfTrue: true).Should().BeTrue(); tkns.IsBack(Token.C, gotNextIfTrue: true).Should().BeTrue(); }
internal void Parse(TokenWalker tokenWalker, Solution solution) { tokenWalker.Consume <BeginProjectToken>(); var project = ParseProject(tokenWalker); ParseProjectSection(tokenWalker, project); solution.Projects.Add(project); tokenWalker.Consume <EndProjectToken>(); tokenWalker.Consume <NewLineToken>(); }
public void SkipWhitespaceTest() { SourceCode source = new SourceCode(" \nclass"); TokenFactory elems = new TokenFactory(source); TokenWalker walker = new TokenWalker(elems); walker.SkipWhitespace(); Token current = walker.CurrentElement; Assert.AreEqual(current.Kind, SyntaxKeyword.Class); Assert.AreEqual(current.Context, new SourceContext(3, 5)); }
public void TestParsingMissingToken() { string source = "variable123"; TokenWalker Walker = TestTools.GetWalker(source); NodeParser Parser = Keep(SyntaxKeyword.Assignment).Name("Identifier"); Node expression = null; Assert.Throws <FailedParsingNodeException>(() => Parser.Parse(ref expression, Walker, out _)); Assert.IsNull(expression); }
public void TestParseSingleToken() { string source = "variable123"; TokenWalker Walker = TestTools.GetWalker(source); NodeParser Parser = Keep(SyntaxKeyword.Identifier).Name("Identifier"); Node expression = null; Parser.Parse(ref expression, Walker, out _); Assert.IsNotNull(expression); }
public void ApplyOnlyIfTrue2() { List <Token> rawTokens; var tkns = TokenWalker.WrapWalker(rawTokens = new List <Token>() { Token.A, Token.B, Token.C, Token.D, Token.E }); tkns.Next(2); tkns.ApplyOnlyIfTrue(() => tkns.SkipNext(Token.D, Token.E, Token.E)).Should().BeFalse(); tkns.HasBack.Should().BeTrue(); tkns.Current.Should().Be(Token.C); }
public void Parse(TokenWalker tokenWalker, Solution solution) { while (tokenWalker.NextIs <EndGlobalSectionToken>() == false) { tokenWalker.ConsumeAllWhiteSpace(); tokenWalker.ConsumeWord(SolutionGuidKey); tokenWalker.ConsumeAllWhiteSpace(); tokenWalker.Consume <AssignToken>(); tokenWalker.ConsumeAllWhiteSpace(); solution.Guid = tokenWalker.ConsumeGuid(); tokenWalker.ConsumeAllWhiteSpace(); } }
public PageFactory(ViewTokenizer viewBindingParser, TokenWalker tokenWalker) { _viewBindingParser = viewBindingParser; _tokenWalker = tokenWalker; _visitors = typeof(IVisitor).GetSubclassesOf(true).Select(GetInstance).ToList(); }