Class: BisonParser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Base

#begin_token, #error, #initialize, #peak, #read, #read_integer, #read_over_whitespace

Instance Attribute Details

#colObject

Returns the value of attribute col.



5
6
7
# File 'lib/bison_parser/base.rb', line 5

def col
  @col
end

#ioObject (readonly)

Returns the value of attribute io.



4
5
6
# File 'lib/bison_parser/base.rb', line 4

def io
  @io
end

#lex_valueObject

Returns the value of attribute lex_value.



5
6
7
# File 'lib/bison_parser/base.rb', line 5

def lex_value
  @lex_value
end

#resultObject

Returns the value of attribute result.



6
7
8
# File 'lib/bison_parser/base.rb', line 6

def result
  @result
end

#rowObject

Returns the value of attribute row.



5
6
7
# File 'lib/bison_parser/base.rb', line 5

def row
  @row
end

#sectionObject

Returns the value of attribute section.



3
4
5
# File 'lib/bison_parser.rb', line 3

def section
  @section
end

#sourceObject

Returns the value of attribute source.



6
7
8
# File 'lib/bison_parser/base.rb', line 6

def source
  @source
end

#token_colObject

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_rowObject

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

#lexObject



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

#parseObject



1792
# File 'ext/bison_parser/bison_parser.c', line 1792

static VALUE bison_parser_parse(VALUE);