Skip to content

Commit

Permalink
Split dynamic x-strings to give each line a real source-line reference
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 23, 2013
1 parent dcf801c commit 95c97e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/opal/nodes/literal.rb
Expand Up @@ -140,6 +140,8 @@ def compile
end

class DynamicXStringNode < Base
include XStringLineSplitter

handle :dxstr

def requires_semicolon(code)
Expand All @@ -151,12 +153,13 @@ def compile

children.each do |part|
if String === part
push part.to_s
compile_split_lines(part.to_s, @sexp)

needs_semicolon = true if requires_semicolon(part.to_s)
elsif part.type == :evstr
push expr(part[1])
elsif part.type == :str
push part.last.to_s
compile_split_lines(part.last.to_s, part)
needs_semicolon = true if requires_semicolon(part.last.to_s)
else
raise "Bad dxstr part"
Expand Down
6 changes: 4 additions & 2 deletions lib/opal/parser/lexer.rb
Expand Up @@ -15,6 +15,7 @@ def initialize(source, file)
@cond = 0
@cmdarg = 0
@line = 1
@tok_line = 1
@column = 0
@tok_column = 0
@file = file
Expand Down Expand Up @@ -115,16 +116,17 @@ def matched

def line=(line)
@column = @tok_column = 0
@line = line
@line = @tok_line = line
end

def next_token
token = self.yylex
value = self.yylval
location = [@line, @tok_column]
location = [@tok_line, @tok_column]

# once location is stored, ensure next token starts in correct place
@tok_column = @column
@tok_line = @line

[token, [value, location]]
end
Expand Down

0 comments on commit 95c97e3

Please sign in to comment.