Removed generated lexer/parser.

I am a dumbass.
This commit is contained in:
Yorick Peterse 2014-03-25 21:47:40 +01:00
parent fb626278a8
commit 4a48647d1e
3 changed files with 2 additions and 1512 deletions

4
.gitignore vendored
View File

@ -3,5 +3,5 @@ coverage
pkg
Gemfile.lock
lib/oga/lexer.rb
lib/oga/parser.rb
lib/oga/xml/lexer.rb
lib/oga/xml/parser.rb

File diff suppressed because it is too large Load Diff

View File

@ -1,402 +0,0 @@
#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.4.11
# from Racc grammer file "".
#
require 'racc/parser.rb'
module Oga
module XML
class Parser < Racc::Parser
##
# @param [Hash] options
#
# @option options [TrueClass|FalseClass] :html Enables HTML parsing mode.
# @see Oga::Lexer#initialize
#
def initialize(options = {})
@lexer = Lexer.new(options)
end
##
# Resets the internal state of the parser.
#
def reset
@lines = []
@line = 1
end
##
# Emits a new AST token.
#
# @param [Symbol] type
# @param [Array] children
#
def s(type, *children)
return AST::Node.new(
type,
children.flatten,
:line => @line
)
end
##
# Returns the next token from the lexer.
#
# @return [Array]
#
def next_token
type, value, line = @tokens.shift
@line = line if line
return type ? [type, value] : [false, false]
end
##
# @param [Fixnum] type The type of token the error occured on.
# @param [String] value The value of the token.
# @param [Array] stack The current stack of parsed nodes.
# @raise [Racc::ParseError]
#
def on_error(type, value, stack)
name = token_to_str(type)
index = @line - 1
lines = ''
# Show up to 5 lines before and after the offending line (if they exist).
(-5..5).each do |offset|
line = @lines[index + offset]
number = @line + offset
if line and number > 0
if offset == 0
prefix = '=> '
else
prefix = ' '
end
lines << "#{prefix}#{number}: #{line.strip}\n"
end
end
raise Racc::ParseError, <<-EOF
Unexpected #{name} with value #{value.inspect} on line #{@line}:
#{lines}
EOF
end
##
# Parses the supplied string and returns the AST.
#
# @example
# parser = Oga::Parser.new
# ast = parser.parse('<foo>bar</foo>')
#
# @param [String] string
# @return [Oga::AST::Node]
#
def parse(string)
@lines = string.lines
@tokens = @lexer.lex(string)
ast = do_parse
reset
return ast
end
# vim: set ft=racc:
##### State transition tables begin ###
racc_action_table = [
16, 40, 16, 10, 24, 37, 11, 22, 12, 28,
14, 23, 21, 45, 31, 15, 16, 10, 44, 28,
11, 43, 12, 36, 14, 35, 16, 10, 34, 15,
11, 41, 12, 42, 14, 33, 16, 10, 17, 15,
11, 46, 12, nil, 14, 29, 30, 19, 20, 15 ]
racc_action_check = [
15, 28, 38, 38, 12, 24, 38, 11, 38, 13,
38, 12, 11, 38, 15, 38, 2, 2, 35, 26,
2, 35, 2, 22, 2, 20, 25, 25, 20, 2,
25, 30, 25, 32, 25, 17, 0, 0, 1, 25,
0, 44, 0, nil, 0, 14, 14, 10, 10, 0 ]
racc_action_pointer = [
33, 38, 13, nil, nil, nil, nil, nil, nil, nil,
42, 4, 1, -6, 33, -3, nil, 35, nil, nil,
23, nil, 15, nil, -5, 23, 4, nil, -1, nil,
19, nil, 16, nil, nil, 16, nil, nil, -1, nil,
nil, nil, nil, nil, 36, nil, nil ]
racc_action_default = [
-2, -32, -1, -4, -6, -7, -8, -9, -10, -11,
-32, -32, -32, -24, -32, -32, -31, -32, -3, -12,
-32, -16, -32, -18, -32, -5, -23, -26, -27, -21,
-32, -29, -32, 47, -13, -32, -17, -19, -32, -25,
-28, -22, -30, -14, -32, -20, -15 ]
racc_goto_table = [
18, 2, 27, 32, 25, 26, 1, nil, nil, nil,
nil, nil, nil, nil, nil, 39, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, 38, nil, nil, nil,
nil, nil, nil, nil, nil, nil, 18 ]
racc_goto_check = [
3, 2, 13, 8, 11, 12, 1, nil, nil, nil,
nil, nil, nil, nil, nil, 13, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, 2, nil, nil, nil,
nil, nil, nil, nil, nil, nil, 3 ]
racc_goto_pointer = [
nil, 6, 1, -2, nil, nil, nil, nil, -12, nil,
nil, -9, -8, -11 ]
racc_goto_default = [
nil, nil, nil, 3, 4, 5, 6, 7, 8, 9,
13, nil, nil, nil ]
racc_reduce_table = [
0, 0, :racc_error,
1, 19, :_reduce_1,
0, 19, :_reduce_2,
2, 20, :_reduce_3,
1, 20, :_reduce_4,
0, 20, :_reduce_5,
1, 21, :_reduce_none,
1, 21, :_reduce_none,
1, 21, :_reduce_none,
1, 21, :_reduce_none,
1, 21, :_reduce_none,
1, 21, :_reduce_none,
2, 22, :_reduce_12,
3, 22, :_reduce_13,
4, 22, :_reduce_14,
5, 22, :_reduce_15,
2, 23, :_reduce_16,
3, 23, :_reduce_17,
2, 24, :_reduce_18,
3, 24, :_reduce_19,
4, 25, :_reduce_20,
2, 28, :_reduce_21,
3, 28, :_reduce_22,
1, 29, :_reduce_23,
0, 29, :_reduce_24,
2, 30, :_reduce_25,
1, 30, :_reduce_26,
1, 31, :_reduce_27,
2, 31, :_reduce_28,
2, 27, :_reduce_29,
3, 27, :_reduce_30,
1, 26, :_reduce_31 ]
racc_reduce_n = 32
racc_shift_n = 47
racc_token_table = {
false => 0,
:error => 1,
:T_STRING => 2,
:T_TEXT => 3,
:T_DOCTYPE_START => 4,
:T_DOCTYPE_END => 5,
:T_DOCTYPE_TYPE => 6,
:T_CDATA_START => 7,
:T_CDATA_END => 8,
:T_COMMENT_START => 9,
:T_COMMENT_END => 10,
:T_ELEM_START => 11,
:T_ELEM_NAME => 12,
:T_ELEM_NS => 13,
:T_ELEM_END => 14,
:T_ATTR => 15,
:T_XML_DECL_START => 16,
:T_XML_DECL_END => 17 }
racc_nt_base = 18
racc_use_result_var = false
Racc_arg = [
racc_action_table,
racc_action_check,
racc_action_default,
racc_action_pointer,
racc_goto_table,
racc_goto_check,
racc_goto_default,
racc_goto_pointer,
racc_nt_base,
racc_reduce_table,
racc_token_table,
racc_shift_n,
racc_reduce_n,
racc_use_result_var ]
Racc_token_to_s_table = [
"$end",
"error",
"T_STRING",
"T_TEXT",
"T_DOCTYPE_START",
"T_DOCTYPE_END",
"T_DOCTYPE_TYPE",
"T_CDATA_START",
"T_CDATA_END",
"T_COMMENT_START",
"T_COMMENT_END",
"T_ELEM_START",
"T_ELEM_NAME",
"T_ELEM_NS",
"T_ELEM_END",
"T_ATTR",
"T_XML_DECL_START",
"T_XML_DECL_END",
"$start",
"document",
"expressions",
"expression",
"doctype",
"cdata",
"comment",
"element",
"text",
"xmldecl",
"element_open",
"attributes",
"attributes_",
"attribute" ]
Racc_debug_parser = false
##### State transition tables end #####
# reduce 0 omitted
def _reduce_1(val, _values)
s(:document, val[0])
end
def _reduce_2(val, _values)
s(:document)
end
def _reduce_3(val, _values)
val.compact
end
def _reduce_4(val, _values)
val[0]
end
def _reduce_5(val, _values)
nil
end
# reduce 6 omitted
# reduce 7 omitted
# reduce 8 omitted
# reduce 9 omitted
# reduce 10 omitted
# reduce 11 omitted
def _reduce_12(val, _values)
s(:doctype)
end
def _reduce_13(val, _values)
s(:doctype, val[1])
end
def _reduce_14(val, _values)
s(:doctype, val[1], val[2])
end
def _reduce_15(val, _values)
s(:doctype, val[1], val[2], val[3])
end
def _reduce_16(val, _values)
s(:cdata)
end
def _reduce_17(val, _values)
s(:cdata, val[1])
end
def _reduce_18(val, _values)
s(:comment)
end
def _reduce_19(val, _values)
s(:comment, val[1])
end
def _reduce_20(val, _values)
s(:element, val[0], val[1], val[2])
end
def _reduce_21(val, _values)
[nil, val[1]]
end
def _reduce_22(val, _values)
[val[1], val[2]]
end
def _reduce_23(val, _values)
s(:attributes, val[0])
end
def _reduce_24(val, _values)
nil
end
def _reduce_25(val, _values)
val
end
def _reduce_26(val, _values)
val
end
def _reduce_27(val, _values)
s(:attribute, val[0])
end
def _reduce_28(val, _values)
s(:attribute, val[0], val[1])
end
def _reduce_29(val, _values)
s(:xml_decl)
end
def _reduce_30(val, _values)
s(:xml_decl, val[1])
end
def _reduce_31(val, _values)
s(:text, val[0])
end
def _reduce_none(val, _values)
val[0]
end
end # class Parser
end # module XML
end # module Oga