Skip to content

Commit

Permalink
Reorganize lexer/parser in lib
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 25, 2013
1 parent 36c74a6 commit f4a7848
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/opal/parser.rb
@@ -1,7 +1,7 @@
require 'opal/sexp'
require 'opal/lexer'
require 'opal/grammar'
require 'opal/parser_scope'
require 'opal/parser/sexp'
require 'opal/parser/lexer'
require 'opal/parser/grammar'
require 'opal/parser/parser_scope'

module Opal
class Parser < Racc::Parser
Expand Down
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions lib/opal/parser/keywords.rb
@@ -0,0 +1,40 @@
module Opal
module Keywords
KEYWORDS = [
["__LINE__", [:LINE, :LINE], :expr_end],
["__FILE__", [:FILE, :FILE], :expr_end],
["alias", [:ALIAS, :ALIAS], :expr_fname],
["and", [:AND, :AND], :expr_beg],
["begin", [:BEGIN, :BEGIN], :expr_beg],
["break", [:BREAK, :BREAK], :expr_mid],
["case", [:CASE, :CASE], :expr_beg],
["class", [:CLASS, :CLASS], :expr_class],
["def", [:DEF, :DEF], :expr_fname],
["defined?", [:DEFINED, :DEFINED], :expr_arg],
["do", [:DO, :DO], :expr_beg],
["else", [:ELSE, :ELSE], :expr_beg],
["elsif", [:ELSE, :ELSE], :expr_beg],
["end", [:END, :END], :expr_end],
["ensure", [:ENSURE, :ENSURE], :expr_beg],
["false", [:FALSE, :FALSE], :expr_end],
["if", [:IF, :IF_MOD], :expr_beg],
["module", [:MODULE, :MODULE], :expr_beg],
["nil", [:NIL, :NIL], :expr_end],
["next", [:NEXT, :NEXT], :expr_mid],
["not", [:NOT, :NOT], :expr_beg],
["or", [:OR, :OR], :expr_beg],
["redo", [:REDO, :REDO], :expr_end],
["rescue", [:RESCUE, :RESCUE_MOD], :expr_mid],
["return", [:RETURN, :RETURN], :expr_mid],
["super", [:SUPER, :SUPER], :expr_arg],
["then", [:THEN, :THEN], :expr_beg],
["true", [:TRUE, :TRUE], :expr_end],
["undef", [:UNDEF, :UNDEF], :expr_fname],
["unless", [:UNLESS, :UNLESS_MOD], :expr_beg],
["until", [:UNTIL, :UNTIL_MOD], :expr_beg],
["when", [:CASE, :CASE], :expr_beg],
["while", [:WHILE, :WHILE_MOD], :expr_beg],
["yield", [:YIELD, :YIELD], :expr_arg]
]
end
end
7 changes: 4 additions & 3 deletions lib/opal/lexer.rb → lib/opal/parser/lexer.rb
@@ -1,4 +1,5 @@
require 'strscan'
require 'opal/parser/keywords'

module Opal
class Lexer
Expand Down Expand Up @@ -907,7 +908,7 @@ def next_token
return :IDENTIFIER, matched
end

@lex_state = :expr_class
@lex_state = :expr_beg
return :MODULE, matched

when 'defined?'
Expand Down Expand Up @@ -1125,7 +1126,7 @@ def next_token
return :IDENTIFIER, matched
end

@lex_state = :expr_arg
@lex_state = :expr_beg
return :NOT, matched

when 'return'
Expand All @@ -1152,7 +1153,7 @@ def next_token
return :IDENTIFIER, matched
end

@lex_state = :expr_mid
@lex_state = :expr_end
return :REDO, matched

when 'break'
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit f4a7848

Please sign in to comment.