@ Override public void exitSimple_range ( VersionParser . Simple_rangeContext ctx ) { String operator = ctx . getChild ( 0 ) . getText ( ) ; Object o = stack . pop ( ) ; if ( o instanceof SemanticVersion ) { //range = new SemanticVersionRange((SemanticVersion)o); switch ( operator ) { case "~>" : // Special case for "pessimistic" range, see // https://www.devalot.com/articles/2012/04/gem-versions.html SemanticVersion sv = ( SemanticVersion ) o ; VersionRange from = new VersionRange ( ">=" , sv ) ; VersionRange to = new VersionRange ( "<" , sv . getNextParentVersion ( ) ) ; range = new AndRange ( from , to ) ; break ; default : range = new VersionRange ( operator , ( SemanticVersion ) o ) ; break ; } stack . push ( range ) ; } else { throw new InvalidRangeRuntimeException ( "Expected a semantic version, got a " + o . getClass ( ) . getSimpleName ( ) ) ; } }
A simple range .