lib/ld/patch/parser.rb
# Parse patch
#
# The result is an S-List. Productions return an array such as the following:
#
#   (prefix ((: <http://example/>))
#
# @param [Symbol, #to_s] prod The starting production for the parser.
#   It may be a URI from the grammar, or a symbol representing the local_name portion of the grammar URI.
# @return [SPARQL::Algebra::Operator, Object]
# @raise [ParseError] when illegal grammar detected.
Parse patch
The result is an S-List. Productions return an array such as the following.


Parse patch The result is an S - List . Productions return an array such as the following .
def parse(prod = START)
      ll1_parse(@input,
        prod.to_sym,
        branch: BRANCH,
        first: FIRST,
        follow: FOLLOW,
        whitespace: WS,
        **@options
      ) do |context, *data|
        case context
        when :trace
          level, lineno, depth, *args = data
          message = args.to_sse
          d_str = depth > 100 ? ' ' * 100 + '+' : ' ' * depth
          str = "[#{lineno}](#{level})#{d_str}#{message}".chop
          if @errors && level == 0
            @errors << str
          else
            case @options[:debug]
            when Array
              @options[:debug] << str
            when TrueClass
              $stderr.puts str
            when Integer
              $stderr.puts(str) if level <= @options[:debug]
            end
          end
        end
      end
      @result = case
      when !prod_data.is_a?(Hash)
        prod_data
      when prod_data.empty?
        nil
      when prod_data[:ldpatch]
        prod_data[:ldpatch]
      else
        key = prod_data.keys.first
        [key] + Array(prod_data[key])  
      end
      @result.validate! if @result && validate?
      @result
    rescue EBNF::LL1::Parser::Error, EBNF::LL1::Lexer::Error =>  e
      raise LD::Patch::ParseError.new(e.message, lineno: e.lineno, token: e.token)
    end
def parse ( prod = START ) ll1_parse ( @input , prod . to_sym , branch : BRANCH , first : FIRST , follow : FOLLOW , whitespace : WS , ** @options ) do | context , * data | case context when :trace level , lineno , depth , * args = data message = args . to_sse d_str = depth > 100 ? ' ' * 100 + '+' : ' ' * depth str = "[#{lineno}](#{level})#{d_str}#{message}" . chop if @errors && level == 0 @errors << str else case @options [ :debug ] when Array @options [ :debug ] << str when TrueClass $stderr . puts str when Integer $stderr . puts ( str ) if level <= @options [ :debug ] end end end end @result = case when ! prod_data . is_a? ( Hash ) prod_data when prod_data . empty? nil when prod_data [ :ldpatch ] prod_data [ :ldpatch ] else key = prod_data . keys . first [ key ] + Array ( prod_data [ key ] ) end @result . validate! if @result && validate? @result rescue EBNF :: LL1 :: Parser :: Error , EBNF :: LL1 :: Lexer :: Error => e raise LD :: Patch :: ParseError . new ( e . message , lineno : e . lineno , token : e . token ) end
Parse patch
The result is an S-List.
Parse patch The result is an S - List .
# The last thing on the @prod_data stack is the result # Creates [:key, [:triple], ...] # Validate resulting expression
None
SPARQL::Algebra::Operator, Object
[ParseError] when illegal grammar detected.
[ ParseError ] when illegal grammar detected .
prod
<not_specific>
<not_specific>
prod The starting production for the parser. It may be a URI from the grammar, or a symbol representing the local_name portion of the grammar URI.
prod The starting production for the parser . It may be a URI from the grammar or a symbol representing the local_name portion of the grammar URI .