Skip to content

Commit

Permalink
Merge pull request #327 from pocke/make-parse-faster
Browse files Browse the repository at this point in the history
Make parser faster
  • Loading branch information
soutaro authored Jul 10, 2020
2 parents bd127a5 + f76d4d4 commit 3da88ed
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/rbs/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ def initialize(type, buffer:, eof_re:)
@eof = false
@bound_variables_stack = []
@comments = {}
@ascii_only = buffer.content.ascii_only?
end

def start_merged_variables_scope
Expand Down Expand Up @@ -1123,8 +1124,9 @@ def push_comment(string, location)
end

def new_token(type, value = input.matched)
start_index = input.charpos - input.matched.size
end_index = input.charpos
charpos = charpos(input)
start_index = charpos - input.matched.size
end_index = charpos

location = RBS::Location.new(buffer: buffer,
start_pos: start_index,
Expand All @@ -1133,6 +1135,14 @@ def new_token(type, value = input.matched)
[type, LocatedValue.new(location: location, value: value)]
end

def charpos(scanner)
if @ascii_only
scanner.pos
else
scanner.charpos
end
end

def empty_params_result
[
[],
Expand Down Expand Up @@ -1250,8 +1260,9 @@ def next_token
when input.scan(/\s+/)
# skip
when input.scan(/#(( *)|( ?(?<string>.*)))\n/)
start_index = input.charpos - input.matched.size
end_index = input.charpos-1
charpos = charpos(input)
start_index = charpos - input.matched.size
end_index = charpos-1

location = RBS::Location.new(buffer: buffer,
start_pos: start_index,
Expand Down

0 comments on commit 3da88ed

Please # to comment.