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.
31 32 33 34 35 36 37 |
# File 'lib/rkelly/parser.rb', line 31 def initialize @tokens = [] @logger = nil @terminator = false @prev_token = nil @comments = [] end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
30 31 32 |
# File 'lib/rkelly/parser.rb', line 30 def logger @logger end |
Instance Method Details
#parse(javascript, filename = nil) ⇒ Object
Parse javascript
and return an AST
40 41 42 43 44 45 46 47 |
# File 'lib/rkelly/parser.rb', line 40 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.
59 60 61 62 63 64 65 |
# File 'lib/rkelly/parser.rb', line 59 def stopped_at if @position < @tokens.length @tokens[@position-1] else nil end end |
#yyabort ⇒ Object
49 50 51 |
# File 'lib/rkelly/parser.rb', line 49 def yyabort raise "something bad happened, please report a bug with sample JavaScript" end |