/*identifier_or_keyword { CSharp3Fast parent_; internal _identifier_or_keyword(CSharp3Fast parent) { parent_ = parent; } bool TryGetUnicodeFromHexString(out char uniCodeChar,out int readLength) { System.Diagnostics.Debug.Assert(parent_.src_[parent_.pos_] == '\\'); uniCodeChar='\0'; readLength=0; string hexString; if (parent_.src_[parent_.pos_ + 1] == 'u' && parent_.pos_ + 5 < parent_.srcLen_) { hexString = parent_.src_.Substring(parent_.pos_ + 2, 4); readLength=6; } else if (parent_.src_[parent_.pos_ + 1] == 'U' && parent_.pos_ + 9 < parent_.srcLen_) { hexString = parent_.src_.Substring(parent_.pos_ + 2, 8); readLength=10; } else return false; try { uint val = UInt32.Parse(hexString, System.Globalization.NumberStyles.HexNumber); uniCodeChar = (char)val; return (val & 0xFFFF0000) == 0; } catch (Exception) { return false; } } bool UnicodeEscapeIsLetter() { System.Diagnostics.Debug.Assert(parent_.src_[parent_.pos_] == '\\'); char uniCodeChar; int readLength; if (!TryGetUnicodeFromHexString(out uniCodeChar, out readLength)) return false; if (UnicodeIsLetter(uniCodeChar)) { parent_.pos_+= readLength; return true; } return false; } static bool UnicodeIsLetter(char c) { var cat =System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c); switch (cat) { case System.Globalization.UnicodeCategory.UppercaseLetter: case System.Globalization.UnicodeCategory.LowercaseLetter: case System.Globalization.UnicodeCategory.TitlecaseLetter: case System.Globalization.UnicodeCategory.ModifierLetter: case System.Globalization.UnicodeCategory.OtherLetter: case System.Globalization.UnicodeCategory.LetterNumber: return true; default: return false; } } bool UnicodeEscapeIsIdentierPartCharacter() { System.Diagnostics.Debug.Assert(parent_.src_[parent_.pos_] == '\\'); char uniCodeChar; int readLength; if (!TryGetUnicodeFromHexString(out uniCodeChar, out readLength)) return false; if (UnicodeIsIdentierPartCharacter(uniCodeChar)) { parent_.pos_ += readLength; return true; } return false; } static bool UnicodeIsIdentierPartCharacter(char c) { var cat = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c); switch (cat) { case System.Globalization.UnicodeCategory.UppercaseLetter: case System.Globalization.UnicodeCategory.LowercaseLetter: case System.Globalization.UnicodeCategory.TitlecaseLetter: case System.Globalization.UnicodeCategory.ModifierLetter: case System.Globalization.UnicodeCategory.OtherLetter: case System.Globalization.UnicodeCategory.LetterNumber: case System.Globalization.UnicodeCategory.DecimalDigitNumber: case System.Globalization.UnicodeCategory.ConnectorPunctuation: case System.Globalization.UnicodeCategory.NonSpacingMark: case System.Globalization.UnicodeCategory.SpacingCombiningMark: case System.Globalization.UnicodeCategory.Format: return true; default: return false; } } internal bool ReadCSharpIdentifier_() { if( parent_.pos_ >= parent_.srcLen_ ) return false; if (parent_.src_[parent_.pos_] == '\\') return UnicodeEscapeIsLetter(); if ( !( UnicodeIsLetter(parent_.src_[parent_.pos_]) || parent_.src_[parent_.pos_]=='_' || parent_.src_[parent_.pos_] == '\\' && UnicodeEscapeIsLetter())) return false; while ( ++parent_.pos_ < parent_.srcLen_) { if (! ( UnicodeIsIdentierPartCharacter(parent_.src_[parent_.pos_]) || parent_.src_[parent_.pos_] == '\\' && UnicodeEscapeIsIdentierPartCharacter())) break; } return true; } } : ReadCSharpIdentifier_; //A.1.7 Keywords //----------------------*/ public bool identifier_or_keyword() { var _sem= new _identifier_or_keyword(this); return _sem.ReadCSharpIdentifier_(); }
public bool identifier_or_keyword() /*identifier_or_keyword { CSharp3Fast parent_; internal _identifier_or_keyword(CSharp3Fast parent) { parent_ = parent; } bool TryGetUnicodeFromHexString(out char uniCodeChar,out int readLength) { System.Diagnostics.Debug.Assert(parent_.src_[parent_.pos_] == '\\'); uniCodeChar='\0'; readLength=0; string hexString; if (parent_.src_[parent_.pos_ + 1] == 'u' && parent_.pos_ + 5 < parent_.srcLen_) { hexString = parent_.src_.Substring(parent_.pos_ + 2, 4); readLength=6; } else if (parent_.src_[parent_.pos_ + 1] == 'U' && parent_.pos_ + 9 < parent_.srcLen_) { hexString = parent_.src_.Substring(parent_.pos_ + 2, 8); readLength=10; } else return false; try { uint val = UInt32.Parse(hexString, System.Globalization.NumberStyles.HexNumber); uniCodeChar = (char)val; return (val & 0xFFFF0000) == 0; } catch (Exception) { return false; } } bool UnicodeEscapeIsLetter() { System.Diagnostics.Debug.Assert(parent_.src_[parent_.pos_] == '\\'); char uniCodeChar; int readLength; if (!TryGetUnicodeFromHexString(out uniCodeChar, out readLength)) return false; if (UnicodeIsLetter(uniCodeChar)) { parent_.pos_+= readLength; return true; } return false; } static bool UnicodeIsLetter(char c) { var cat =System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c); switch (cat) { case System.Globalization.UnicodeCategory.UppercaseLetter: case System.Globalization.UnicodeCategory.LowercaseLetter: case System.Globalization.UnicodeCategory.TitlecaseLetter: case System.Globalization.UnicodeCategory.ModifierLetter: case System.Globalization.UnicodeCategory.OtherLetter: case System.Globalization.UnicodeCategory.LetterNumber: return true; default: return false; } } bool UnicodeEscapeIsIdentierPartCharacter() { System.Diagnostics.Debug.Assert(parent_.src_[parent_.pos_] == '\\'); char uniCodeChar; int readLength; if (!TryGetUnicodeFromHexString(out uniCodeChar, out readLength)) return false; if (UnicodeIsIdentierPartCharacter(uniCodeChar)) { parent_.pos_ += readLength; return true; } return false; } static bool UnicodeIsIdentierPartCharacter(char c) { var cat = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c); switch (cat) { case System.Globalization.UnicodeCategory.UppercaseLetter: case System.Globalization.UnicodeCategory.LowercaseLetter: case System.Globalization.UnicodeCategory.TitlecaseLetter: case System.Globalization.UnicodeCategory.ModifierLetter: case System.Globalization.UnicodeCategory.OtherLetter: case System.Globalization.UnicodeCategory.LetterNumber: case System.Globalization.UnicodeCategory.DecimalDigitNumber: case System.Globalization.UnicodeCategory.ConnectorPunctuation: case System.Globalization.UnicodeCategory.NonSpacingMark: case System.Globalization.UnicodeCategory.SpacingCombiningMark: case System.Globalization.UnicodeCategory.Format: return true; default: return false; } } internal bool ReadCSharpIdentifier_() { if( parent_.pos_ >= parent_.srcLen_ ) return false; if (parent_.src_[parent_.pos_] == '\\') return UnicodeEscapeIsLetter(); if ( !( UnicodeIsLetter(parent_.src_[parent_.pos_]) || parent_.src_[parent_.pos_]=='_' || parent_.src_[parent_.pos_] == '\\' && UnicodeEscapeIsLetter())) return false; while ( ++parent_.pos_ < parent_.srcLen_) { if (! ( UnicodeIsIdentierPartCharacter(parent_.src_[parent_.pos_]) || parent_.src_[parent_.pos_] == '\\' && UnicodeEscapeIsIdentierPartCharacter())) break; } return true; } } : ReadCSharpIdentifier_; //A.1.7 Keywords //----------------------*/ { var _sem= new _identifier_or_keyword(this); return _sem.ReadCSharpIdentifier_(); }