Class: RKelly::Parser
- Inherits:
-
GeneratedParser
- Object
- Racc::Parser
- GeneratedParser
- RKelly::Parser
- Defined in:
- lib/rkelly/parser.rb
Constant Summary collapse
Constants inherited from GeneratedParser
GeneratedParser::Racc_arg, GeneratedParser::Racc_debug_parser, GeneratedParser::Racc_token_to_s_table
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
-
#parse(javascript, filename = nil) ⇒ Object
Parse
javascript
and return an AST. -
#stopped_at ⇒ Object
When parsing finishes without all tokens being parsed, returns the token at which the parsing stopped.
- #yyabort ⇒ Object
Methods inherited from GeneratedParser
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
30 31 32 33 34 35 36 |
# File 'lib/rkelly/parser.rb', line 30 def initialize @tokens = [] @logger = nil @terminator = false @prev_token = nil @comments = [] end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
29 30 31 |
# File 'lib/rkelly/parser.rb', line 29 def logger @logger end |
Instance Method Details
#parse(javascript, filename = nil) ⇒ Object
Parse javascript
and return an AST
39 40 41 42 43 44 45 46 |
# File 'lib/rkelly/parser.rb', line 39 def parse(javascript, filename = nil) @tokens = TOKENIZER.raw_tokens(javascript) @position = 0 @filename = filename ast = do_parse ast.comments = @comments if ast ast end |
#stopped_at ⇒ Object
When parsing finishes without all tokens being parsed, returns the token at which the parsing stopped. Returns nil when parser reached to the very last token (but possibly still failed as it expeced more tokens).
Useful for pin-pointing the position of a syntax error.
58 59 60 61 62 63 64 |
# File 'lib/rkelly/parser.rb', line 58 def stopped_at if @position < @tokens.length @tokens[@position-1] else nil end end |
#yyabort ⇒ Object
48 49 50 |
# File 'lib/rkelly/parser.rb', line 48 def yyabort raise "something bad happened, please report a bug with sample JavaScript" end |