Skip to content

Instantly share code, notes, and snippets.

@headius
Last active May 20, 2016 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/a403d56a68d6c733f76b9ec539a23289 to your computer and use it in GitHub Desktop.
Save headius/a403d56a68d6c733f76b9ec539a23289 to your computer and use it in GitHub Desktop.
--- lib/ruby/gems/shared/gems/brakeman-3.3.0/bundle/ruby/2.3.0/gems/ruby_parser-3.8.1/lib/ruby_lexer.rex.rb 2016-05-19 16:17:39.000000000 -0500
+++ ruby_lexer.rex.rb 2016-05-19 16:00:36.000000000 -0500
@@ -1,11 +1,12 @@
# encoding: UTF-8
+# frozen-literal-string: true
#--
# This file is automatically generated. Do not modify it.
# Generated by: oedipus_lex version 2.4.1.
# Source: lib/ruby_lexer.rex
#++
#
# lexical scanner definition for ruby
class RubyLexer
@@ -55,253 +56,299 @@
do_parse
end
def parse_file path
self.filename = path
open path do |f|
parse f.read
end
end
+ def bang_match
+ if in_arg_state? && (ss.skip(/\!\@/)) then
+ result :expr_arg, :tUBANG, "!@"
+ elsif text = ss.scan(/\![=~]?/) then
+ result :arg_state, TOKENS.fetch(text), text
+ end # group /\!/
+ end
+
+ def dot_match
+ if text = ss.scan(/\.\.\.?/) then
+ result :expr_beg, TOKENS.fetch(text), text
+ elsif ss.skip(/\.\d/) then
+ rb_compile_error "no .<digit> floating literal anymore put 0 before dot"
+ elsif ss.skip(/\./) then
+ result :expr_dot, :tDOT, "."
+ end # group /\./
+ end
+
+ def equal_match
+ if text = ss.scan(/\=\=\=|\=\=|\=~|\=>|\=(?!begin\b)/) then
+ result arg_state, TOKENS.fetch(text), text
+ elsif bol? && (text = ss.scan(/\=begin(?=\s)/)) then
+ process_begin text
+ elsif text = ss.scan(/\=(?=begin\b)/) then
+ result arg_state, TOKENS.fetch(text), text
+ end # group /=/
+ end
+
+ def colon_match
+ if not_end? && (text = ss.scan(/:([a-zA-Z_]#{IDENT_CHAR}*(?:[?]|[!](?!=)|=(?==>)|=(?![=>]))?)/o)) then
+ process_symbol text
+ elsif not_end? && (text = ss.scan(/\:\"(#{SIMPLE_STRING})\"/o)) then
+ process_symbol text
+ elsif not_end? && (text = ss.scan(/\:\'(#{SSTRING})\'/o)) then
+ process_symbol text
+ elsif text = ss.scan(/\:\:/) then
+ process_colon2 text
+ elsif text = ss.scan(/\:/) then
+ process_colon1 text
+ end # group /:/
+ end
+
+ def digit_match
+ if ss.skip(/#{NUM_BAD}/o) then
+ rb_compile_error "Invalid numeric format"
+ elsif ss.skip(/#{INT_DEC}/o) then
+ int_with_base 10
+ elsif ss.skip(/#{INT_HEX}/o) then
+ int_with_base 16
+ elsif ss.skip(/#{INT_BIN}/o) then
+ int_with_base 2
+ elsif ss.skip(/#{INT_OCT_BAD}/o) then
+ rb_compile_error "Illegal octal digit."
+ elsif ss.skip(/#{INT_OCT}/o) then
+ int_with_base 8
+ elsif ss.skip(/#{FLOAT_BAD}/o) then
+ rb_compile_error "Trailing '_' in number."
+ elsif text = ss.scan(/#{FLOAT}/o) then
+ process_float text
+ elsif ss.skip(/#{INT_DEC2}/o) then
+ int_with_base 10
+ elsif ss.skip(/[0-9]/) then
+ rb_compile_error "Bad number format"
+ end # group /[+\d]/
+ end
+
+ def pipe_match
+ if ss.skip(/\|\|\=/) then
+ result :expr_beg, :tOP_ASGN, "||"
+ elsif ss.skip(/\|\|/) then
+ result :expr_beg, :tOROP, "||"
+ elsif ss.skip(/\|\=/) then
+ result :expr_beg, :tOP_ASGN, "|"
+ elsif ss.skip(/\|/) then
+ result :arg_state, :tPIPE, "|"
+ end # group /\|/
+ end
+
+ def star_match
+ if ss.skip(/\*\*=/) then
+ result :expr_beg, :tOP_ASGN, "**"
+ elsif ss.skip(/\*\*/) then
+ result(:arg_state, space_vs_beginning(:tDSTAR, :tDSTAR, :tPOW), "**")
+ elsif ss.skip(/\*\=/) then
+ result(:expr_beg, :tOP_ASGN, "*")
+ elsif ss.skip(/\*/) then
+ result(:arg_state, space_vs_beginning(:tSTAR, :tSTAR, :tSTAR2), "*")
+ end # group /\*/
+ end
+
+ def lt_match
+ if ss.skip(/\<\=\>/) then
+ result :arg_state, :tCMP, "<=>"
+ elsif ss.skip(/\<\=/) then
+ result :arg_state, :tLEQ, "<="
+ elsif ss.skip(/\<\<\=/) then
+ result :arg_state, :tOP_ASGN, "<<"
+ elsif text = ss.scan(/\<\</) then
+ process_lchevron text
+ elsif ss.skip(/\</) then
+ result :arg_state, :tLT, "<"
+ end # group /</
+ end
+
+ def gt_match
+ if ss.skip(/\>\=/) then
+ result :arg_state, :tGEQ, ">="
+ elsif ss.skip(/\>\>=/) then
+ result :arg_state, :tOP_ASGN, ">>"
+ elsif ss.skip(/\>\>/) then
+ result :arg_state, :tRSHFT, ">>"
+ elsif ss.skip(/\>/) then
+ result :arg_state, :tGT, ">"
+ end # group />/
+ end
+
+ def backtick_match
+ if expr_fname? && (ss.skip(/\`/)) then
+ result(:expr_end, :tBACK_REF2, "`")
+ elsif expr_dot? && (ss.skip(/\`/)) then
+ result((command_state ? :expr_cmdarg : :expr_arg), :tBACK_REF2, "`")
+ elsif ss.skip(/\`/) then
+ string STR_XQUOTE, '`'; result(nil, :tXSTRING_BEG, "`")
+ end # group /\`/
+ end
+
+ def ampersand_match
+ if ss.skip(/\&\&\=/) then
+ result(:expr_beg, :tOP_ASGN, "&&")
+ elsif ss.skip(/\&\&/) then
+ result(:expr_beg, :tANDOP, "&&")
+ elsif ss.skip(/\&\=/) then
+ result(:expr_beg, :tOP_ASGN, "&" )
+ elsif ss.skip(/\&\./) then
+ result(:expr_dot, :tLONELY, "&.")
+ elsif text = ss.scan(/\&/) then
+ process_amper text
+ end # group /&/
+ end
+
+ def caret_match
+ if ss.skip(/\^=/) then
+ result(:expr_beg, :tOP_ASGN, "^")
+ elsif ss.skip(/\^/) then
+ result(:arg_state, :tCARET, "^")
+ end # group /\^/
+ end
+
+ def tilde_match
+ if in_arg_state? && (ss.skip(/\~@/)) then
+ result(:arg_state, :tTILDE, "~")
+ elsif ss.skip(/\~/) then
+ result(:arg_state, :tTILDE, "~")
+ end # group /~/
+ end
+
+ def newline_match
+ if ss.skip(/\\\r?\n/) then
+ self.lineno += 1
+ self.space_seen = true
+ nil
+ elsif ss.skip(/\\/) then
+ rb_compile_error "bare backslash only allowed before newline"
+ end # group /\\/
+ end
+
+ def dollar_match
+ if text = ss.scan(/\$_\w+/) then
+ process_gvar text
+ elsif text = ss.scan(/\$_/) then
+ process_gvar text
+ elsif text = ss.scan(/\$[~*$?!@\/\\;,.=:<>\"]|\$-\w?/) then
+ process_gvar text
+ elsif in_fname? && (text = ss.scan(/\$([\&\`\'\+])/)) then
+ process_gvar text
+ elsif text = ss.scan(/\$([\&\`\'\+])/) then
+ process_backref text
+ elsif in_fname? && (text = ss.scan(/\$([1-9]\d*)/)) then
+ process_gvar text
+ elsif text = ss.scan(/\$([1-9]\d*)/) then
+ process_nthref text
+ elsif text = ss.scan(/\$0/) then
+ process_gvar text
+ elsif text = ss.scan(/\$\W|\$\z/) then
+ process_gvar_oddity text
+ elsif text = ss.scan(/\$\w+/) then
+ process_gvar text
+ end # group /\$/
+ end
+
def next_token
return process_string if lex_strterm
self.command_state = self.command_start
self.command_start = false
self.space_seen = false
self.last_state = lex_state
token = nil
until ss.eos? or token do
token =
- case state
- when nil then
- case
- when ss.skip(/[\ \t\r\f\v]/) then
- action { self.space_seen = true; next }
- when text = ss.scan(/\n|\#/) then
+ if nil === state then
+ if ss.skip(/[\ \t\r\f\v]/) then
+ self.space_seen = true
+ nil
+ elsif text = ss.scan(/\n|\#/) then
process_newline_or_comment text
- when text = ss.scan(/[\]\)\}]/) then
+ elsif text = ss.scan(/[\]\)\}]/) then
process_bracing text
- when ss.match?(/\!/) then
- case
- when in_arg_state? && (ss.skip(/\!\@/)) then
- action { result :expr_arg, :tUBANG, "!@" }
- when text = ss.scan(/\![=~]?/) then
- action { result :arg_state, TOKENS[text], text }
- end # group /\!/
- when ss.match?(/\./) then
- case
- when text = ss.scan(/\.\.\.?/) then
- action { result :expr_beg, TOKENS[text], text }
- when ss.skip(/\.\d/) then
- action { rb_compile_error "no .<digit> floating literal anymore put 0 before dot" }
- when ss.skip(/\./) then
- action { result :expr_dot, :tDOT, "." }
- end # group /\./
- when text = ss.scan(/\(/) then
+ elsif ss.match?(/\!/) then
+ bang_match
+ elsif ss.match?(/\./) then
+ dot_match
+ elsif text = ss.scan(/\(/) then
process_paren text
- when text = ss.scan(/\,/) then
- action { result :expr_beg, TOKENS[text], text }
- when ss.match?(/=/) then
- case
- when text = ss.scan(/\=\=\=|\=\=|\=~|\=>|\=(?!begin\b)/) then
- action { result arg_state, TOKENS[text], text }
- when bol? && (text = ss.scan(/\=begin(?=\s)/)) then
- process_begin text
- when text = ss.scan(/\=(?=begin\b)/) then
- action { result arg_state, TOKENS[text], text }
- end # group /=/
- when ruby22_label? && (text = ss.scan(/\"#{SIMPLE_STRING}\":/o)) then
+ elsif text = ss.scan(/\,/) then
+ result :expr_beg, TOKENS.fetch(text), text
+ elsif ss.match?(/=/) then
+ equal_match
+ elsif ruby22_label? && (text = ss.scan(/\"#{SIMPLE_STRING}\":/o)) then
process_label text
- when text = ss.scan(/\"(#{SIMPLE_STRING})\"/o) then
- action { result :expr_end, :tSTRING, text[1..-2].gsub(ESC) { unescape $1 } }
- when text = ss.scan(/\"/) then
- action { string STR_DQUOTE; result nil, :tSTRING_BEG, text }
- when text = ss.scan(/\@\@?\d/) then
- action { rb_compile_error "`#{text}` is not allowed as a variable name" }
- when text = ss.scan(/\@\@?#{IDENT_CHAR}+/o) then
+ elsif text = ss.scan(/\"(#{SIMPLE_STRING})\"/o) then
+ result :expr_end, :tSTRING, text[1..-2].gsub(ESC) { unescape $1 }
+ elsif text = ss.scan(/\"/) then
+ string STR_DQUOTE; result nil, :tSTRING_BEG, text
+ elsif text = ss.scan(/\@\@?\d/) then
+ rb_compile_error "`#{text}` is not allowed as a variable name"
+ elsif text = ss.scan(/\@\@?#{IDENT_CHAR}+/o) then
process_ivar text
- when ss.match?(/:/) then
- case
- when not_end? && (text = ss.scan(/:([a-zA-Z_]#{IDENT_CHAR}*(?:[?]|[!](?!=)|=(?==>)|=(?![=>]))?)/o)) then
- process_symbol text
- when not_end? && (text = ss.scan(/\:\"(#{SIMPLE_STRING})\"/o)) then
- process_symbol text
- when not_end? && (text = ss.scan(/\:\'(#{SSTRING})\'/o)) then
- process_symbol text
- when text = ss.scan(/\:\:/) then
- process_colon2 text
- when text = ss.scan(/\:/) then
- process_colon1 text
- end # group /:/
- when ss.skip(/->/) then
- action { result :expr_endfn, :tLAMBDA, nil }
- when text = ss.scan(/[+-]/) then
+ elsif ss.match?(/:/) then
+ colon_match
+ elsif ss.skip(/->/) then
+ result :expr_endfn, :tLAMBDA, nil
+ elsif text = ss.scan(/[+-]/) then
process_plus_minus text
- when ss.match?(/[+\d]/) then
- case
- when ss.skip(/#{NUM_BAD}/o) then
- action { rb_compile_error "Invalid numeric format" }
- when ss.skip(/#{INT_DEC}/o) then
- action { int_with_base 10 }
- when ss.skip(/#{INT_HEX}/o) then
- action { int_with_base 16 }
- when ss.skip(/#{INT_BIN}/o) then
- action { int_with_base 2 }
- when ss.skip(/#{INT_OCT_BAD}/o) then
- action { rb_compile_error "Illegal octal digit." }
- when ss.skip(/#{INT_OCT}/o) then
- action { int_with_base 8 }
- when ss.skip(/#{FLOAT_BAD}/o) then
- action { rb_compile_error "Trailing '_' in number." }
- when text = ss.scan(/#{FLOAT}/o) then
- process_float text
- when ss.skip(/#{INT_DEC2}/o) then
- action { int_with_base 10 }
- when ss.skip(/[0-9]/) then
- action { rb_compile_error "Bad number format" }
- end # group /[+\d]/
- when text = ss.scan(/\[/) then
+ elsif ss.match?(/[+\d]/) then
+ digit_match
+ elsif text = ss.scan(/\[/) then
process_square_bracket text
- when was_label? && (text = ss.scan(/\'#{SSTRING}\':?/o)) then
+ elsif was_label? && (text = ss.scan(/\'#{SSTRING}\':?/o)) then
process_label_or_string text
- when ss.match?(/\|/) then
- case
- when ss.skip(/\|\|\=/) then
- action { result :expr_beg, :tOP_ASGN, "||" }
- when ss.skip(/\|\|/) then
- action { result :expr_beg, :tOROP, "||" }
- when ss.skip(/\|\=/) then
- action { result :expr_beg, :tOP_ASGN, "|" }
- when ss.skip(/\|/) then
- action { result :arg_state, :tPIPE, "|" }
- end # group /\|/
- when text = ss.scan(/\{/) then
+ elsif ss.match?(/\|/) then
+ pipe_match
+ elsif text = ss.scan(/\{/) then
process_curly_brace text
- when ss.match?(/\*/) then
- case
- when ss.skip(/\*\*=/) then
- action { result :expr_beg, :tOP_ASGN, "**" }
- when ss.skip(/\*\*/) then
- action { result(:arg_state, space_vs_beginning(:tDSTAR, :tDSTAR, :tPOW), "**") }
- when ss.skip(/\*\=/) then
- action { result(:expr_beg, :tOP_ASGN, "*") }
- when ss.skip(/\*/) then
- action { result(:arg_state, space_vs_beginning(:tSTAR, :tSTAR, :tSTAR2), "*") }
- end # group /\*/
- when ss.match?(/</) then
- case
- when ss.skip(/\<\=\>/) then
- action { result :arg_state, :tCMP, "<=>" }
- when ss.skip(/\<\=/) then
- action { result :arg_state, :tLEQ, "<=" }
- when ss.skip(/\<\<\=/) then
- action { result :arg_state, :tOP_ASGN, "<<" }
- when text = ss.scan(/\<\</) then
- process_lchevron text
- when ss.skip(/\</) then
- action { result :arg_state, :tLT, "<" }
- end # group /</
- when ss.match?(/>/) then
- case
- when ss.skip(/\>\=/) then
- action { result :arg_state, :tGEQ, ">=" }
- when ss.skip(/\>\>=/) then
- action { result :arg_state, :tOP_ASGN, ">>" }
- when ss.skip(/\>\>/) then
- action { result :arg_state, :tRSHFT, ">>" }
- when ss.skip(/\>/) then
- action { result :arg_state, :tGT, ">" }
- end # group />/
- when ss.match?(/\`/) then
- case
- when expr_fname? && (ss.skip(/\`/)) then
- action { result(:expr_end, :tBACK_REF2, "`") }
- when expr_dot? && (ss.skip(/\`/)) then
- action { result((command_state ? :expr_cmdarg : :expr_arg), :tBACK_REF2, "`") }
- when ss.skip(/\`/) then
- action { string STR_XQUOTE, '`'; result(nil, :tXSTRING_BEG, "`") }
- end # group /\`/
- when text = ss.scan(/\?/) then
+ elsif ss.match?(/\*/) then
+ star_match
+ elsif ss.match?(/</) then
+ lt_match
+ elsif ss.match?(/>/) then
+ gt_match
+ elsif ss.match?(/\`/) then
+ backtick_match
+ elsif text = ss.scan(/\?/) then
process_questionmark text
- when ss.match?(/&/) then
- case
- when ss.skip(/\&\&\=/) then
- action { result(:expr_beg, :tOP_ASGN, "&&") }
- when ss.skip(/\&\&/) then
- action { result(:expr_beg, :tANDOP, "&&") }
- when ss.skip(/\&\=/) then
- action { result(:expr_beg, :tOP_ASGN, "&" ) }
- when ss.skip(/\&\./) then
- action { result(:expr_dot, :tLONELY, "&.") }
- when text = ss.scan(/\&/) then
- process_amper text
- end # group /&/
- when text = ss.scan(/\//) then
+ elsif ss.match?(/&/) then
+ ampersand_match
+ elsif text = ss.scan(/\//) then
process_slash text
- when ss.match?(/\^/) then
- case
- when ss.skip(/\^=/) then
- action { result(:expr_beg, :tOP_ASGN, "^") }
- when ss.skip(/\^/) then
- action { result(:arg_state, :tCARET, "^") }
- end # group /\^/
- when ss.skip(/\;/) then
- action { self.command_start = true; result(:expr_beg, :tSEMI, ";") }
- when ss.match?(/~/) then
- case
- when in_arg_state? && (ss.skip(/\~@/)) then
- action { result(:arg_state, :tTILDE, "~") }
- when ss.skip(/\~/) then
- action { result(:arg_state, :tTILDE, "~") }
- end # group /~/
- when ss.match?(/\\/) then
- case
- when ss.skip(/\\\r?\n/) then
- action { self.lineno += 1; self.space_seen = true; next }
- when ss.skip(/\\/) then
- action { rb_compile_error "bare backslash only allowed before newline" }
- end # group /\\/
- when text = ss.scan(/\%/) then
+ elsif ss.match?(/\^/) then
+ caret_match
+ elsif ss.skip(/\;/) then
+ self.command_start = true; result(:expr_beg, :tSEMI, ";")
+ elsif ss.match?(/~/) then
+ tilde_match
+ elsif ss.match?(/\\/) then
+ newline_match
+ elsif text = ss.scan(/\%/) then
process_percent text
- when ss.match?(/\$/) then
- case
- when text = ss.scan(/\$_\w+/) then
- process_gvar text
- when text = ss.scan(/\$_/) then
- process_gvar text
- when text = ss.scan(/\$[~*$?!@\/\\;,.=:<>\"]|\$-\w?/) then
- process_gvar text
- when in_fname? && (text = ss.scan(/\$([\&\`\'\+])/)) then
- process_gvar text
- when text = ss.scan(/\$([\&\`\'\+])/) then
- process_backref text
- when in_fname? && (text = ss.scan(/\$([1-9]\d*)/)) then
- process_gvar text
- when text = ss.scan(/\$([1-9]\d*)/) then
- process_nthref text
- when text = ss.scan(/\$0/) then
- process_gvar text
- when text = ss.scan(/\$\W|\$\z/) then
- process_gvar_oddity text
- when text = ss.scan(/\$\w+/) then
- process_gvar text
- end # group /\$/
- when text = ss.scan(/\_/) then
+ elsif ss.match?(/\$/) then
+ dollar_match
+ elsif text = ss.scan(/\_/) then
process_underscore text
- when text = ss.scan(/#{IDENT}/o) then
+ elsif text = ss.scan(/#{IDENT}/o) then
process_token text
- when ss.skip(/\004|\032|\000|\Z/) then
- action { [RubyLexer::EOF, RubyLexer::EOF] }
- when text = ss.scan(/./) then
- action { rb_compile_error "Invalid char #{text.inspect} in expression" }
+ elsif ss.skip(/\004|\032|\000|\Z/) then
+ [RubyLexer::EOF, RubyLexer::EOF]
+ elsif text = ss.scan(/./) then
+ rb_compile_error "Invalid char #{text.inspect} in expression"
else
text = ss.string[ss.pos .. -1]
raise ScanError, "can not match (#{state.inspect}): '#{text}'"
end
else
raise ScanError, "undefined state: '#{state}'"
end # token = case state
next unless token # allow functions to trigger redo w/ nil
end # while
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment