示例#1
0
 public bool ValidateValue(ValueVariable val)
 {
     if (val!=null) {
     if (_checkIden(_iden, val.Name, _casesens)) {
         if (_layout!=null && _layout.Length>0)
             return (_layout[0]&val.Type)!=0;
         // No canon types, check infinitism
         if (_infinitism!=VariableType.NONE)
             return (_infinitism&val.Type)!=0;
     }
     }
     return false;
 }
示例#2
0
 public static string FormatValue(ValueVariable val)
 {
     return FormatValue(val, ValueFormat.NAME_DEFAULT, ValueFormat.ALL_DEFAULT);
 }
示例#3
0
 public bool Validate(ValueVariable val)
 {
     return ValidateValue(val);
 }
示例#4
0
 protected override void Clean()
 {
     base.Clean();
     _varname=String.Empty;
     _equals=false;
     _currentvalue=null;
     _currentiden=null;
 }
示例#5
0
 void Reset(bool iden, bool val)
 {
     _varname=String.Empty;
     _equals=false;
     if (val)
     _currentvalue=null;
     if (iden)
     _currentiden=null;
 }
示例#6
0
 public override void HandleToken(Token<ScriptToken> token)
 {
     switch (token.Type) {
     case ScriptToken.String:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             int bv=Variable.StringToBool(token.ToString());
             if (bv!=-1) {
                 AddVariableAndReset(_currentnode, new BoolVariable(bv==1 ? true : false, _varname), false, false);
                 break;
             } else {
                 AddVariableAndReset(_currentnode, new StringVariable(token.ToString(), _varname), false, false);
             }
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             int bv=Variable.StringToBool(token.ToString());
             if (bv!=-1) {
                 AddVariableAndReset(_currentiden, new BoolVariable(bv==1 ? true : false), false, false);
                 break;
             }
             AddVariableAndReset(_currentiden, new StringVariable(token.ToString()), false, false);
         } else {
             _varname=token.ToString();
         }
         break;
     case ScriptToken.QuotedString:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             AddVariableAndReset(_currentnode, new StringVariable(token.ToString(), _varname), false, false);
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             AddVariableAndReset(_currentiden, new StringVariable(token.ToString()), false, false);
         } else {
             _varname=token.ToString();
         }
         break;
     case ScriptToken.Number:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             _currentvalue=new IntVariable(token.ToInt(), _varname);
             AddVariableAndReset(_currentnode, _currentvalue, false, false);
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             AddVariableAndReset(_currentiden, new IntVariable(token.ToInt()), false, false);
         } else {
             //new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "A number cannot be an identifier");
             _varname=token.ToString();
         }
         break;
     case ScriptToken.Double:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             _currentvalue=new FloatVariable((float)token.ToDouble(), _varname);
             AddVariableAndReset(_currentnode, _currentvalue, false, false);
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             AddVariableAndReset(_currentiden, new FloatVariable((float)token.ToDouble()), false, false);
         } else {
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "A number cannot be an identifier");
             _varname=token.ToString();
         }
         break;
     case ScriptToken.Equals:
         if (_currentiden!=null)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Unexpected equality sign after identifier declaration");
         else if (_varname.Length==0)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Expected string, got equality sign");
         else if (_equals)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Expected value, got equality sign");
         else
             _equals=true;
         break;
     case ScriptToken.OpenBrace:
         if (_currentiden!=null)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Node cannot contain values (possible openbrace typo)");
         Node tempnode=new Node(_varname, _currentnode);
         AddVariableAndReset(_currentnode, tempnode, false, false);
         _currentnode=tempnode;
         break;
     case ScriptToken.CloseBrace:
         if (_currentnode.Parent==null) {
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Mismatched node brace");
         } else if (_equals) {
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Expected value, got close-brace");
         } else {
             if (_currentiden!=null)
                 Reset(true, true);
             _currentnode=(Node)_currentnode.Parent;
         }
         break;
     case ScriptToken.Comment:
     case ScriptToken.CommentBlock:
         // Do nothing
         break;
     case ScriptToken.EOL:
     case ScriptToken.EOF:
         Finish();
         break;
     //default:
     //	//DebugLog("(StandardScriptParserHandler.handleToken) Unhandled token of type "+token.typeAsString())
     //	break;
     }
 }
示例#7
0
 public static bool FormatValue(ValueVariable val, out string result, ValueFormat nameformat, ValueFormat varformat)
 {
     if (!String.IsNullOrEmpty(val.Name)) {
     StringBuilder builder=new StringBuilder(64);
     builder.Append(val.GetNameFormatted(nameformat));
     builder.Append("=");
     builder.Append(val.GetValueFormatted(varformat));
     //builder.Append(String.Format("<{0}>", val.TypeName));
     result=builder.ToString();
     return true;
     } else {
     result=String.Empty; // clear the result string
     }
     return false;
 }
示例#8
0
 public static bool FormatValue(ValueVariable val, out string result, ValueFormat nameformat)
 {
     return FormatValue(val, out result, nameformat, ValueFormat.ALL_DEFAULT);
 }
示例#9
0
 public static string FormatValue(ValueVariable val, ValueFormat nameformat, ValueFormat varformat)
 {
     string formatted;
     FormatValue(val, out formatted, nameformat, varformat);
     return formatted;
 }
示例#10
0
 public static string FormatValue(ValueVariable val, ValueFormat nameformat)
 {
     return FormatValue(val, nameformat, ValueFormat.ALL_DEFAULT);
 }