public override bool VisitObjectProperty( int startPropertyIndex, string propertyName, int propertyIndex ) { if( Path.Count == 0 ) { _hasTopLevelProperties = true; if( propertyName == "version" ) { if( _thisVersion != null ) return Matcher.SetError( "Duplicate version." ); return GetVersionValue( startPropertyIndex, out _thisVersion ); } } else if( _versions != null && Path[Path.Count-1].PropertyName == "dependencies" && _projectNameFinder( propertyName ) ) { Matcher.MatchWhiteSpaces( 0 ); if( Matcher.Head == '{' ) { JSONVersionFinder f = new JSONVersionFinder( Matcher, null, null ); if( f.ThisVersion == null ) return Matcher.SetError( "Property version expected." ); CollectVersion( f.ThisVersion ); } else { int start = Matcher.StartIndex; string version; if( !Matcher.TryMatchJSONQuotedString( out version ) ) return Matcher.SetError( "Version string expected." ); VersionOccurrence v = new VersionOccurrence( version, start, Matcher.StartIndex - start, false ); Debug.Assert( v.IsNakedVersionNumber ); CollectVersion( v ); } return true; } return base.VisitObjectProperty( startPropertyIndex, propertyName, propertyIndex ); }
void ExtractVersions(string text) { StringMatcher m = new StringMatcher(text); var allVersions = new List <VersionOccurrence>(); JSONVersionFinder finder = new JSONVersionFinder(m, _projectNameFinder, allVersions); _thisVersion = finder.ThisVersion; _allVersions = allVersions; _sameVersions = finder.SameVersions; _parseError = m.ErrorMessage; }
public override bool VisitObjectProperty(int startPropertyIndex, string propertyName, int propertyIndex) { if (Path.Count == 0) { _hasTopLevelProperties = true; if (propertyName == "version") { if (_thisVersion != null) { return(Matcher.SetError("Duplicate version.")); } return(GetVersionValue(startPropertyIndex, out _thisVersion)); } } else if (_versions != null && Path[Path.Count - 1].PropertyName == "dependencies" && _projectNameFinder(propertyName)) { Matcher.MatchWhiteSpaces(0); if (Matcher.Head == '{') { JSONVersionFinder f = new JSONVersionFinder(Matcher, null, null); if (f.ThisVersion == null) { return(Matcher.SetError("Property version expected.")); } CollectVersion(f.ThisVersion); } else { int start = Matcher.StartIndex; string version; if (!Matcher.TryMatchJSONQuotedString(out version)) { return(Matcher.SetError("Version string expected.")); } VersionOccurrence v = new VersionOccurrence(version, start, Matcher.StartIndex - start, false); Debug.Assert(v.IsNakedVersionNumber); CollectVersion(v); } return(true); } return(base.VisitObjectProperty(startPropertyIndex, propertyName, propertyIndex)); }
void ExtractVersions( string text ) { StringMatcher m = new StringMatcher( text ); var allVersions = new List<VersionOccurrence>(); JSONVersionFinder finder = new JSONVersionFinder( m, _projectNameFinder, allVersions ); _thisVersion = finder.ThisVersion; _allVersions = allVersions; _sameVersions = finder.SameVersions; _parseError = m.ErrorMessage; }