当前位置: 首页>>代码示例>>C#>>正文


C# StringLiteral.AddStartEnd方法代码示例

本文整理汇总了C#中StringLiteral.AddStartEnd方法的典型用法代码示例。如果您正苦于以下问题:C# StringLiteral.AddStartEnd方法的具体用法?C# StringLiteral.AddStartEnd怎么用?C# StringLiteral.AddStartEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringLiteral的用法示例。


在下文中一共展示了StringLiteral.AddStartEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExpressionEvaluatorGrammar

        public ExpressionEvaluatorGrammar() : base(caseSensitive: false)
        {
            this.GrammarComments =
      @"Irony expression evaluator. Case-insensitive. Supports big integers, float data types, variables, assignments,
arithmetic operations, augmented assignments (+=, -=), inc/dec (++,--), strings with embedded expressions; 
bool operations &,&&, |, ||; ternary '?:' operator.";
            // 1. Terminals
            var number = new NumberLiteral("number");
            //Let's allow big integers (with unlimited number of digits):
            number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
            var identifier = new IdentifierTerminal("identifier");
            var comment = new CommentTerminal("comment", "#", "\n", "\r");
            //comment must be added to NonGrammarTerminals list; it is not used directly in grammar rules,
            // so we add it to this list to let Scanner know that it is also a valid terminal. 
            base.NonGrammarTerminals.Add(comment);
            var comma = ToTerm(",");

            //String literal with embedded expressions  ------------------------------------------------------------------
            var stringLit = new StringLiteral("string", "\"", StringOptions.AllowsAllEscapes | StringOptions.IsTemplate);
            stringLit.AddStartEnd("'", StringOptions.AllowsAllEscapes | StringOptions.IsTemplate);
            stringLit.AstConfig.NodeType = typeof(StringTemplateNode);
            var Expr = new NonTerminal("Expr"); //declare it here to use in template definition 
            var templateSettings = new StringTemplateSettings(); //by default set to Ruby-style settings 
            templateSettings.ExpressionRoot = Expr; //this defines how to evaluate expressions inside template
            this.SnippetRoots.Add(Expr);
            stringLit.AstConfig.Data = templateSettings;
            //--------------------------------------------------------------------------------------------------------

            // 2. Non-terminals
            var Term = new NonTerminal("Term");
            var BinExpr = new NonTerminal("BinExpr", typeof(BinaryOperationNode));
            var ParExpr = new NonTerminal("ParExpr");
            var UnExpr = new NonTerminal("UnExpr", typeof(UnaryOperationNode));
            var TernaryIfExpr = new NonTerminal("TernaryIf", typeof(IfNode));
            var ArgList = new NonTerminal("ArgList", typeof(ExpressionListNode));
            var FunctionCall = new NonTerminal("FunctionCall", typeof(FunctionCallNode));
            var MemberAccess = new NonTerminal("MemberAccess", typeof(MemberAccessNode));
            var IndexedAccess = new NonTerminal("IndexedAccess", typeof(IndexedAccessNode));
            var ObjectRef = new NonTerminal("ObjectRef"); // foo, foo.bar or f['bar']
            var UnOp = new NonTerminal("UnOp");
            var BinOp = new NonTerminal("BinOp", "operator");
            var PrefixIncDec = new NonTerminal("PrefixIncDec", typeof(IncDecNode));
            var PostfixIncDec = new NonTerminal("PostfixIncDec", typeof(IncDecNode));
            var IncDecOp = new NonTerminal("IncDecOp");
            var AssignmentStmt = new NonTerminal("AssignmentStmt", typeof(AssignmentNode));
            var AssignmentOp = new NonTerminal("AssignmentOp", "assignment operator");
            var Statement = new NonTerminal("Statement");
            var Program = new NonTerminal("Program", typeof(StatementListNode));

            // 3. BNF rules
            Expr.Rule = Term | UnExpr | BinExpr | PrefixIncDec | PostfixIncDec | TernaryIfExpr;
            Term.Rule = number | ParExpr | stringLit | FunctionCall | identifier | MemberAccess | IndexedAccess;
            ParExpr.Rule = "(" + Expr + ")";
            UnExpr.Rule = UnOp + Term + ReduceHere();
            UnOp.Rule = ToTerm("+") | "-" | "!";
            BinExpr.Rule = Expr + BinOp + Expr;
            BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "**" | "==" | "<" | "<=" | ">" | ">=" | "!=" | "&&" | "||" | "&" | "|";
            PrefixIncDec.Rule = IncDecOp + identifier;
            PostfixIncDec.Rule = identifier + PreferShiftHere() + IncDecOp;
            IncDecOp.Rule = ToTerm("++") | "--";
            TernaryIfExpr.Rule = Expr + "?" + Expr + ":" + Expr;
            MemberAccess.Rule = Expr + PreferShiftHere() + "." + identifier;
            AssignmentStmt.Rule = ObjectRef + AssignmentOp + Expr;
            AssignmentOp.Rule = ToTerm("=") | "+=" | "-=" | "*=" | "/=";
            Statement.Rule = AssignmentStmt | Expr | Empty;
            ArgList.Rule = MakeStarRule(ArgList, comma, Expr);
            FunctionCall.Rule = Expr + PreferShiftHere() + "(" + ArgList + ")";
            FunctionCall.NodeCaptionTemplate = "call #{0}(...)";
            ObjectRef.Rule = identifier | MemberAccess | IndexedAccess;
            IndexedAccess.Rule = Expr + PreferShiftHere() + "[" + Expr + "]";

            Program.Rule = MakePlusRule(Program, NewLine, Statement);

            this.Root = Program;       // Set grammar root

            // 4. Operators precedence
            RegisterOperators(10, "?");
            RegisterOperators(15, "&", "&&", "|", "||");
            RegisterOperators(20, "==", "<", "<=", ">", ">=", "!=");
            RegisterOperators(30, "+", "-");
            RegisterOperators(40, "*", "/");
            RegisterOperators(50, Associativity.Right, "**");
            RegisterOperators(60, "!");
            // For precedence to work, we need to take care of one more thing: BinOp. 
            //For BinOp which is or-combination of binary operators, we need to either 
            // 1) mark it transient or 2) set flag TermFlags.InheritPrecedence
            // We use first option, making it Transient.  

            // 5. Punctuation and transient terms
            MarkPunctuation("(", ")", "?", ":", "[", "]");
            RegisterBracePair("(", ")");
            RegisterBracePair("[", "]");
            MarkTransient(Term, Expr, Statement, BinOp, UnOp, IncDecOp, AssignmentOp, ParExpr, ObjectRef);

            // 7. Syntax error reporting
            MarkNotReported("++", "--");
            AddToNoReportGroup("(", "++", "--");
            AddToNoReportGroup(NewLine);
            AddOperatorReportGroup("operator");
            AddTermsReportGroup("assignment operator", "=", "+=", "-=", "*=", "/=");
//.........这里部分代码省略.........
开发者ID:HyperSharp,项目名称:Hyperspace.DotLua,代码行数:101,代码来源:ExpressionEvaluatorGrammar.cs

示例2: CreateStringLiteral

 private StringLiteral CreateStringLiteral(string name)
 {
     var term = new StringLiteral(name);
     term.AddStartEnd("\"", StringOptions.AllowsAllEscapes);
     term.AddStartEnd("'", StringOptions.AllowsDoubledQuote | StringOptions.AllowsOctalEscapes | StringOptions.AllowsUEscapes | StringOptions.AllowsXEscapes);
     return term;
 }
开发者ID:Karapuska,项目名称:Totem,代码行数:7,代码来源:TotemGrammar.Literals.cs

示例3: CreatePythonString

    public static StringLiteral CreatePythonString(string name) {
      StringLiteral term = new StringLiteral(name);
      term.AddStartEnd("'", StringOptions.AllowsAllEscapes);
      term.AddStartEnd("'''", StringOptions.AllowsAllEscapes | StringOptions.AllowsLineBreak);
      term.AddStartEnd("\"", StringOptions.AllowsAllEscapes);
      term.AddStartEnd("\"\"\"", StringOptions.AllowsAllEscapes | StringOptions.AllowsLineBreak);

      term.AddPrefix("u", StringOptions.AllowsAllEscapes);
      term.AddPrefix("r", StringOptions.NoEscapes );
      term.AddPrefix("ur", StringOptions.NoEscapes);
 
      return term;
    }
开发者ID:anukat2015,项目名称:sones,代码行数:13,代码来源:TerminalFactory.cs

示例4: CreateZodiacString

 public static StringLiteral CreateZodiacString(string name)
 {
     StringLiteral term = new StringLiteral(name);
     //term.AddStartEnd("'", StringOptions.AllowsAllEscapes);// AllowLineBreak??
     term.AddStartEnd("\"", StringOptions.AllowsAllEscapes);// AllowLineBreak??
     return term;
 }
开发者ID:zackszhu,项目名称:ZodiacLanguage,代码行数:7,代码来源:ZodiacTerminalFactory.cs

示例5: CreateVbString

 public static StringLiteral CreateVbString(string name) {
   StringLiteral term = new StringLiteral(name);
   term.AddStartEnd("\"", StringOptions.NoEscapes | StringOptions.AllowsDoubledQuote);
   term.AddSuffix("$", TypeCode.String);
   term.AddSuffix("c", TypeCode.Char);
   return term;
 }
开发者ID:anukat2015,项目名称:sones,代码行数:7,代码来源:TerminalFactory.cs

示例6: ODataFilterGrammar

    public ODataFilterGrammar() {
      //Terminals

      var simpleIdentifier = TerminalFactory.CreateCSharpIdentifier("Identifier");
      var stringLiteral = new StringLiteral("StringLiteral", "'", StringOptions.NoEscapes | StringOptions.AllowsDoubledQuote);
      var numberLiteral = new NumberLiteral("NumberLiteral");
      
      // This impl has problems with .NET 4.5 - so ToTerm methods below were used instead.
      //var constant = new ConstantTerminal("Constant", typeof(Object));
      //constant.Add("true", true);
      //constant.Add("false", false);
      //constant.Add("null", null);
      var trueLiteral = ToTerm("true", "Constant");
      var falseLiteral = ToTerm("false", "Constant");
      var nullLiteral = ToTerm("null", "Constant");

      var dateTimeOffsetLiteral = new StringLiteral("DateTimeOffsetLiteral");
      dateTimeOffsetLiteral.AddStartEnd("datetimeoffset'","'", StringOptions.None);
      var dateTimeLiteral = new StringLiteral("DateTimeLiteral");
      dateTimeLiteral.AddStartEnd("datetime'", "'", StringOptions.None);
      var timeLiteral = new StringLiteral("TimeLiteral");
      timeLiteral.AddStartEnd("time'", "'", StringOptions.None);
      var guidLiteral = new StringLiteral("GuidLiteral");
      guidLiteral.AddStartEnd("guid'", "'", StringOptions.None);

      //NonTerminals
      var baseExpr = new NonTerminal("BaseExpr");
      var compositeIdentifier = new NonTerminal("CompositeIdentifier");
      var parenExpr = new NonTerminal("ParenExpr");
      var methodCallExpr = new NonTerminal("MethodCallExpr"); 
      var literalExpr = new NonTerminal("LiteralExpr");
      var subExpr= new NonTerminal("SubExpr");
      var lambdaExpr = new NonTerminal("LambdaExpr");
      var lambdaVariable = new NonTerminal("LambdaVariable");

      var memberExpr = new NonTerminal("MemberExpr");
      var binaryExpr = new NonTerminal("BinaryExpr"); 
      var binaryExprOp = new NonTerminal("BinaryExprOp");
      var unaryExpr = new NonTerminal("UnaryExpr"); 
      var unaryExprOp = new NonTerminal("UnaryExprOp");      

      #region Methods
      // bool
      var anyMethodCallExpr = new NonTerminal("AnyMethodCallExpr");
      var allMethodCallExpr = new NonTerminal("AllMethodCallExpr");
      var substringOfMethodCallExpr = new NonTerminal("SubstringOfMethodCallExpr"); 
      var endsWithMethodCallExpr = new NonTerminal("EndsWithMethodCallExpr"); 
      var startsWithMethodCallExpr = new NonTerminal("StartsWithMethodCallExpr");

      // int
      var lengthMethodCallExpr = new NonTerminal("LengthMethodCallExpr"); 
      var indexOfMethodCallExpr = new NonTerminal("IndexOfMethodCallExpr"); 

      // string
      var replaceMethodCallExpr = new NonTerminal("ReplaceMethodCallExpr"); 
      var substring1MethodCallExpr = new NonTerminal("Substring1MethodCallExpr"); 
      var substring2MethodCallExpr = new NonTerminal("Substring2MethodCallExpr"); 
      var toLowerMethodCallExpr = new NonTerminal("ToLowerMethodCallExpr"); 
      var toUpperMethodCallExpr = new NonTerminal("ToUpperMethodCallExpr"); 
      var trimMethodCallExpr = new NonTerminal("TrimMethodCallExpr"); 
      var concatMethodCallExpr = new NonTerminal("ConcatMethodCallExpr"); 

      // date
      var secondMethodCallExpr = new NonTerminal("SecondMethodCallExpr"); 
      var minuteMethodCallExpr = new NonTerminal("MinuteMethodCallExpr"); 
      var hourMethodCallExpr = new NonTerminal("HourMethodCallExpr"); 
      var dayMethodCallExpr = new NonTerminal("DayMethodCallExpr"); 
      var monthMethodCallExpr = new NonTerminal("MonthMethodCallExpr"); 
      var yearMethodCallExpr = new NonTerminal("YearMethodCallExpr"); 

      // math
      var roundMethodCallExpr = new NonTerminal("RoundMethodCallExpr"); 
      var floorMethodCallExpr = new NonTerminal("FloorMethodCallExpr"); 
      var ceilingMethodCallExpr = new NonTerminal("CeilingMethodCallExpr"); 

      // type
      var isOf1MethodCallExpr = new NonTerminal("isOf1MethodCallExpr"); 
      var isOf2MethodCallExpr = new NonTerminal("isOf2MethodCallExpr"); 

      #endregion

      Root = baseExpr;
      baseExpr.Rule = parenExpr
                    | literalExpr
                    | memberExpr
                    | methodCallExpr
                    | binaryExpr
                    | unaryExpr;

   
      parenExpr.Rule = "(" + baseExpr + ")";
      literalExpr.Rule = stringLiteral
                        | numberLiteral
                        // | constant
                        | trueLiteral | falseLiteral | nullLiteral
                        | dateTimeLiteral
                        | dateTimeOffsetLiteral
                        | timeLiteral
                        | guidLiteral;

//.........这里部分代码省略.........
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:101,代码来源:ODataFilterGrammer.cs

示例7: RubyGrammar

        public RubyGrammar()
        {
            #region Terminals
              //String Literals with single and double-quote start/end symbols
              StringLiteral STRING = new StringLiteral("STRING", TermOptions.SpecialIgnoreCase);
              STRING.AddStartEnd("\"", ScanFlags.None);
              STRING.AddStartEnd("'", ScanFlags.None);
              Terminal HereDoc = new Terminal("HereDoc"); //-- implement me!
              Terminal RegExLiteral = new Terminal("RegExLiteral"); //-- implement me!
              IdentifierTerminal IDENTIFIER = new IdentifierTerminal("identifier", "_!?", "[email protected]");
              //                                                name     extraChars      extraFirstChars
              IDENTIFIER.DisplayName = "variable";
              //we need to isolate reserved words to avoid ambiguities in grammar
              IDENTIFIER.AddKeywords("do", "end", "def", "class",
                                       "if", "case", "return", "yield", "while", "until");  //and some others...
              Terminal Number = new NumberLiteral("Number");
              Terminal Comment = new CommentTerminal("Comment", "#", "\n");
              NonGrammarTerminals.Add(Comment); //add comment explicitly to this list as it is not reachable from Root

              //some conveniency variables
              Terminal Pipe = Symbol("|");
              Terminal dot = Symbol(".");
              Terminal comma = Symbol(",");
              #endregion

              #region NonTerminals
              //NT variables names match element names in original grammar
              NonTerminal PROGRAM = new NonTerminal("PROGRAM");
              NonTerminal COMPSTMT = new NonTerminal("COMPSTMT");
              NonTerminal STMT = new NonTerminal("STMT");
              NonTerminal BLOCK = new NonTerminal("BLOCK");
              NonTerminal EXPR = new NonTerminal("EXPR");
              //NonTerminal CALL = new NonTerminal("CALL");
              NonTerminal COMMAND = new NonTerminal("COMMAND");
              NonTerminal FUNCTION = new NonTerminal("FUNCTION");
              NonTerminal ARG = EXPR;// new NonTerminal("ARG");
              NonTerminal PRIMARY = new NonTerminal("PRIMARY", "operand");
              NonTerminal WHEN_ARGS = new NonTerminal("WHEN_ARGS");
              NonTerminal THEN = new NonTerminal("THEN");
              NonTerminal BLOCK_BEGIN = new NonTerminal("BLOCK_BEGIN");
              NonTerminal BLOCK_END = new NonTerminal("BLOCK_END");
              NonTerminal BLOCK_VAR = new NonTerminal("BLOCK_VAR");
            //      NonTerminal MLHS_ITEM = new NonTerminal("MLHS_ITEM");
              NonTerminal LHS = new NonTerminal("LHS");
              NonTerminal MRHS = new NonTerminal("MRHS");
            //      NonTerminal MLHS = MRHS; // new NonTerminal("MLHS");
              NonTerminal CALL_ARGS = new NonTerminal("CALL_ARGS");
              NonTerminal CALL_ARGS_P = new NonTerminal("CALL_ARGS_P");
              NonTerminal AMP_ARG = new NonTerminal("AMP_ARG");
              NonTerminal STAR_ARG = new NonTerminal("STAR_ARG");
              NonTerminal ARGS = new NonTerminal("ARGS");
              NonTerminal ARGDECL = new NonTerminal("ARGDECL");
              NonTerminal ARGLIST = new NonTerminal("ARGLIST");
            //      NonTerminal SINGLETON = new NonTerminal("SINGLETON");
              NonTerminal ASSOCS = new NonTerminal("ASSOCS");
              NonTerminal ASSOC = new NonTerminal("ASSOC");
            //      NonTerminal VARIABLE = new NonTerminal("VARIABLE");  --merged into IDENTIFIER
              NonTerminal LITERAL = new NonTerminal("LITERAL", "value");
              NonTerminal TERM = new NonTerminal("TERM");
              NonTerminal DO = new NonTerminal("DO");
            //      NonTerminal VARNAME = new NonTerminal("VARNAME");   // note 1
              NonTerminal GLOBAL = new NonTerminal("GLOBAL");
              NonTerminal RETURN_STMT = new NonTerminal("RETURN_STMT");
              NonTerminal YIELD_STMT = new NonTerminal("YIELD_STMT");
              NonTerminal DEFINEDQ_STMT = new NonTerminal("DEFINEDQ_STMT");
              NonTerminal FUNCTION_STMT = new NonTerminal("FUNCTION_STMT");
              NonTerminal IF_STMT = new NonTerminal("IF_STMT");
              NonTerminal UNLESS_STMT = new NonTerminal("UNLESS_STMT");
              NonTerminal WHILE_STMT = new NonTerminal("WHILE_STMT");
              NonTerminal UNTIL_STMT = new NonTerminal("UNTIL_STMT");
              NonTerminal CASE_STMT = new NonTerminal("CASE_STMT");
              NonTerminal FOR_STMT = new NonTerminal("FOR_STMT");
              NonTerminal BLOCK_STMT = new NonTerminal("BLOCK_STMT");
              NonTerminal CLASS_DEF = new NonTerminal("CLASS_DEF");
              NonTerminal BASE_REF = new NonTerminal("BASE_REF");
              NonTerminal MODULE = new NonTerminal("MODULE_STMT");
              NonTerminal DEFFUNC_STMT = new NonTerminal("DEFFUNC_STMT");
              NonTerminal DEFSING_STMT = new NonTerminal("DEFSING_STMT");
              NonTerminal SINGLETON = new NonTerminal("SINGLETON");
              NonTerminal END = new NonTerminal("end");

              NonTerminal SYMBOL = new NonTerminal("SYMBOL");
              //Not in original grammar
              NonTerminal FNAME = new NonTerminal("FNAME");
              BLOCK_BEGIN.Rule = Symbol("do") | "{";
              BLOCK_END.Rule = Symbol("end") | "}";
              NonTerminal OPERATION = new NonTerminal("OPERATION");
              //      Terminal VARNAME = IDENTIFIER;
              NonTerminal AUG_ASGN = new NonTerminal("AUG_ASGN");
              NonTerminal BINOP = new NonTerminal("BINOP", "operator");
              NonTerminal UNOP = new NonTerminal("UNOP");
              NonTerminal DELIM = new NonTerminal("DELIM");

              #endregion

              #region Rules
              //Set grammar root
              this.Root = PROGRAM;

              //PROGRAM         : COMPSTMT
//.........这里部分代码省略.........
开发者ID:TheByte,项目名称:sones,代码行数:101,代码来源:RubyGrammar.cs

示例8: CreateSqlExtIdentifier

 //Covers simple identifiers like abcd, and also quoted versions: [abc d], "abc d".
 public static IdentifierTerminal CreateSqlExtIdentifier(Grammar grammar, string name) {
   var id = new IdentifierTerminal(name);
   StringLiteral term = new StringLiteral(name + "_qouted");
   term.AddStartEnd("[", "]", StringOptions.NoEscapes);
   term.AddStartEnd("\"", StringOptions.NoEscapes);
   term.SetOutputTerminal(grammar, id); //term will be added to NonGrammarTerminals automatically 
   return id;
 }
开发者ID:anukat2015,项目名称:sones,代码行数:9,代码来源:TerminalFactory.cs

示例9: ReportingLanguage

		public ReportingLanguage():base(false)
		{
			// 1. Terminals

			var numberLiteral = TerminalFactory.CreateCSharpNumber("Number");
			
			var boolean = new ConstantTerminal("Boolean");
            boolean.Add("true", true);
            boolean.Add("false", false);
            boolean.Priority = 10;
            
            
            var nil = new ConstantTerminal("Null");
            nil.Add("null", null);
            nil.Add("nothing", null);
            nil.Priority = 10;
            
			var identifier = new IdentifierTerminal("Identifier");
         
			var stringLiteral = new StringLiteral("String","'",StringFlags.AllowsDoubledQuote);
			stringLiteral.AddStartEnd("\"",StringFlags.AllowsAllEscapes);
			
			Terminal dot = Symbol(".", "dot");
            Terminal less = Symbol("<");
            Terminal greater = Symbol(">");
            Terminal LCb = Symbol("(");
            Terminal RCb = Symbol(")");
            Terminal RFb = Symbol("}");
            Terminal LFb = Symbol("{");
            Terminal comma = Symbol(",");
//            Terminal LSb = Symbol("[");
//            Terminal RSb = Symbol("]");
              var exclamationMark = Symbol("!");
              
             Terminal and = Symbol("and");
            and.Priority = 10;

            Terminal or = Symbol("or");
            or.Priority = 10;
            
			var UserSection = Symbol("User");
			var GlobalSection = Symbol("Globals");
			var ParameterSection = Symbol("Parameters");
			var FieldsSection = Symbol("Fields");
			
			// 2. Non-terminals
			
			var FieldRef = new NonTerminal("FieldRef");
			var userSectionStmt = new NonTerminal("UserSectionStmt");
			var globalSectionStmt = new NonTerminal("GlobalSectionStmt");
			var parameterSectionStmt = new NonTerminal("ParameterSectionStmt");
			var fieldsSectionStmt = new NonTerminal("FieldsSectionStmt");
			
			var QualifiedName = new NonTerminal("QualifiedName");
			var FunctionExpression = new NonTerminal("FunctionExpression");
			
			var Condition = new NonTerminal("Condition");
            var Conditional = new NonTerminal("IfThen");  
			  
			var Expr = new NonTerminal("Expr");
			 
			var BinOp = new NonTerminal("BinOp");
			var LUnOp = new NonTerminal("LUnOp");
			 
			 
			var ExprList = new NonTerminal("ExprList");
			var BinExpr = new NonTerminal("BinExpr", typeof(BinExprNode));	
				
			var ProgramLine = new NonTerminal("ProgramLine");
			var Program = new NonTerminal("Program", typeof(StatementListNode));
			
			// 3. BNF rules
			 
			#region Reporting
			userSectionStmt.Rule = UserSection + exclamationMark + Symbol("UserId")
				|UserSection + exclamationMark + Symbol("Language");

			globalSectionStmt.Rule = GlobalSection + exclamationMark + Symbol("PageNumber")
				| GlobalSection + exclamationMark + Symbol("TotalPages")
				| GlobalSection + exclamationMark + Symbol("ExecutionTime")
				| GlobalSection + exclamationMark + Symbol("ReportFolder")
				| GlobalSection + exclamationMark + Symbol("ReportName");
			
			
			parameterSectionStmt.Rule = ParameterSection + exclamationMark + identifier;
			
			fieldsSectionStmt.Rule = FieldsSection + exclamationMark + identifier;
			#endregion
			
			Expr.Rule = Symbol("null")
				| boolean
				| nil
				| stringLiteral
				| numberLiteral
				| QualifiedName
				| FunctionExpression
				| LCb + Expr + RCb
				| LFb + QualifiedName + RFb
				| Conditional
				| BinExpr
//.........这里部分代码省略.........
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:101,代码来源:ReportingLanguage.cs

示例10: MakeSimpleId

 private void MakeSimpleId()
 {
     Identifier = new IdentifierTerminal("simple_id");
     var idStringLiteral = new StringLiteral("simple_id_quoted");
     idStringLiteral.AddStartEnd("\"", StringOptions.NoEscapes);
     idStringLiteral.AstConfig.NodeType = typeof(IdentifierNode);
     idStringLiteral.SetOutputTerminal(this, Identifier);
 }
开发者ID:ArsenShnurkov,项目名称:deveeldb,代码行数:8,代码来源:SqlGrammarBase.cs

示例11: CreateSqlExtIdentifier

 public static StringLiteral CreateSqlExtIdentifier(String name)
 {
     StringLiteral term = new StringLiteral(name);
       term.AddStartEnd("[", "]", StringFlags.NoEscapes);
       term.AddStartEnd("\"", StringFlags.NoEscapes);
       return term;
 }
开发者ID:TheByte,项目名称:sones,代码行数:7,代码来源:TerminalFactory.cs

示例12: CreateSqlExtIdentifier

 private BnfTerm CreateSqlExtIdentifier(string name)
 {
     IdentifierTerminal identifierTerminal = new IdentifierTerminal(name, null, "@");
     StringLiteral stringLiteral = new StringLiteral(name + "_quoted");
     stringLiteral.AddStartEnd("[", "]", StringOptions.NoEscapes);
     stringLiteral.AddStartEnd("\"", StringOptions.NoEscapes);
     stringLiteral.SetOutputTerminal(this, (Terminal)identifierTerminal);
     return identifierTerminal;
 }
开发者ID:adrobyazko-softheme,项目名称:PQL,代码行数:9,代码来源:GrammarPql.cs

示例13: QueryLanguageGrammar

        public QueryLanguageGrammar()
            : base(false)
        {
            var comment = new CommentTerminal("lineComment", "//", "\n", "\r\n");

            NonGrammarTerminals.Add(comment);

            var comma = ToTerm(",");

            //LITERALS
            var integerLiteral = new NumberLiteral("integerLiteral", NumberOptions.IntOnly | NumberOptions.NoDotAfterInt);
            var stringLiteral = new StringLiteral("stringLiteral");
            stringLiteral.AddStartEnd("\"", StringOptions.NoEscapes);
            stringLiteral.AddStartEnd("'", StringOptions.NoEscapes);

            var decimalLiteral = new NumberLiteral("decimalLiteral", NumberOptions.AllowSign | NumberOptions.AllowStartEndDot);
            var parsedLiteral = new NonTerminal("parsedLiteral");
            var parsedLiteralType = CreateNonTerminal("parsedLiteralType", ToTerm("date") | "timeofday" | "datetime");

            parsedLiteral.Rule = parsedLiteralType + stringLiteral;

            var literals = CreateNonTerminal("literals", ToTerm("null") | "true" | "false" | integerLiteral | stringLiteral | decimalLiteral | parsedLiteral);

            //OPERATORS
            var binaryOperator = CreateNonTerminal("binaryOperator", ToTerm("*") | "-" | "+" | "/" | "%"
                | "=" | "!=" | "<>" | "<" | "<=" | ">" | ">=" | "is" | "contains" | "starts with" | "ends with" | "matches" | "like"
                | "and" | "or" | "not");

            //CLAUSES
            var selectClause = new NonTerminal("selectClause");
            var whereClause = new NonTerminal("whereClause");
            var groupByClause = new NonTerminal("groupByClause");
            var pivotClause = new NonTerminal("pivotClause");
            var orderByClause = new NonTerminal("orderByClause");
            var limitClause = new NonTerminal("limitClause");
            var offsetClause = new NonTerminal("offsetClause");
            var labelClause = new NonTerminal("labelClause");
            var formatClause = new NonTerminal("formatClause");
            var optionsClause = new NonTerminal("optionsClause");

            //IDENTIFIERS AND EXPRESSIONS
            var identifier = CreateIdentifier();
            var identifierList = new NonTerminal("identifierList");

            var selectList = new NonTerminal("selectList");
            var expressionList = new NonTerminal("expressionList");
            var expression = new NonTerminal("expression");
            //var unaryExpression = new NonTerminal("unaryExpression");
            var binaryExpression = new NonTerminal("binaryExpression");
            var parExpression = new NonTerminal("parExpression");

            var aggregate = new NonTerminal("aggregate");
            var aggregateName = new NonTerminal("aggregateName");

            //TODO: var scalar

            var term = new NonTerminal("term");

            var orderBy = new NonTerminal("orderBy");
            var orderDirection = new NonTerminal("orderDirection");
            var orderByList = new NonTerminal("orderByList");

            var label = new NonTerminal("label");
            var labelList = new NonTerminal("labelList");

            //ROOT
            var query = new NonTerminal("query");

            this.Root = query;

            query.Rule = selectClause + whereClause + groupByClause + pivotClause + orderByClause + limitClause + offsetClause + labelClause + formatClause + optionsClause;

            selectClause.Rule = Empty | "select" + selectList;
            whereClause.Rule = Empty | "where" + expression;
            groupByClause.Rule = Empty | "group by" + identifierList;
            pivotClause.Rule = Empty | "pivot" + identifierList;
            orderByClause.Rule = Empty | "order by" + orderByList;
            limitClause.Rule = Empty | "limit" + integerLiteral;
            offsetClause.Rule = Empty | "offset" + integerLiteral;
            labelClause.Rule = Empty | "label" + labelList;
            formatClause.Rule = Empty | "format" + labelList;
            optionsClause.Rule = Empty | "options" + "no_format" | "options" + "no_values";

            selectList.Rule = ToTerm("*") | expressionList;
            expressionList.Rule = MakePlusRule(expressionList, comma, expression);
            expression.Rule = term | binaryExpression; // unaryExpression
            term.Rule = literals | parExpression | identifier | aggregate;
            parExpression.Rule = "(" + expression + ")";
            //unaryExpression = unaryOperator + term;
            //unaryOperator.Rule =
            binaryExpression.Rule = expression + binaryOperator + expression;

            aggregate.Rule = aggregateName + "(" + identifier + ")";
            aggregateName.Rule = ToTerm("avg") | "count" | "max" | "min" | "sum";

            identifierList.Rule = MakePlusRule(identifierList, comma, identifier);

            orderBy.Rule = expression + orderDirection;
            orderDirection.Rule = Empty | "asc" | "desc";
            orderByList.Rule = MakePlusRule(orderByList, comma, orderBy);
//.........这里部分代码省略.........
开发者ID:paultyng,项目名称:GoogleVisualization,代码行数:101,代码来源:QueryLanguageGrammar.cs

示例14: CreateIdentifier

 IdentifierTerminal CreateIdentifier()
 {
     var identifier = new IdentifierTerminal("identifier");
     var quotedIdentifier = new StringLiteral("identifier_quoted");
     quotedIdentifier.AddStartEnd("`", StringOptions.NoEscapes);
     quotedIdentifier.SetOutputTerminal(this, identifier);
     return identifier;
 }
开发者ID:paultyng,项目名称:GoogleVisualization,代码行数:8,代码来源:QueryLanguageGrammar.cs

示例15: InitGrammar

        private void InitGrammar()
        {
            this.GrammarComments = @"One first go at it.";

            // 1. Non-terminals
            var Expr = new NonTerminal("Expr"); //declare it here to use in template definition
            var Term = new NonTerminal("Term");
            var BinExpr = new NonTerminal("BinExpr", typeof(BinaryOperationNode));
            var ParExpr = new NonTerminal("ParExpr");
            var UnExpr = new NonTerminal("UnExpr", typeof(UnaryOperationNode));
            var TernaryIfExpr = new NonTerminal("TernaryIf", typeof(IfNode));
            var ArgList = new NonTerminal("ArgList", typeof(ExpressionListNode));
            var FunctionCall = new NonTerminal("FunctionCall", typeof(FunctionCallNode));
            var MemberAccess = new NonTerminal("MemberAccess", typeof(MemberAccessNode));
            // var IndexedAccess = new NonTerminal("IndexedAccess", typeof(IndexedAccessNode));
            // var ObjectRef = new NonTerminal("ObjectRef"); // foo, foo.bar or f['bar']
            var UnOp = new NonTerminal("UnOp");
            var BinOp = new NonTerminal("BinOp", "operator");
            var PrefixIncDec = new NonTerminal("PrefixIncDec", typeof(IncDecNode));
            var PostfixIncDec = new NonTerminal("PostfixIncDec", typeof(IncDecNode));
            var IncDecOp = new NonTerminal("IncDecOp");
            var AssignmentStmt = new NonTerminal("AssignmentStmt", typeof(AssignmentNode));
            var AssignmentOp = new NonTerminal("AssignmentOp", "assignment operator");

            // selects
            var SelectStatement = new NonTerminal("SelectStatement", typeof(SelectStatement));
            var SelectRoot = new NonTerminal("SelectRoot", typeof(SelectRoot));
            var SelectRootModel = new NonTerminal("SelectRootModel", typeof(EmptyStatementNode));
            var SelectRootElementList = new NonTerminal("SelectRootElementList", typeof(EmptyStatementNode));
            var SelectRootElement = new NonTerminal("SelectRootElement", typeof(EmptyStatementNode));

            var SelectExpression = new NonTerminal("SelectExpression", typeof(SelectExpressionNode));
            var SelectFunction = new NonTerminal("SelectFunction", typeof(SelectFunctionNode));
            var SelectMemberAccess = new NonTerminal("SelectMemberAccess", typeof(SelectMemberAccessNode));
            var SelectProperty = new NonTerminal("SelectProperty", typeof(SelectPropertyNode));
            var SelectFunctionName = new NonTerminal("SelectFunctionName", typeof(EmptyStatementNode));
            var SelectTerm = new NonTerminal("SelectItem", typeof(EmptyStatementNode));
            var NumberOrEmpty = new NonTerminal("NumberOrEmpty", typeof(EmptyStatementNode));
            var IfcClassProperty = new NonTerminal("IfcClassProperty", typeof(IfcClassPropertyNode));

            // core
            var Statement = new NonTerminal("Statement");
            var Program = new NonTerminal("Program", typeof(StatementListNode));

            // 2. Terminals
            var number = new NumberLiteral("number");
            number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64 }; //Let's allow big integers (with unlimited number of digits):
            var identifier = new IdentifierTerminal("identifier");
            var comma = ToTerm(",");
            var PositiveIntegerNumber = new NumberLiteral("IntegerNumber", NumberOptions.IntOnly);
            var stringLit = new StringLiteral("string", "\"", StringOptions.AllowsAllEscapes);
            var ElementIdStart = ToTerm("@");
            stringLit.AddStartEnd("'", StringOptions.AllowsAllEscapes);

            /*
             * for embedded expressions:
            var templateSettings = new StringTemplateSettings(); //by default set to Ruby-style settings
            templateSettings.ExpressionRoot = Expr; //this defines how to evaluate expressions inside template
            this.SnippetRoots.Add(Expr);
            stringLit.AstConfig.Data = templateSettings;
             */

            // 3. BNF rules
            Expr.Rule = Term | UnExpr | BinExpr | PrefixIncDec | PostfixIncDec | TernaryIfExpr;
            Term.Rule = number | ParExpr | stringLit | FunctionCall | identifier | IfcClassProperty | MemberAccess; // | IndexedAccess; // | MemberAccess;
            ParExpr.Rule = "(" + Expr | SelectStatement + ")";
            UnExpr.Rule = UnOp + Term + ReduceHere();
            UnOp.Rule = ToTerm("+") | "-" | "!";
            BinExpr.Rule = Expr + BinOp + Expr;
            BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "**" | "==" | "<" | "<=" | ">" | ">=" | "!=" | "&&" | "||" | "&" | "|";
            PrefixIncDec.Rule = IncDecOp + identifier;
            PostfixIncDec.Rule = identifier + PreferShiftHere() + IncDecOp;
            IncDecOp.Rule = ToTerm("++") | "--";
            TernaryIfExpr.Rule = Expr + "?" + Expr + ":" + Expr;
            MemberAccess.Rule = Expr + PreferShiftHere() + "." + identifier;
            IfcClassProperty.Rule = ElementIdStart + identifier;

            AssignmentStmt.Rule = identifier + AssignmentOp + Expr;
            AssignmentOp.Rule = ToTerm("=") | "+=" | "-=" | "*=" | "/=";
            Statement.Rule = AssignmentStmt | Expr | SelectStatement | Empty;
            ArgList.Rule = MakeStarRule(ArgList, comma, Expr);
            FunctionCall.Rule = Expr + PreferShiftHere() + "(" + ArgList + ")";
            FunctionCall.NodeCaptionTemplate = "call #{0}(...)";

            // select
            var dot = ToTerm("."); dot.SetFlag(TermFlags.IsTransient);
            var select = ToTerm("select"); select.SetFlag(TermFlags.IsTransient);

            SelectStatement.Rule = select + SelectRoot + SelectExpression;

            var ModelAt = ToTerm("@"); ModelAt.SetFlag(TermFlags.IsTransient);
            SelectRoot.Rule = SelectRootModel +  ModelAt + SelectRootElementList;
            SelectRootModel.Rule = identifier | Empty;
            SelectRootElementList.Rule = MakeStarRule(SelectRootElementList, comma, SelectRootElement); // can be empty
            SelectRootElement.Rule = identifier | PositiveIntegerNumber | ToTerm("*");

            SelectExpression.Rule = Empty | SelectMemberAccess;
            SelectMemberAccess.Rule = dot + PreferShiftHere() + SelectTerm + SelectExpression;
            SelectTerm.Rule = SelectFunction | SelectProperty;
            SelectProperty.Rule = identifier;
//.........这里部分代码省略.........
开发者ID:bnaand,项目名称:xBim-Toolkit,代码行数:101,代码来源:xBimQueryLanguage.cs


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