protected static bool ValidateIdentifierString(string str) { // stringDelimiter identifier stringDelimiter // identifier ::= letter (letter | digit)* if (str == null) return true; if (str.Length == 0) return false; // Empty identifier ScanResult scanResult = new ScanResult(); scanResult.SetResult(str[0]); if (!scanResult.IsLetter()) return false; // First char non-letter foreach (char ch in str) { scanResult.SetResult(ch); if (!(scanResult.IsLetter() || scanResult.IsDigit())) return false; // Non-letter or non-digit char } return true; // OK }
protected virtual StringToken VerifyIdentifierString(StringToken token, string errorMessage) { // stringDelimiter identifier stringDelimiter // identifier ::= letter (letter | digit)* if (token == null) return null; string str = token.Value; if (str.Length == 0) { this.ReportParserError(errorMessage, token); return null; // Empty } ScanResult scanResult = new ScanResult(); scanResult.SetResult(str[0]); if (!scanResult.IsLetter()) { this.ReportParserError(errorMessage, token); return null; // First char non-letter } foreach (char ch in str) { scanResult.SetResult(ch); if (!(scanResult.IsLetter() || scanResult.IsDigit())) { this.ReportParserError(errorMessage, token); return null; // Non-letter or non-digit char } } return token; // OK }
protected virtual StringToken VerifyIdentifierList(StringToken token, string errorMessage) { // stringDelimiter identifier* stringDelimiter if (token == null) return null; if (token.Value.Length == 0) return token; bool inComment = false; bool identifierStart = true; ScanResult scanResult = new ScanResult(); foreach (char ch in token.Value) { scanResult.SetResult(ch); if (scanResult.IsCommentDelimiter()) { inComment = !inComment; identifierStart = true; } else { if (!inComment) { if (scanResult.IsWhitespace()) { identifierStart = true; } else { if (identifierStart) { if (!scanResult.IsLetter()) { this.ReportParserError(errorMessage, token); return null; } identifierStart = false; } else { if (!(scanResult.IsLetter() || scanResult.IsDigit())) { this.ReportParserError(errorMessage, token); return null; } } } } } } return token; }