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
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col.
3 4 5 |
# File 'lib/bison_parser/base.rb', line 3 def col @col end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
2 3 4 |
# File 'lib/bison_parser/base.rb', line 2 def io @io end |
#lex_value ⇒ Object
Returns the value of attribute lex_value.
3 4 5 |
# File 'lib/bison_parser/base.rb', line 3 def lex_value @lex_value end |
#result ⇒ Object
Returns the value of attribute result.
4 5 6 |
# File 'lib/bison_parser/base.rb', line 4 def result @result end |
#row ⇒ Object
Returns the value of attribute row.
3 4 5 |
# File 'lib/bison_parser/base.rb', line 3 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.
4 5 6 |
# File 'lib/bison_parser/base.rb', line 4 def source @source end |
#token_col ⇒ Object
Returns the value of attribute token_col.
3 4 5 |
# File 'lib/bison_parser/base.rb', line 3 def token_col @token_col end |
#token_row ⇒ Object
Returns the value of attribute token_row.
3 4 5 |
# File 'lib/bison_parser/base.rb', line 3 def token_row @token_row end |
Instance Method Details
#lex ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bison_parser.rb', line 5 def lex x = real_lex Tokens.constants.each do |const| if Tokens.const_get(const) == x warn "Lex'd #{const}\t: #{lex_value.inspect}" if ENV['DEBUG_GRAMMAR'] return x end end warn "Lex'd #{x.inspect}" if ENV['DEBUG_GRAMMAR'] x end |
#parse ⇒ Object
1786 |
# File 'ext/bison_parser/bison_parser.c', line 1786 static VALUE bison_parser_parse(VALUE); |
#real_lex ⇒ Object
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bison_parser.rb', line 19 def real_lex self.section ||= 0 self.lex_value = nil if section == 2 self.lex_value = io.read self.section += 2 return Tokens::ACTIONS end # skip space while true while (c = self.read) && c =~ /\s/ end if c == '#' while (char = self.read) && char != "\n" end else break end end 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 when '"' string = '' while (c = self.read) && c != '"' string << c end self.lex_value = string return Tokens::STRING when "'" string = '' while (c = self.read) && c != "'" string << c end self.lex_value = string return Tokens::STRING 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 warn "Yielding literal #{c.inspect}" return c.ord end |