Class: BisonParser
- Inherits:
-
Object
- Object
- BisonParser
- Includes:
- Base
- Defined in:
- lib/bison_parser.rb,
lib/bison_parser/base.rb,
lib/bison_parser/actions.rb,
ext/bison_parser/bison_parser.c
Defined Under Namespace
Modules: Base, Tokens Classes: Actions, Error
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#lex_value ⇒ Object
Returns the value of attribute lex_value.
-
#result ⇒ Object
Returns the value of attribute result.
-
#row ⇒ Object
Returns the value of attribute row.
-
#section ⇒ Object
Returns the value of attribute section.
-
#source ⇒ Object
Returns the value of attribute source.
-
#token_col ⇒ Object
Returns the value of attribute token_col.
-
#token_row ⇒ Object
Returns the value of attribute token_row.
Instance Method Summary collapse
Methods included from Base
#begin_token, #error, #initialize, #peak, #read, #read_integer, #read_over_whitespace
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col.
5 6 7 |
# File 'lib/bison_parser/base.rb', line 5 def col @col end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
4 5 6 |
# File 'lib/bison_parser/base.rb', line 4 def io @io end |
#lex_value ⇒ Object
Returns the value of attribute lex_value.
5 6 7 |
# File 'lib/bison_parser/base.rb', line 5 def lex_value @lex_value end |
#result ⇒ Object
Returns the value of attribute result.
6 7 8 |
# File 'lib/bison_parser/base.rb', line 6 def result @result end |
#row ⇒ Object
Returns the value of attribute row.
5 6 7 |
# File 'lib/bison_parser/base.rb', line 5 def row @row end |
#section ⇒ Object
Returns the value of attribute section.
3 4 5 |
# File 'lib/bison_parser.rb', line 3 def section @section end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/bison_parser/base.rb', line 6 def source @source end |
#token_col ⇒ Object
Returns the value of attribute token_col.
5 6 7 |
# File 'lib/bison_parser/base.rb', line 5 def token_col @token_col end |
#token_row ⇒ Object
Returns the value of attribute token_row.
5 6 7 |
# File 'lib/bison_parser/base.rb', line 5 def token_row @token_row end |
Instance Method Details
#lex ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bison_parser.rb', line 5 def lex self.section ||= 0 self.lex_value = nil if section == 2 self.lex_value = io.read self.section += 2 return Tokens::ACTIONS end c = read_over_whitespace(line_comment_prefix: '#') return nil unless c case c when ':' return Tokens::COLON when ';' return Tokens::SEMICOLON when '|' return Tokens::PIPE when '%' if self.peak == '%' self.read self.section += 1 return Tokens::DOUBLE_HASH end return Tokens::HASH when '[' return Tokens::LBRACK when ']' return Tokens::RBRACK when '{' nesting = 1 action = '' while (c = self.read) && nesting > 0 nesting += 1 if c == '{' nesting -= 1 if c == '}' action << c unless nesting.zero? end self.lex_value = action return Tokens::ACTIONS when '0'..'9' number = c while (c = self.peak) && ('0'..'9').include?(c) number << self.read end self.lex_value = number.to_i return Tokens::NUMBER end if c =~ /\w/ string = c while (c = self.peak) && c =~ /\w/ self.read string << c end if section.zero? && string == 'token' return Tokens::KW_TOKEN elsif section.zero? && string == 'left' return Tokens::KW_LEFT elsif section.zero? && string == 'right' return Tokens::KW_RIGHT else self.lex_value = string return Tokens::IDENTIFIER end end return nil end |
#parse ⇒ Object
1792 |
# File 'ext/bison_parser/bison_parser.c', line 1792 static VALUE bison_parser_parse(VALUE); |