• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Lexer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Lexer的典型用法代码示例。如果您正苦于以下问题:C# Lexer类的具体用法?C# Lexer怎么用?C# Lexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Lexer类属于命名空间,在下文中一共展示了Lexer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Detect

        internal override void Detect(Lexer l)
        {
            if (l.Text.TrimStart().StartsWith("#") &&
                (l.MatchNext(" ") || l.MatchNext("\n")) &&
                l.Text != "#import" &&
                l.Text != "#include")
                l.TakeOwnership();
            else if (!l.Text.TrimStart().StartsWith("#") || l.Text == "#import" || l.Text == "#include")
                l.ForceExclude();

            if (l.HasOwnership())
            {
                if (l.Char == '\\' && l.MatchNext("\n"))
                {
                    this.m_KeepOwnership = true;
                }
                else if (l.Char == '\n' && !this.m_KeepOwnership)
                {
                    l.AddNode(new DirectNode(l.Text));
                    l.EndOwnership();
                }
                else if (this.m_KeepOwnership)
                    this.m_KeepOwnership = false;
            }
        }
开发者ID:hach-que,项目名称:Monocle-Engine,代码行数:25,代码来源:PreprocessorIgnoreToken.cs


示例2: ArrayAssignment

        private static Nodes.Assignment ArrayAssignment(Lexer.Lexem currLexem, Nodes.Node.Coords coords)
        {
            Nodes.Expression index = Expr();
            if (Lexer.LookAhead().LexType != Lexer.LexType.CloseSquadBracket)
                ErrorList.Add(new Error(ParserException.NeedCloseSquadBracket, Lexer.LookBack().EndCoords));
            else
                Lexer.NextLexem();

            if (Lexer.LookAhead().LexType == Lexer.LexType.EqualSign)
            {
                Lexer.NextLexem();
                Nodes.Expression value = Expr();
                /*if (Lexer.LookAhead().LexType != Lexer.LexType.Semicolon)
                    ErrorList.Add(new Error(ParserException.NeedSemicolon, Lexer.LookBack().EndCoords));
                else
                    Lexer.NextLexem();*/
                Nodes.Assignment result = new Nodes.Assignment(new Nodes.ElementOfArray(currLexem.VarName, index), value, coords);
                result.Head = result;
                result.Tail = result;
                return result;
            }
            else
            {
                while (Lexer.LookBack().LexType != Lexer.LexType.Variable)
                    Lexer.RollBack();
                Lexer.RollBack();
                return null;
            }
        }
开发者ID:shurik111333,项目名称:spbu,代码行数:29,代码来源:Parser.cs


示例3: Lexer_CanIdentifyNumberTokens

 public void Lexer_CanIdentifyNumberTokens(string input, double expectedValue)
 {
     var lexer = new Lexer(input);
     Assert.IsTrue(lexer.Next());
     Assert.AreEqual(TokenType.Number, lexer.CurrentToken.Type);
     Assert.AreEqual(expectedValue, (double)(Number)lexer.CurrentToken.Value);
 }
开发者ID:ChaosPandion,项目名称:Calculate,代码行数:7,代码来源:LexerTests.cs


示例4: matchMembers

    /// <summary>
    /// Count the number of words in this list that matches in the phrase
    /// </summary>
    /// <param name="lexer">The words to match</param>
    /// <param name="count">The number of words that match [out]</param>
    /// <returns>Score for the match: 0 if no match</returns>
    internal double matchMembers(Lexer lexer, out int count)
    {
        var cnt = 0  ; // The number of words that match
          var score=0.0; // The score to match

          // for each of the remaining words
          while (!lexer.EOF)
          {
         lexer.Preprocess();
         var word =lexer.Symbol();

         // See if it matches a modifier
         double score1 = matchMembers(word);

         // check for a minimum score
         if (score1 <= 0.0) break;

         // Update the tracking info
         cnt++;
         score += score1;
          }

          // return the results
          count = cnt;
          return score;
    }
开发者ID:randym32,项目名称:InteractiveText-CS,代码行数:32,代码来源:WordList-Match.cs


示例5: Main

 public static void Main(string[] args)
 {
     while (true)
     {
         try
         {
             string s = Console.ReadLine();
             Lexer l = new Lexer();
             Parser p = new Parser(l.Lex(s));
             Ast.Chunk c = p.Parse();
             Compiler.Compiler cplr = new SharpLua.Compiler.Compiler();
             LuaFile proto = cplr.Compile(c, "<stdin>");
             Console.WriteLine("compiled!");
             FileStream fs = File.Open("out.sluac", FileMode.Create);
             foreach (char ch in proto.Compile())
             {
                 //Console.WriteLine(ch + " " + (int)ch);
                 fs.WriteByte((byte)ch);
             }
             fs.Close();
             Console.WriteLine("written to out.sluac!");
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     Console.Write("Press any key to continue . . . ");
     Console.ReadKey(true);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:30,代码来源:Program.cs


示例6: match

 /// <summary>
 /// Finds the object that best matches the phrase
 /// </summary>
 /// <param name="phrase">The words to match</param>
 /// <param name="index">The first word in phrase to match</param>
 /// <param name="score">The score for the best match: 0 if no match[out]</param>
 /// <param name="numWordsMatch">The number of words that match [out]</param>
 /// <param name="bestMatch">The object that best matches [out]</param>
 /// <param name="seen">Set of objects already examined</param>
 public void match(Lexer lexer, ref double score,
            ref int numWordsMatch,
            ref object bestMatch,
            ref LexState lexerState, Dictionary<object,object> seen)
 {
     // Skip if we've already seen this object
       if (seen.ContainsKey(this))
      return;
       // Add ourself to prevent cycles
       seen[this] = this;
     //      edge.match(lexer, ref score, ref numWordsMatch, ref bestMatch, ref lexerState, seen);
     #if true
       /// We only check to see if the gate matches the phrase
       if (null != edge.gate)
      edge.gate.match(lexer, ref score, ref numWordsMatch,
                          ref bestMatch, ref lexerState, seen);
       // Should only match if no door, or door is open
       if (null != edge.sink && (null == edge.gate || isOpen(edge.gate)))
       {
      // we only want match -- matchInContext checks the stuff from the parents..
      edge.sink.match(lexer, ref score, ref numWordsMatch,
                  ref bestMatch, ref lexerState, seen);
       }
     #endif
 }
开发者ID:randym32,项目名称:InteractiveText-CS,代码行数:34,代码来源:ZEdge.cs


示例7:

 public ILexerConfig this[Lexer lexer]
 {
     get
     {
         return this[(int)lexer];
     }
 }
开发者ID:nguyenhuuhuy,项目名称:mygeneration,代码行数:7,代码来源:LexerConfigCollection.cs


示例8: ShouldDistinguishTwoDigitOperatorsStartingWithSameChar

 public void ShouldDistinguishTwoDigitOperatorsStartingWithSameChar()
 {
     var lexer = new Lexer("= ==");
     AssertTokenIs("=", lexer.Next());
     AssertTokenIs("==", lexer.Next());
     AssertTokenIs("EOF", lexer.Next());
 }
开发者ID:jordanwallwork,项目名称:jello,代码行数:7,代码来源:LexerTests.cs


示例9: ShouldRecognizeNumbers

 public void ShouldRecognizeNumbers()
 {
     var lexer = new Lexer("1 2.3 4.56789");
     AssertTokenIs("number", 1, lexer.Next());
     AssertTokenIs("number", 2.3, lexer.Next());
     AssertTokenIs("number", 4.56789, lexer.Next());
 }
开发者ID:jordanwallwork,项目名称:jello,代码行数:7,代码来源:LexerTests.cs


示例10: Parse

        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "Pattern " + Type.Name);
            
            int start = lexer.Position;
            
            if (state.Excluded.Contains(this))
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.CurrentSource(), "Excluded");
                return ParseTree.No;
            }
            
		    Precedence oldCurrentPrecedence = state.CurrentPrecedence;
		    
		    if (Precedence.Overwrites(state.CurrentPrecedence))
		        state.CurrentPrecedence = Precedence;

            ParseTree tree = ParseGraph.Parse(lexer, state);
            
            state.CurrentPrecedence = oldCurrentPrecedence;

            if (tree == ParseTree.No)
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start));
                return ParseTree.No;
            }

            state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
            
            return tree;
        }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:31,代码来源:AbstractPattern.cs


示例11: ProcessToken

        protected override ResultOfProcess ProcessToken(Lexer.Token token)
        {
            this.Context.Recovery(token);

            var tmpExpressionStatementLeaf = new Syntaxer.StatementLeafs.ExpressionStatementLeaf(this.Context);

            var tmpRez = tmpExpressionStatementLeaf.Run();

            var tmpResultNode = tmpExpressionStatementLeaf.Result;

            if (mCurrStatement == null)
            {
                mCurrStatement = tmpResultNode;

                mMainCodeBlock.FirstStatement = mCurrStatement;
            }
            else
            {
                mCurrStatement.NextStatement = tmpResultNode;

                mCurrStatement = tmpResultNode;
            }

            return tmpRez;
        }
开发者ID:metatypeman,项目名称:stillOneScript,代码行数:25,代码来源:MainLeaf.cs


示例12: CorrectLineAndColumnNumbers

        public void CorrectLineAndColumnNumbers()
        {
            var input = "Hello World!\nSecond line\r\nFoo";

            MemoryStream m = new MemoryStream();
            var w = new StreamWriter(m);
            w.Write(input);
            w.Flush();
            m.Position = 0;

            var word = new Terminal("Word", "\\S+");
            var whitespace = new Terminal("Whitespace", " |\n|\r");

            var lexer = new Lexer(m, word, whitespace);
            Token[] tokens = lexer.ToArray();

            Assert.AreEqual(10, tokens.Length);
            AssertToken(tokens[0], "Word", 1, 1);
            AssertToken(tokens[1], "Whitespace", 1, 6);
            AssertToken(tokens[2], "Word", 1, 7);
            AssertToken(tokens[3], "Whitespace", 1, 13);
            AssertToken(tokens[4], "Word", 2, 1);
            AssertToken(tokens[5], "Whitespace", 2, 7);
            AssertToken(tokens[6], "Word", 2, 8);
            AssertToken(tokens[7], "Whitespace", 2, 12);
            AssertToken(tokens[8], "Whitespace", 2, 13);
            AssertToken(tokens[9], "Word", 3, 1);
        }
开发者ID:martindevans,项目名称:Hermes,代码行数:28,代码来源:LexerTest.cs


示例13: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     lexer.Whitespace(state.RuntimeState);
     
     int start = lexer.Position;
     
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), range.ToString());
     
     char character = lexer.Peek();
     
     if (!range.Contains(character))
     {
         lexer.ErrorStrings[start].Add(range.ToString());
         
         state.RuntimeState.Runtime.ParseTrace.No(this,
             lexer.SourceFrom(start), TextEscape.Quote(character));
         
         return ParseTree.No;
     }
     
     lexer.Read();
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this,
         lexer.SourceFrom(start), TextEscape.Quote(character));
     
     if (state.BuildTextNodes)
         return new ParseTree(Convert.ToString(character));
     else
         return ParseTree.Yes;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:30,代码来源:CharNode.cs


示例14: Test

        /// <summary>
        /// Parses the given chunk of code and verifies that it matches the expected pretty-printed result
        /// </summary>
        /// <param name="source"></param>
        /// <param name="expected"></param>
        public void Test(string source, string expected)
        {
            var lexer = new Lexer(source);
            Parser parser = new BantamParser(lexer);

            try
            {
                var result = parser.ParseExpression();
                var builder = new StringBuilder();
                result.Print(builder);
                var actual = builder.ToString();

                if (expected.Equals(actual))
                {
                    _passed++;
                }
                else
                {
                    _failed++;
                    Console.Out.WriteLine("[FAIL] Expected: " + expected);
                    Console.Out.WriteLine("         Actual: " + actual);
                }
            }
            catch (ParseException ex)
            {
                _failed++;
                Console.Out.WriteLine("[FAIL] Expected: " + expected);
                Console.Out.WriteLine("          Error: " + ex.Message);
            }
        }
开发者ID:modulexcite,项目名称:graveyard,代码行数:35,代码来源:PortedTests.cs


示例15: ModuleDefinitionLoader

 public ModuleDefinitionLoader(IServiceProvider services, string filename, byte[] bytes) : base(services, filename, bytes)
 {
     this.filename = filename;
     this.lexer = new Lexer( new StreamReader(new MemoryStream(bytes)));
     this.bufferedTok = null;
     this.arch = new Reko.Arch.X86.X86ArchitectureFlat32();
 }
开发者ID:gh0std4ncer,项目名称:reko,代码行数:7,代码来源:ModuleDefinitionLoader.cs


示例16: ShouldRecordPositionOfTokens

 public void ShouldRecordPositionOfTokens()
 {
     var lexer = new Lexer("one\ntwo\nthree");
     Assert.AreEqual(1, lexer.Next().LineNo);
     Assert.AreEqual(2, lexer.Next().LineNo);
     Assert.AreEqual(3, lexer.Next().LineNo);
 }
开发者ID:jordanwallwork,项目名称:jello,代码行数:7,代码来源:LexerTests.cs


示例17: ShouldReportErrorForUnclosedString

 public void ShouldReportErrorForUnclosedString()
 {
     var lexer = new Lexer("\"the cow said \\\"moo\\\"");
     AssertTokenIs("string", "the cow said \"moo\"", lexer.Next());
     Assert.AreEqual(lexer.Errors.Count, 1);
     Assert.AreEqual("String not closed - Unexpected end of file", lexer.Errors[0].Message);
 }
开发者ID:jordanwallwork,项目名称:jello,代码行数:7,代码来源:LexerTests.cs


示例18: ReadFile

 public void ReadFile()
 {
     Lexer lexer = new Lexer();
     Parser parser = new Parser();
     var lines = GetFileTextLinesAsync().ToList();
     List<Block> block = new List<Block>();
     for (int i = 0; i < lines.Count; i++)
     {
         var tokenList = lexer.ReadLine(lines[i], i);
         foreach (var item in tokenList)
         {
             do
             {
                 parser.Push(item);
             } while (parser.IsLoopingForReduce);
             if (parser.IsAccepted)
             {
                 block.Add(parser.Block);
                 parser.Reset();
                 if (block[block.Count - 1].BlockType == BlockTypes.SETTINGS)
                 /// ACC will not push current item,
                 /// it will cause error
                 {
                     parser.Push(item);
                 }
             }
         }
     }
     Block = block.ToArray();
 }
开发者ID:kirenamusumesan,项目名称:ProjectAsahi,代码行数:30,代码来源:Program.cs


示例19: Check

        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal attval;
            bool hasAlt = false;
            bool hasHref = false;

            node.CheckUniqueAttributes(lexer);

            for (attval = node.Attributes; attval != null; attval = attval.Next)
            {
                Attribute attribute = attval.CheckAttribute(lexer, node);

                if (attribute == AttributeTable.AttrAlt)
                {
                    hasAlt = true;
                }
                else if (attribute == AttributeTable.AttrHref)
                {
                    hasHref = true;
                }
            }

            if (!hasAlt)
            {
                lexer.BadAccess |= Report.MISSING_LINK_ALT;
                Report.AttrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE);
            }
            if (!hasHref)
            {
                Report.AttrError(lexer, node, "href", Report.MISSING_ATTRIBUTE);
            }
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:32,代码来源:AreaCheckTableCheckAttribs.cs


示例20: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //GridView1.DataSource = bll.GetScrollMatchList();
            //GridView1.DataBind();
            WebClient web = WebClientBLL.getWebClient();
            string s = web.DownloadString("http://data.nowscore.com/detail/403052.html");
            Lexer lexer = new Lexer(s);
            Parser parser = new Parser(lexer);
            INode tableNode = parser.Parse(new TagNameFilter("HTML"))[0].Children.ExtractAllNodesThatMatch(new TagNameFilter("BODY"))[0].Children[0];
            TableTag tt = tableNode as TableTag;

            Response.Write(tt.GetRow(0).Columns[0].Children[0].Children[0].ToPlainTextString());
            Response.Write(tt.GetRow(0).Columns[1].Children[0].Children[0].ToPlainTextString());
            Response.Write(tt.GetRow(0).Columns[2].Children[0].Children[0].ToPlainTextString());

            //ITag divNode = bodyNodes.ExtractAllNodesThatMatch(new TagNameFilter("FORM"))[0].Children.ExtractAllNodesThatMatch(new TagNameFilter("DIV"))[0] as ITag;
            //if (divNode.Attributes["ID"].Equals("PageBody"))
            //{
            //    NodeList dataDivList = divNode.Children.SearchFor(typeof(Winista.Text.HtmlParser.Tags.Div));

            //}
        }
    }
开发者ID:opo30,项目名称:bet-helper,代码行数:25,代码来源:Default4.aspx.cs



注:本文中的Lexer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# LexerMode类代码示例发布时间:2022-05-24
下一篇:
C# LexState类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap