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 =
[ "&.", "&&", "&&=", "**", "*=", "+=", "-=", "..", "...", "/=", "::", "<<=", "<<", "<=>", "<=", "===", "==", "=~", ">=", ">>=", ">>", "||=", "||", "|=", "!==", "!=", "!~", "%=", "^=", "=>" ].sort_by(&:length).reverse.freeze
- CONTINUATION_KEYWORDS =
%w[or and rescue].freeze
- POSTFIX_CONTINUATIONS =
%w[. :: &.].freeze
- HORIZONTAL_WHITESPACE =
[" ", "\t"].freeze
- NEWLINE_CHARACTERS =
["\n", "\r"].freeze
- PUNCTUATION_CHARACTERS =
%w[( ) [ ] { } , ? :].freeze
- OPERATOR_CHARACTERS =
%w[. & | = ! ~ + - * / % < > ^ × ÷].freeze
- SUFFIX_PUNCTUATION =
%w[! ?].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
Returns a new instance of Parser.
130 131 132 133 134 |
# File 'lib/code/parser.rb', line 130 def initialize(input) @input = input.to_s @tokens = lex(@input) @index = 0 end |
Class Method Details
.parse ⇒ Object
136 137 138 |
# File 'lib/code/parser.rb', line 136 def self.parse(...) new(...).parse end |