Clover.NET coverage report - Coverage for s2dao.net

Coverage timestamp: 2006年5月30日 11:48:56

File Stats: LOC: 218   Methods: 23
NCLOC: 175 Classes: 6
 
Source File Conditionals Statements Methods TOTAL
Seasar.Dao.Node\ExpressionUtil.cs 85.7% 76.7% 65.2% 75.3%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Text;
21   using System.Text.RegularExpressions;
22  
23   namespace Seasar.Dao.Node
24   {
25   /// <summary>
26   /// ExpressionUtil の概要の説明です。
27   /// </summary>
28   public class ExpressionUtil
29   {
30   private IToken current;
31   private int start;
32   private string text;
33   private Regex reOps;
34   private Regex reLit;
35   private Regex reSym;
36  
37 29 public ExpressionUtil()
38   {
39 29 reOps = new Regex(@"^\s*(&&|\|\||<=|>=|==|!=|[=+\-*/^()!<>])", RegexOptions.Compiled);
40 29 reSym = new Regex(@"^\s*(\-?\b*[_a-zA-Z.']+[_a-zA-Z0-9\[()\]]*)", RegexOptions.Compiled);
41 29 reLit = new Regex(@"^\s*([0-9]+(\.[0-9]+)?)", RegexOptions.Compiled);
42   }
43  
44 29 public string parseExpression(string expression)
45   {
46 29 current = null;
47 29 text = expression;
48 29 StringBuilder sb = new StringBuilder(255);
49 135 while (!EOF())
50   {
51 106 IToken token = NextToken();
52 106 sb.Append(token.Value + " ");
53   }
54 29 return sb.ToString().TrimEnd(' ');
55   }
56  
57 135 protected bool EOF()
58   {
59 135 if (current is Eof)
60   {
61 29 return true;
62   }
63 106 return false;
64   }
65  
66 106 protected IToken NextToken()
67   {
68 106 Match match;
69 106 match = reOps.Match(text);
70 106 if (match.Length != 0)
71   {
72 24 SetOperatorToken(match);
73   }
74   else
75   {
76 82 match = reSym.Match(text);
77 82 if (match.Length != 0)
78   {
79 53 SetSymbolToken(match);
80   }
81   else
82   {
83 29 match = reLit.Match(text);
84 29 if (match.Length != 0)
85   {
86 0 SetNumberLiteralToken(match);
87   }
88   else
89 29 current = new Eof();
90   }
91   }
92 106 return current;
93   }
94  
95 0 private void SetNumberLiteralToken(Match match)
96   {
97   IToken token;
98   start += match.Length;
99   text = text.Substring(match.Length);
100   token = new NumberLiteral();
101   token.Value = match.Groups[1].Value;
102   current = token;
103   }
104  
105 53 private void SetSymbolToken(Match match)
106   {
107 53 IToken token;
108 53 start += match.Length;
109 53 text = text.Substring(match.Length);
110 53 token = new Symbol();
111 53 token.Value = match.Groups[1].Value;
112 53 current = token;
113   }
114  
115 24 private void SetOperatorToken(Match match)
116   {
117 24 IToken token;
118 24 start += match.Length;
119 24 text = text.Substring(match.Length);
120 24 token = new Operator();
121 24 token.Value = match.Groups[1].Value;
122 24 current = token;
123   }
124   }
125  
126   #region Token
127   public interface IToken
128   {
129   object Value {get; set;}
130   }
131   public class Eof : IToken
132   {
133 29 public Eof()
134   {
135   }
136  
137   public object Value
138   {
139 29 get { return null; }
140 0 set { throw new NotImplementedException(); }
141   }
142   }
143  
144   public class Symbol : IToken
145   {
146   private string _value;
147   private string[] _escapes = { "null", "true", "false" };
148  
149 53 public Symbol()
150   {
151   }
152  
153   public object Value
154   {
155 53 get { return GetArgValue(); }
156 53 set { _value = (string) value; }
157   }
158  
159 53 private string GetArgValue()
160   {
161 53 if(_value.StartsWith("'") && _value.EndsWith("'"))
162 0 return _value;
163  
164 53 foreach(string escape in _escapes)
165   {
166 110 if ( _value.ToLower() == escape)
167 29 return _value.ToLower();
168   }
169  
170 24 return "self.GetArg('" + _value + "')";
171   }
172  
173 0 public override string ToString()
174   {
175   return _value.ToString();
176   }
177   }
178  
179   public class NumberLiteral : IToken
180   {
181   private float _value;
182  
183 0 public NumberLiteral()
184   {
185   }
186  
187 0 public object Value
188   {
189   get { return _value; }
190   set { _value = (float)Double.Parse(value.ToString()); }
191   }
192 0 public override string ToString()
193   {
194   return _value.ToString();
195   }
196   }
197  
198   public class Operator : IToken
199   {
200   private string _value;
201  
202 24 public Operator()
203   {
204   }
205  
206   public object Value
207   {
208 24 get { return _value; }
209 24 set { _value = (string) value; }
210   }
211 0 public override string ToString()
212   {
213   return _value.ToString();
214   }
215   }
216   #endregion
217   }
218