Method: CEML::Instructions#_nt_condition

Defined in:
lib/ceml/lang/tt/instructions.rb

#_nt_conditionObject



1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
# File 'lib/ceml/lang/tt/instructions.rb', line 1060

def _nt_condition
  start_index = index
  if node_cache[:condition].has_key?(index)
    cached = node_cache[:condition][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_ws
  s0 << r1
  if r1
    i2 = index
    if has_terminal?('if', false, index)
      r3 = instantiate_node(SyntaxNode,input, index...(index + 2))
      @index += 2
    else
      terminal_parse_failure('if')
      r3 = nil
    end
    if r3
      r2 = r3
    else
      if has_terminal?('unless', false, index)
        r4 = instantiate_node(SyntaxNode,input, index...(index + 6))
        @index += 6
      else
        terminal_parse_failure('unless')
        r4 = nil
      end
      if r4
        r2 = r4
      else
        @index = i2
        r2 = nil
      end
    end
    s0 << r2
    if r2
      r5 = _nt_ws
      s0 << r5
      if r5
        r6 = _nt_id
        s0 << r6
      end
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Condition0)
    r0.extend(Condition1)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:condition][start_index] = r0

  r0
end