Module: GraphQL::CParser
- Defined in:
- lib/graphql/c_parser.rb,
lib/graphql/c_parser/version.rb,
ext/graphql_c_parser_ext/graphql_c_parser_ext.c
Defined Under Namespace
Modules: Lexer Classes: Parser, SchemaParser
Constant Summary collapse
- VERSION =
"1.1.4"
Class Method Summary collapse
- .parse(query_str, filename: nil, trace: GraphQL::Tracing::NullTrace, max_tokens: nil) ⇒ Object
- .parse_file(filename) ⇒ Object
- .prepare_bad_unicode_error(parser) ⇒ Object
- .prepare_number_name_parse_error(line, col, query_str, number_part, name_part) ⇒ Object
- .prepare_parse_error(message, parser) ⇒ Object
- .tokenize_with_c(str) ⇒ Object
Class Method Details
.parse(query_str, filename: nil, trace: GraphQL::Tracing::NullTrace, max_tokens: nil) ⇒ Object
9 10 11 |
# File 'lib/graphql/c_parser.rb', line 9 def self.parse(query_str, filename: nil, trace: GraphQL::Tracing::NullTrace, max_tokens: nil) Parser.parse(query_str, filename: filename, trace: trace, max_tokens: max_tokens) end |
.parse_file(filename) ⇒ Object
13 14 15 16 |
# File 'lib/graphql/c_parser.rb', line 13 def self.parse_file(filename) contents = File.read(filename) parse(contents, filename: filename) end |
.prepare_bad_unicode_error(parser) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/graphql/c_parser.rb', line 53 def self.prepare_bad_unicode_error(parser) token = parser.tokens[parser.next_token_index - 1] line = token[1] col = token[2] GraphQL::ParseError.new( "Parse error on bad Unicode escape sequence: #{token[3].inspect} (error) at [#{line}, #{col}]", line, col, parser.query_string, filename: parser.filename ) end |
.prepare_number_name_parse_error(line, col, query_str, number_part, name_part) ⇒ Object
49 50 51 |
# File 'lib/graphql/c_parser.rb', line 49 def self.prepare_number_name_parse_error(line, col, query_str, number_part, name_part) raise GraphQL::ParseError.new("Name after number is not allowed (in `#{number_part}#{name_part}`)", line, col, query_str) end |
.prepare_parse_error(message, parser) ⇒ Object
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 |
# File 'lib/graphql/c_parser.rb', line 23 def self.prepare_parse_error(, parser) query_str = parser.query_string filename = parser.filename if .start_with?("memory exhausted") return GraphQL::ParseError.new("This query is too large to execute.", nil, nil, query_str, filename: filename) end token = parser.tokens[parser.next_token_index - 1] if token # There might not be a token if it's a comments-only string line = token[1] col = token[2] if line && col location_str = " at [#{line}, #{col}]" if !.include?(location_str) += location_str end end if !.include?("end of file") .sub!(/, unexpected ([a-zA-Z ]+)(,| at)/, ", unexpected \\1 (#{token[3].inspect})\\2") end end GraphQL::ParseError.new(, line, col, query_str, filename: filename) end |
.tokenize_with_c(str) ⇒ Object
18 19 20 21 |
# File 'lib/graphql/c_parser.rb', line 18 def self.tokenize_with_c(str) reject_numbers_followed_by_names = GraphQL.respond_to?(:reject_numbers_followed_by_names) && GraphQL.reject_numbers_followed_by_names tokenize_with_c_internal(str, false, reject_numbers_followed_by_names) end |