Skip to content

Commit

Permalink
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/string/modulo_tags.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
fails:String#% formats single % characters before a newline or NULL as literal %s
fails:String#% raises an error if single % appears anywhere else
fails:String#% raises an error if NULL or \n appear anywhere else in the format string
fails:String#% raises an ArgumentError for unused arguments when $DEBUG is true
fails:String#% always allows unused arguments when positional argument style is used
fails:String#% replaces trailing absolute argument specifier without type with percent sign
fails:String#% raises an ArgumentError when given invalid argument specifiers
fails:String#% raises an ArgumentError when multiple positional argument tokens are given for one format specifier
fails:String#% raises an ArgumentError when multiple width star tokens are given for one format specifier
fails:String#% raises an ArgumentError when a width star token is seen after a width token
fails:String#% raises an ArgumentError when multiple precision tokens are given
fails:String#% raises an ArgumentError when absolute and relative argument numbers are mixed
fails:String#% allows reuse of the one argument multiple via absolute argument numbers
fails:String#% allows positional arguments for width star and precision star arguments
Original file line number Diff line number Diff line change
@@ -26,4 +26,5 @@ DOT : '.' ;
HASH : '#' ;
CURLY_KEY : '{' .*? '}' -> mode(DEFAULT_MODE) ;
TYPE : [bBdiouxXeEfgGaAcps] -> mode(DEFAULT_MODE) ;
NOT_TYPE : ~([bBdiouxXeEfgGaAcps%]);
ESCAPED : '%' -> mode(DEFAULT_MODE) ;
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ directive : CURLY_KEY # string
flag*
width=NUMBER?
(DOT precision=(ZERO|NUMBER))?
TYPE # format ;
(type=TYPE | invalidType=NOT_TYPE) # format ;

flag : SPACE
| ZERO
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.core.format.convert.ToDoubleWithCoercionNodeGen;
import org.jruby.truffle.core.format.convert.ToIntegerNodeGen;
import org.jruby.truffle.core.format.convert.ToStringNodeGen;
import org.jruby.truffle.core.format.exceptions.InvalidFormatException;
import org.jruby.truffle.core.format.format.FormatIntegerBinaryNodeGen;
import org.jruby.truffle.core.format.format.FormatFloatHumanReadableNodeGen;
import org.jruby.truffle.core.format.format.FormatFloatNodeGen;
@@ -77,6 +78,14 @@ public void exitString(PrintfParser.StringContext ctx) {
public void exitFormat(PrintfParser.FormatContext ctx) {
final int width;

if(ctx.invalidType != null){
throw new InvalidFormatException("malformed format string - %" + ctx.invalidType.getText());
} else if (ctx.type == null && ctx.width != null){
throw new InvalidFormatException("malformed format string - %*[0-9]");
} else if (ctx.type == null) {
throw new InvalidFormatException("invalid format character - %");
}

if (ctx.width != null) {
width = Integer.parseInt(ctx.width.getText());
} else {
@@ -101,6 +110,9 @@ public void exitFormat(PrintfParser.FormatContext ctx) {
} else if (flag.ZERO() != null) {
hasZeroFlag = true;
} else if (flag.STAR() != null) {
if (hasStarFlag || ctx.width != null) {
throw new InvalidFormatException("width given twice");
}
hasStarFlag = true;
} else if (flag.PLUS() != null) {
hasPlusFlag = true;

0 comments on commit d1a73f9

Please sign in to comment.