@Deprecated public void validateFormalIdentifier(String identifier) { char first = identifier.charAt(0); if (Character.isUpperCase(first)) { compile_error("formal argument cannot be a constant"); } switch(first) { case '@': if (identifier.charAt(1) == '@') { compile_error("formal argument cannot be a class variable"); } else { compile_error("formal argument cannot be an instance variable"); } break; case '$': compile_error("formal argument cannot be a global variable"); break; default: // This mechanism feels a tad dicey but at this point we are dealing with a valid // method name at least so we should not need to check the entire string... char last = identifier.charAt(identifier.length() - 1); if (last == '=' || last == '?' || last == '!') { compile_error("formal argument must be local variable"); } } }
@Deprecated public void validateFormalIdentifier(String identifier) { char first = identifier.charAt(0); if (Character.isUpperCase(first)) { compile_error("formal argument cannot be a constant"); } switch(first) { case '@': if (identifier.charAt(1) == '@') { compile_error("formal argument cannot be a class variable"); } else { compile_error("formal argument cannot be an instance variable"); } break; case '$': compile_error("formal argument cannot be a global variable"); break; default: // This mechanism feels a tad dicey but at this point we are dealing with a valid // method name at least so we should not need to check the entire string... char last = identifier.charAt(identifier.length() - 1); if (last == '=' || last == '?' || last == '!') { compile_error("formal argument must be local variable"); } } }
public void validateFormalIdentifier(ByteList identifier) { char first = identifier.charAt(0); if (Character.isUpperCase(first)) { compile_error("formal argument cannot be a constant"); } switch(first) { case '@': if (identifier.charAt(1) == '@') { compile_error("formal argument cannot be a class variable"); } else { compile_error("formal argument cannot be an instance variable"); } break; case '$': compile_error("formal argument cannot be a global variable"); break; default: // This mechanism feels a tad dicey but at this point we are dealing with a valid // method name at least so we should not need to check the entire string... char last = identifier.charAt(identifier.length() - 1); if (last == '=' || last == '?' || last == '!') { compile_error("formal argument must be local variable"); } } }
public void validateFormalIdentifier(ByteList identifier) { char first = identifier.charAt(0); if (Character.isUpperCase(first)) { compile_error("formal argument cannot be a constant"); } switch(first) { case '@': if (identifier.charAt(1) == '@') { compile_error("formal argument cannot be a class variable"); } else { compile_error("formal argument cannot be an instance variable"); } break; case '$': compile_error("formal argument cannot be a global variable"); break; default: // This mechanism feels a tad dicey but at this point we are dealing with a valid // method name at least so we should not need to check the entire string... char last = identifier.charAt(identifier.length() - 1); if (last == '=' || last == '?' || last == '!') { compile_error("formal argument must be local variable"); } } }
/** * This differs from MRI in a few ways. This version does not apply value to a separate token buffer. * It is for use when we know we will not be omitting or including ant non-syntactical characters. Use * tokadd_mbchar(int, ByteList) if the string differs from actual source. Secondly, this returns a boolean * instead of the first byte passed. MRI only used the return value as a success/failure code to return * EOF. * * Because this version does not use a separate token buffer we only just increment lex_p. When we reach * end of the token it will just get the bytes directly from source directly. */ public boolean tokadd_mbchar(int first_byte) { int length = precise_mbclen(); if (length <= 0) { compile_error("invalid multibyte char (" + getEncoding() + ")"); return false; } else if (length > 1) { tokenCR = StringSupport.CR_VALID; } lex_p += length - 1; // we already read first byte so advance pointer for remainder return true; }
/** * This differs from MRI in a few ways. This version does not apply value to a separate token buffer. * It is for use when we know we will not be omitting or including ant non-syntactical characters. Use * tokadd_mbchar(int, ByteList) if the string differs from actual source. Secondly, this returns a boolean * instead of the first byte passed. MRI only used the return value as a success/failure code to return * EOF. * * Because this version does not use a separate token buffer we only just increment lex_p. When we reach * end of the token it will just get the bytes directly from source directly. */ public boolean tokadd_mbchar(int first_byte) { int length = precise_mbclen(); if (length <= 0) { compile_error("invalid multibyte char (" + getEncoding() + ")"); return false; } else if (length > 1) { tokenCR = StringSupport.CR_VALID; } lex_p += length - 1; // we already read first byte so advance pointer for remainder return true; }
public boolean tokadd_mbchar(int first_byte, ByteList buffer) { int length = precise_mbclen(); if (length <= 0) { compile_error("invalid multibyte char (" + getEncoding() + ")"); return false; } tokAdd(first_byte, buffer); // add first byte since we have it. lex_p += length - 1; // we already read first byte so advance pointer for remainder if (length > 1) tokCopy(length - 1, buffer); // copy next n bytes over. return true; }
public void checkRegexpSyntax(Ruby runtime, ByteList value, RegexpOptions options) { final String stringValue = value.toString(); // Joni doesn't support these modifiers - but we can fix up in some cases - let the error delay until we try that if (stringValue.startsWith("(?u)") || stringValue.startsWith("(?a)") || stringValue.startsWith("(?d)")) return; ThreadContext context = runtime.getCurrentContext(); IRubyObject $ex = context.getErrorInfo(); try { // This is only for syntax checking but this will as a side-effect create an entry in the regexp cache. RubyRegexp.newRegexpParser(runtime, value, (RegexpOptions)options.clone()); } catch (RaiseException re) { context.setErrorInfo($ex); compile_error(re.getMessage()); } }
public void checkRegexpSyntax(Ruby runtime, ByteList value, RegexpOptions options) { final String stringValue = value.toString(); // Joni doesn't support these modifiers - but we can fix up in some cases - let the error delay until we try that if (stringValue.startsWith("(?u)") || stringValue.startsWith("(?a)") || stringValue.startsWith("(?d)")) return; ThreadContext context = runtime.getCurrentContext(); IRubyObject $ex = context.getErrorInfo(); try { // This is only for syntax checking but this will as a side-effect create an entry in the regexp cache. RubyRegexp.newRegexpParser(runtime, value, (RegexpOptions)options.clone()); } catch (RaiseException re) { context.setErrorInfo($ex); compile_error(re.getMessage()); } }
public boolean tokadd_mbchar(int first_byte, ByteList buffer) { int length = precise_mbclen(); if (length <= 0) { compile_error("invalid multibyte char (" + getEncoding() + ")"); return false; } tokAdd(first_byte, buffer); // add first byte since we have it. lex_p += length - 1; // we already read first byte so advance pointer for remainder if (length > 1) tokCopy(length - 1, buffer); // copy next n bytes over. return true; }
public void checkRegexpFragment(Ruby runtime, ByteList value, RegexpOptions options) { setRegexpEncoding(runtime, value, options); ThreadContext context = runtime.getCurrentContext(); IRubyObject $ex = context.getErrorInfo(); try { RubyRegexp.preprocessCheck(runtime, value); } catch (RaiseException re) { context.setErrorInfo($ex); compile_error(re.getMessage()); } }
public void checkRegexpFragment(Ruby runtime, ByteList value, RegexpOptions options) { setRegexpEncoding(runtime, value, options); ThreadContext context = runtime.getCurrentContext(); IRubyObject $ex = context.getErrorInfo(); try { RubyRegexp.preprocessCheck(runtime, value); } catch (RaiseException re) { context.setErrorInfo($ex); compile_error(re.getMessage()); } }
protected int numberLiteralSuffix(int mask) throws IOException { int c = nextc(); if (c == 'i') return (mask & SUFFIX_I) != 0 ? mask & SUFFIX_I : 0; if (c == 'r') { int result = 0; if ((mask & SUFFIX_R) != 0) result |= (mask & SUFFIX_R); if (peek('i') && (mask & SUFFIX_I) != 0) { c = nextc(); result |= (mask & SUFFIX_I); } return result; } if (c == '.') { int c2 = nextc(); if (Character.isDigit(c2)) { compile_error("unexpected fraction part after numeric literal"); do { // Ripper does not stop so we follow MRI here and read over next word... c2 = nextc(); } while (isIdentifierChar(c2)); } else { pushback(c2); } } pushback(c); return 0; }
protected int numberLiteralSuffix(int mask) throws IOException { int c = nextc(); if (c == 'i') return (mask & SUFFIX_I) != 0 ? mask & SUFFIX_I : 0; if (c == 'r') { int result = 0; if ((mask & SUFFIX_R) != 0) result |= (mask & SUFFIX_R); if (peek('i') && (mask & SUFFIX_I) != 0) { c = nextc(); result |= (mask & SUFFIX_I); } return result; } if (c == '.') { int c2 = nextc(); if (Character.isDigit(c2)) { compile_error("unexpected fraction part after numeric literal"); do { // Ripper does not stop so we follow MRI here and read over next word... c2 = nextc(); } while (isIdentifierChar(c2)); } else { pushback(c2); } } pushback(c); return 0; }