Class: GraphQL::CParser::Parser
- Inherits:
-
Object
- Object
- GraphQL::CParser::Parser
- Defined in:
- lib/graphql/c_parser.rb,
ext/graphql_c_parser_ext/graphql_c_parser_ext.c
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#next_token_index ⇒ Object
readonly
Returns the value of attribute next_token_index.
-
#query_string ⇒ Object
readonly
Returns the value of attribute query_string.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
- .parse(query_str, filename: nil, trace: GraphQL::Tracing::NullTrace, max_tokens: nil) ⇒ Object
- .parse_file(filename) ⇒ Object
Instance Method Summary collapse
- #c_parse ⇒ Object
-
#initialize(query_string, filename, trace, max_tokens) ⇒ Parser
constructor
A new instance of Parser.
- #result ⇒ Object
- #tokens_count ⇒ Object
Constructor Details
#initialize(query_string, filename, trace, max_tokens) ⇒ Parser
Returns a new instance of Parser.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/graphql/c_parser.rb', line 99 def initialize(query_string, filename, trace, max_tokens) if query_string.nil? raise GraphQL::ParseError.new("No query string was present", nil, nil, query_string) end @query_string = query_string @filename = filename @tokens = nil @next_token_index = 0 @result = nil @trace = trace @intern_identifiers = false @max_tokens = max_tokens end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
131 132 133 |
# File 'lib/graphql/c_parser.rb', line 131 def filename @filename end |
#next_token_index ⇒ Object (readonly)
Returns the value of attribute next_token_index.
131 132 133 |
# File 'lib/graphql/c_parser.rb', line 131 def next_token_index @next_token_index end |
#query_string ⇒ Object (readonly)
Returns the value of attribute query_string.
131 132 133 |
# File 'lib/graphql/c_parser.rb', line 131 def query_string @query_string end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
131 132 133 |
# File 'lib/graphql/c_parser.rb', line 131 def tokens @tokens end |
Class Method Details
.parse(query_str, filename: nil, trace: GraphQL::Tracing::NullTrace, max_tokens: nil) ⇒ Object
90 91 92 |
# File 'lib/graphql/c_parser.rb', line 90 def self.parse(query_str, filename: nil, trace: GraphQL::Tracing::NullTrace, max_tokens: nil) self.new(query_str, filename, trace, max_tokens).result end |
.parse_file(filename) ⇒ Object
94 95 96 97 |
# File 'lib/graphql/c_parser.rb', line 94 def self.parse_file(filename) contents = File.read(filename) parse(contents, filename: filename) end |
Instance Method Details
#c_parse ⇒ Object
7 8 9 10 |
# File 'ext/graphql_c_parser_ext/graphql_c_parser_ext.c', line 7 VALUE GraphQL_CParser_Parser_c_parse(VALUE self) { yyparse(self, rb_ivar_get(self, rb_intern("@filename"))); return Qnil; } |
#result ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/graphql/c_parser.rb', line 113 def result if @result.nil? @tokens = @trace.lex(query_string: @query_string) do GraphQL::CParser::Lexer.tokenize(@query_string, intern_identifiers: @intern_identifiers, max_tokens: @max_tokens) end @trace.parse(query_string: @query_string) do c_parse @result end end @result end |
#tokens_count ⇒ Object
126 127 128 129 |
# File 'lib/graphql/c_parser.rb', line 126 def tokens_count result @tokens.length end |