Module: GraphQL::CParser::Lexer

Defined in:
lib/graphql/c_parser.rb,
ext/graphql_c_parser_ext/graphql_c_parser_ext.c

Class Method Summary collapse

Class Method Details

.tokenize(graphql_string, intern_identifiers: false, max_tokens: nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/graphql/c_parser.rb', line 67

def self.tokenize(graphql_string, intern_identifiers: false, max_tokens: nil)
  if !(graphql_string.encoding == Encoding::UTF_8 || graphql_string.ascii_only?)
    graphql_string = graphql_string.dup.force_encoding(Encoding::UTF_8)
  end
  if !graphql_string.valid_encoding?
    return [
      [
        :BAD_UNICODE_ESCAPE,
        1,
        1,
        graphql_string,
        241 # BAD_UNICODE_ESCAPE in lexer.rl
      ]
    ]
  end
  reject_numbers_followed_by_names = GraphQL.respond_to?(:reject_numbers_followed_by_names) && GraphQL.reject_numbers_followed_by_names
  # -1 indicates that there is no limit
  lexer_max_tokens = max_tokens.nil? ? -1 : max_tokens
  tokenize_with_c_internal(graphql_string, intern_identifiers, reject_numbers_followed_by_names, lexer_max_tokens)
end

.tokenize_with_c_internal(query_string, fstring_identifiers, reject_numbers_followed_by_names, max_tokens) ⇒ Object



3
4
5
# File 'ext/graphql_c_parser_ext/graphql_c_parser_ext.c', line 3

VALUE GraphQL_CParser_Lexer_tokenize_with_c_internal(VALUE self, VALUE query_string, VALUE fstring_identifiers, VALUE reject_numbers_followed_by_names, VALUE max_tokens) {
  return tokenize(query_string, RTEST(fstring_identifiers), RTEST(reject_numbers_followed_by_names), FIX2INT(max_tokens));
}