/** * Is the top of this scope a block scope (which happens in evals). * This is supposed to serve same purpose as MRIs: dyna_in_block but * I don't quite get why it is so complicated. All non-eval parsers * have local scopes except eval but they combine in_main || compile_for_eval? */ public boolean isBlockTopLevel() { return getConfiguration().isEvalParse(); }
/** * Is the top of this scope a block scope (which happens in evals). * This is supposed to serve same purpose as MRIs: dyna_in_block but * I don't quite get why it is so complicated. All non-eval parsers * have local scopes except eval but they combine in_main || compile_for_eval? */ public boolean isBlockTopLevel() { return getConfiguration().isEvalParse(); }
@Override protected void setCompileOptionFlag(String name, ByteList value) { if (tokenSeen) { warnings.warn(ID.ACCESSOR_MODULE_FUNCTION, "`" + name + "' is ignored after any tokens"); return; } int b = asTruth(name, value); if (b < 0) return; // Enebo: This is a hash in MRI for multiple potential compile options but we currently only support one. // I am just going to set it and when a second is done we will reevaluate how they are populated. parserSupport.getConfiguration().setFrozenStringLiteral(b == 1); }
@Override protected void setCompileOptionFlag(String name, ByteList value) { if (tokenSeen) { warnings.warn(ID.ACCESSOR_MODULE_FUNCTION, "`" + name + "' is ignored after any tokens"); return; } int b = asTruth(name, value); if (b < 0) return; // Enebo: This is a hash in MRI for multiple potential compile options but we currently only support one. // I am just going to set it and when a second is done we will reevaluate how they are populated. parserSupport.getConfiguration().setFrozenStringLiteral(b == 1); }
public void compile_error(String message) { // mri: rb_compile_error_with_enc String line = lexer.getCurrentLine(); ISourcePosition position = lexer.getPosition(); String errorMessage = lexer.getFile() + ":" + (position.getLine() + 1) + ": "; if (line != null && line.length() > 5) { boolean addNewline = message != null && ! message.endsWith("\n"); message += (addNewline ? "\n" : "") + line; } throw getConfiguration().getRuntime().newSyntaxError(errorMessage + message); }
public void compile_error(String message) { // mri: rb_compile_error_with_enc String line = lexer.getCurrentLine(); ISourcePosition position = lexer.getPosition(); String errorMessage = lexer.getFile() + ":" + (position.getLine() + 1) + ": "; if (line != null && line.length() > 5) { boolean addNewline = message != null && ! message.endsWith("\n"); message += (addNewline ? "\n" : "") + line; } throw getConfiguration().getRuntime().newSyntaxError(errorMessage + message); }
public DStrNode createDStrNode(ISourcePosition position) { DStrNode dstr = new DStrNode(position, lexer.getEncoding()); if (getConfiguration().isFrozenStringLiteral()) dstr.setFrozen(true); return dstr; }
public DStrNode createDStrNode(ISourcePosition position) { DStrNode dstr = new DStrNode(position, lexer.getEncoding()); if (getConfiguration().isFrozenStringLiteral()) dstr.setFrozen(true); return dstr; }
public final void reset() { token = 0; yaccValue = null; src = null; setState(null); resetStacks(); lex_strterm = null; commandStart = true; if (parserSupport != null) isTwoZero = parserSupport.getConfiguration().getVersion().is2_0(); }
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) { yyVal = new FileNode(lexer.tokline, new ByteList(lexer.getFile().getBytes(), support.getConfiguration().getRuntime().getEncodingService().getLocaleEncoding())); return yyVal; } };
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) { yyVal = new FileNode(lexer.tokline, new ByteList(lexer.getFile().getBytes(), support.getConfiguration().getRuntime().getEncodingService().getLocaleEncoding())); return yyVal; } };
private int identifierToken(int result, ByteList value) { Ruby runtime = parserSupport.getConfiguration().getRuntime(); String id = runtime.newSymbol(value).idString(); if (result == RubyParser.tIDENTIFIER && !isLexState(last_state, EXPR_DOT|EXPR_FNAME) && parserSupport.getCurrentScope().isDefined(id) >= 0) { setState(EXPR_END|EXPR_LABEL); } yaccValue = value; return result; }
private int identifierToken(int result, ByteList value) { Ruby runtime = parserSupport.getConfiguration().getRuntime(); String id = runtime.newSymbol(value).idString(); if (result == RubyParser.tIDENTIFIER && !isLexState(last_state, EXPR_DOT|EXPR_FNAME) && parserSupport.getCurrentScope().isDefined(id) >= 0) { setState(EXPR_END|EXPR_LABEL); } yaccValue = value; return result; }
public int tokenize_ident(int result) { // FIXME: Get token from newtok index to lex_p? ByteList value = createTokenByteList(); Ruby runtime = parserSupport.getConfiguration().getRuntime(); String id = runtime.newSymbol(value).idString(); if (isLexState(last_state, EXPR_DOT|EXPR_FNAME) && parserSupport.getCurrentScope().isDefined(id) >= 0) { setState(EXPR_END); } yaccValue = value; return result; }
public int tokenize_ident(int result) { // FIXME: Get token from newtok index to lex_p? ByteList value = createTokenByteList(); Ruby runtime = parserSupport.getConfiguration().getRuntime(); String id = runtime.newSymbol(value).idString(); if (isLexState(last_state, EXPR_DOT|EXPR_FNAME) && parserSupport.getCurrentScope().isDefined(id) >= 0) { setState(EXPR_END); } yaccValue = value; return result; }
protected void setEncoding(ByteList name) { Ruby runtime = parserSupport.getConfiguration().getRuntime(); Encoding newEncoding = runtime.getEncodingService().loadEncoding(name); if (newEncoding == null) throw runtime.newArgumentError("unknown encoding name: " + name.toString()); if (!newEncoding.isAsciiCompatible()) throw runtime.newArgumentError(name.toString() + " is not ASCII compatible"); setEncoding(newEncoding); }
protected void setEncoding(ByteList name) { Ruby runtime = parserSupport.getConfiguration().getRuntime(); Encoding newEncoding = runtime.getEncodingService().loadEncoding(name); if (newEncoding == null) throw runtime.newArgumentError("unknown encoding name: " + name.toString()); if (!newEncoding.isAsciiCompatible()) throw runtime.newArgumentError(name.toString() + " is not ASCII compatible"); setEncoding(newEncoding); }
private void setEncoding(ByteList name) { Encoding newEncoding = parserSupport.getConfiguration().getEncodingService().loadEncoding(name); if (newEncoding == null) { throw new SyntaxException(PID.UNKNOWN_ENCODING, getPosition(), null, "unknown encoding name: " + name.toString()); } if (!newEncoding.isAsciiCompatible()) { throw new SyntaxException(PID.NOT_ASCII_COMPATIBLE, getPosition(), null, name.toString() + " is not ASCII compatible"); } setEncoding(newEncoding); }
protected void handleFileEncodingComment(ByteList encodingLine) throws IOException { int realSize = encodingLine.getRealSize(); int begin = encodingLine.getBegin(); Matcher matcher = encodingRegexp.matcher(encodingLine.getUnsafeBytes(), begin, begin + realSize); int result = RubyRegexp.matcherSearch(parserSupport.getConfiguration().getRuntime(), matcher, begin, begin + realSize, Option.IGNORECASE); if (result < 0) return; int begs[] = matcher.getRegion().beg; int ends[] = matcher.getRegion().end; setEncoding(new ByteList(encodingLine.getUnsafeBytes(), begs[1], ends[1] - begs[1])); }
public ByteList shadowing_lvar(ByteList nameBytes) { if (nameBytes.realSize() == 1 && nameBytes.charAt(0) == '_') return nameBytes; RubySymbol name = symbolID(nameBytes); String id = name.idString(); StaticScope current = getCurrentScope(); if (current.exists(id) >= 0) yyerror("duplicated argument name"); if (current.isBlockScope() && warnings.isVerbose() && current.isDefined(id) >= 0 && Options.PARSER_WARN_LOCAL_SHADOWING.load()) { Ruby runtime = getConfiguration().getRuntime(); warnings.warning(ID.STATEMENT_NOT_REACHED, lexer.getFile(), lexer.getPosition().getLine(), str(runtime, "shadowing outer local variable - ", ids(runtime, name))); } return nameBytes; }