Skip to content

Commit

Permalink
Split x-strings into lines to map each line back to original source line
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 23, 2013
1 parent 6def562 commit debb5e5
Show file tree
Hide file tree
Showing 5 changed files with 1,922 additions and 1,880 deletions.
3 changes: 3 additions & 0 deletions lib/opal/fragment.rb
Expand Up @@ -22,6 +22,9 @@ def to_code
end
end

# debug:
# alias code to_code

# inspect the contents of this fragment, f("fooo")
def inspect
"f(#{@code.inspect})"
Expand Down
27 changes: 26 additions & 1 deletion lib/opal/nodes/literal.rb
Expand Up @@ -51,7 +51,27 @@ def compile
end
end

module XStringLineSplitter
def compile_split_lines(value, sexp)
idx = 0
value.each_line do |line|
if idx == 0
push line
else
line_sexp = s()
line_sexp.loc = [sexp.line + idx, 0]
frag = Fragment.new(line, line_sexp)
push frag
end

idx += 1
end
end
end

class XStringNode < Base
include XStringLineSplitter

handle :xstr

children :value
Expand All @@ -61,11 +81,16 @@ def needs_semicolon?
end

def compile
push value.to_s
compile_split_lines(value.to_s, @sexp)

push ';' if needs_semicolon?

wrap '(', ')' if recv?
end

def start_line
@sexp.line
end
end

class DynamicStringNode < Base
Expand Down
4 changes: 3 additions & 1 deletion lib/opal/parser.rb
Expand Up @@ -558,14 +558,16 @@ def new_yield(args)
s(:yield, *args)
end

def new_xstr(str)
def new_xstr(start_t, str, end_t)
return s(:xstr, '') unless str
case str.type
when :str then str.type = :xstr
when :dstr then str.type = :dxstr
when :evstr then str = s(:dxstr, '', str)
end

str.loc = source(start_t)

str
end

Expand Down

0 comments on commit debb5e5

Please sign in to comment.