Class: Code::Parser
Defined Under Namespace
Classes: Error, Language, Token
Constant Summary collapse
- KEYWORDS =
%w[ and begin do else elsif elsunless end false if loop not nothing or rescue true unless until while ].freeze
- MULTI_CHAR_OPERATORS =
%w[ &. && &&= ** *= += -= .. ... /= :: <<= << <=> <= === == =~ >= >>= >> ||= || |= !== != !~ %= ^= => ].sort_by(&:length).reverse.freeze
- ASSIGNMENT_RHS_MIN_BP =
20- INFIX_PRECEDENCE =
{ "if" => [10, 9], "unless" => [10, 9], "while" => [10, 9], "until" => [10, 9], "or" => [20, 21], "=" => [30, 29], "+=" => [30, 29], "-=" => [30, 29], "*=" => [30, 29], "/=" => [30, 29], "%=" => [30, 29], "<<=" => [30, 29], ">>=" => [30, 29], "&=" => [30, 29], "|=" => [30, 29], "^=" => [30, 29], "||=" => [30, 29], "&&=" => [30, 29], "rescue" => [35, 34], "?" => [40, 39], ".." => [50, 51], "..." => [50, 51], "||" => [60, 61], "and" => [70, 71], "&&" => [70, 71], "==" => [80, 81], "===" => [80, 81], "!=" => [80, 81], "!==" => [80, 81], "<=>" => [80, 81], "=~" => [80, 81], "~=" => [80, 81], "!~" => [80, 81], ">=" => [90, 91], "<=" => [90, 91], ">" => [90, 91], "<" => [90, 91], "|" => [100, 101], "^" => [105, 106], "&" => [110, 111], "<<" => [120, 121], ">>" => [120, 121], "+" => [130, 131], "-" => [130, 131], "*" => [140, 141], "/" => [140, 141], "%" => [140, 141], "×" => [140, 141], "÷" => [140, 141], "**" => [160, 159] }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(input) ⇒ Parser
122 123 124 125 126 |
# File 'lib/code/parser.rb', line 122 def initialize(input) @input = input.to_s @tokens = lex(@input) @index = 0 end |
Class Method Details
.parse ⇒ Object
128 129 130 |
# File 'lib/code/parser.rb', line 128 def self.parse(...) new(...).parse end |
Instance Method Details
#parse ⇒ Object
132 133 134 |
# File 'lib/code/parser.rb', line 132 def parse Node::Code.new(parse_code) end |