public LanguageParser(Lexers.Lexer lexer) { TokenStream = new ParseableTokenStream(lexer); // we'll tag all lambdas we find starting from 1000 here // later when we iterate over scope and create anonnymous lambdas // we need the lambdas to have the SAME name even if we iterate over // the syntax tree multiple times. this is hacky, i know. // curried functions will be labeled from 0 to 1000 LambdaDeclr.LambdaCount = 1000; }
/// <summary> /// 新規にパーサーを作成します。 /// </summary> private Grammar CreateParser(AngleMode angleMode) { var sDelim = Scanners.IsWhitespaces().Many_(); var OPs = Terms.GetOperatorsInstance( "+", "-", "**", "*", "/", "%", "(", ")", ",", "#"); var lToken = OPs.Lexer | Lexers.LexDecimal() | Lexers.LexWord(); var lexeme = Lexers.Lexeme(sDelim, lToken).FollowedBy(Parsers.Eof()); var pNumber = Terms.OnDecimal((from, len, s) => double.Parse(s)); var pWord = Terms.OnWord((from, len, s) => s); Terms.FromSimpleToken <string, string>((from, len, s) => s); var pPlus = GetOperator(OPs, "+", new Binary((a, b) => (a + b))); var pMinus = GetOperator(OPs, "-", new Binary((a, b) => (a - b))); var pMul = GetOperator(OPs, "*", new Binary((a, b) => (a * b))); var pDiv = GetOperator(OPs, "/", new Binary((a, b) => (a / b))); var pMod = GetOperator(OPs, "%", new Binary((a, b) => (a % b))); var pPow = GetOperator(OPs, "**", new Binary((a, b) => Math.Pow(a, b))); var pNone = GetOperator(OPs, "+", new Unary(n => n)); var pNeg = GetOperator(OPs, "-", new Unary(n => - n)); var opTable = new OperatorTable <double>() .Infixl(pPlus, 10) .Infixl(pMinus, 10) .Infixl(pMul, 20) .Infixl(pDiv, 20) .Infixl(pMod, 20) .Infixr(pPow, 30) .Prefix(pNone, 40) .Prefix(pNeg, 40); var pLParen = OPs.GetParser("("); var pRParen = OPs.GetParser(")"); var pComma = OPs.GetParser(new string[] { ",", "#" }); var lazyExpr = new Grammar[1]; var pLazyExpr = Parsers.Lazy <double>(() => lazyExpr[0]); var pArg = pLazyExpr.SepEndBy(pComma).Between(pLParen, pRParen) | pLParen.Seq(pRParen).Seq(Parsers.Return(new double[0])); var pTerm = pLazyExpr.Between(pLParen, pRParen) | pWord.And(pArg.Optional(), new Map <string, double[], double>(CalcFunc)) | pNumber; var pExpr = Expressions.BuildExpressionParser(pTerm, opTable); lazyExpr[0] = pExpr; return(Parsers.ParseTokens(lexeme, pExpr.FollowedBy(Parsers.Eof()), "calculator")); }
public override void Initialize(IApp app) { base.Initialize(app); Lexers.ForEach(b => { var iface = default(Type); if ((iface = b.Type.GetInterface(typeof(ICodeLexer).FullName)) == null) { throw new ElideException("ICodeLexer '{0}' doesn't implement ICodeLexer interface.", b.Type); } LexerInstances.Add(b.Key, TypeCreator.New <ICodeLexer>(b.Type)); }); }
private void StyleSetItalic(Lexers.Cpp style, bool italic) { this.SendMessageDirect(Constants.SCI_STYLESETITALIC, (int)style, italic); }
public ExtInfo GetInfo(string section, string key) { ValidateSection(section); return(Lexers.FirstOrDefault(b => b.Key == key)); }
public IEnumerable <ExtInfo> EnumerateInfos(string section) { ValidateSection(section); return(Lexers.OfType <ExtInfo>().ToArray()); }