Esempio n. 1
0
    static private Rule Parse(String rulename, String text, bool trace)
    {
        if (rulename == null)
        {
            throw new ArgumentNullException("null rulename");
        }
        if (text == null)
        {
            throw new ArgumentException("null string");
        }

        ParserContext context = new ParserContext(text, trace);

        Rule rule = null;

        if (rulename.ToLower().Equals("did".ToLower()))
        {
            rule = Rule_did.Parse(context);
        }
        else if (rulename.ToLower().Equals("did-method".ToLower()))
        {
            rule = Rule_did_method.Parse(context);
        }
        else if (rulename.ToLower().Equals("did-root".ToLower()))
        {
            rule = Rule_did_root.Parse(context);
        }
        else if (rulename.ToLower().Equals("method".ToLower()))
        {
            rule = Rule_method.Parse(context);
        }
        else if (rulename.ToLower().Equals("methodchar".ToLower()))
        {
            rule = Rule_methodchar.Parse(context);
        }
        else if (rulename.ToLower().Equals("method-specific-idstring".ToLower()))
        {
            rule = Rule_method_specific_idstring.Parse(context);
        }
        else if (rulename.ToLower().Equals("idstring".ToLower()))
        {
            rule = Rule_idstring.Parse(context);
        }
        else if (rulename.ToLower().Equals("idchar".ToLower()))
        {
            rule = Rule_idchar.Parse(context);
        }
        else if (rulename.ToLower().Equals("did-uri".ToLower()))
        {
            rule = Rule_did_uri.Parse(context);
        }
        else if (rulename.ToLower().Equals("did-optional-transform".ToLower()))
        {
            rule = Rule_did_optional_transform.Parse(context);
        }
        else if (rulename.ToLower().Equals("did-method-transform".ToLower()))
        {
            rule = Rule_did_method_transform.Parse(context);
        }
        else if (rulename.ToLower().Equals("did-root-transform".ToLower()))
        {
            rule = Rule_did_root_transform.Parse(context);
        }
        else if (rulename.ToLower().Equals("transform".ToLower()))
        {
            rule = Rule_transform.Parse(context);
        }
        else if (rulename.ToLower().Equals("transformer".ToLower()))
        {
            rule = Rule_transformer.Parse(context);
        }
        else if (rulename.ToLower().Equals("transformer-namedvalue".ToLower()))
        {
            rule = Rule_transformer_namedvalue.Parse(context);
        }
        else if (rulename.ToLower().Equals("transformer-option".ToLower()))
        {
            rule = Rule_transformer_option.Parse(context);
        }
        else if (rulename.ToLower().Equals("transformer-value".ToLower()))
        {
            rule = Rule_transformer_value.Parse(context);
        }
        else if (rulename.ToLower().Equals("transformer-char".ToLower()))
        {
            rule = Rule_transformer_char.Parse(context);
        }
        else if (rulename.ToLower().Equals("TRANSFORM".ToLower()))
        {
            rule = Rule_TRANSFORM.Parse(context);
        }
        else if (rulename.ToLower().Equals("generic-option".ToLower()))
        {
            rule = Rule_generic_option.Parse(context);
        }
        else if (rulename.ToLower().Equals("transformer-options".ToLower()))
        {
            rule = Rule_transformer_options.Parse(context);
        }
        else if (rulename.ToLower().Equals("URI".ToLower()))
        {
            rule = Rule_URI.Parse(context);
        }
        else if (rulename.ToLower().Equals("hier-part".ToLower()))
        {
            rule = Rule_hier_part.Parse(context);
        }
        else if (rulename.ToLower().Equals("scheme".ToLower()))
        {
            rule = Rule_scheme.Parse(context);
        }
        else if (rulename.ToLower().Equals("authority".ToLower()))
        {
            rule = Rule_authority.Parse(context);
        }
        else if (rulename.ToLower().Equals("userinfo".ToLower()))
        {
            rule = Rule_userinfo.Parse(context);
        }
        else if (rulename.ToLower().Equals("host".ToLower()))
        {
            rule = Rule_host.Parse(context);
        }
        else if (rulename.ToLower().Equals("port".ToLower()))
        {
            rule = Rule_port.Parse(context);
        }
        else if (rulename.ToLower().Equals("IP-literal".ToLower()))
        {
            rule = Rule_IP_literal.Parse(context);
        }
        else if (rulename.ToLower().Equals("IPvFuture".ToLower()))
        {
            rule = Rule_IPvFuture.Parse(context);
        }
        else if (rulename.ToLower().Equals("IPv6address".ToLower()))
        {
            rule = Rule_IPv6address.Parse(context);
        }
        else if (rulename.ToLower().Equals("h16".ToLower()))
        {
            rule = Rule_h16.Parse(context);
        }
        else if (rulename.ToLower().Equals("ls32".ToLower()))
        {
            rule = Rule_ls32.Parse(context);
        }
        else if (rulename.ToLower().Equals("IPv4address".ToLower()))
        {
            rule = Rule_IPv4address.Parse(context);
        }
        else if (rulename.ToLower().Equals("dec-octet".ToLower()))
        {
            rule = Rule_dec_octet.Parse(context);
        }
        else if (rulename.ToLower().Equals("reg-name".ToLower()))
        {
            rule = Rule_reg_name.Parse(context);
        }
        else if (rulename.ToLower().Equals("path-abempty".ToLower()))
        {
            rule = Rule_path_abempty.Parse(context);
        }
        else if (rulename.ToLower().Equals("path-absolute".ToLower()))
        {
            rule = Rule_path_absolute.Parse(context);
        }
        else if (rulename.ToLower().Equals("path-rootless".ToLower()))
        {
            rule = Rule_path_rootless.Parse(context);
        }
        else if (rulename.ToLower().Equals("segment".ToLower()))
        {
            rule = Rule_segment.Parse(context);
        }
        else if (rulename.ToLower().Equals("segment-nz".ToLower()))
        {
            rule = Rule_segment_nz.Parse(context);
        }
        else if (rulename.ToLower().Equals("pchar".ToLower()))
        {
            rule = Rule_pchar.Parse(context);
        }
        else if (rulename.ToLower().Equals("query".ToLower()))
        {
            rule = Rule_query.Parse(context);
        }
        else if (rulename.ToLower().Equals("fragment".ToLower()))
        {
            rule = Rule_fragment.Parse(context);
        }
        else if (rulename.ToLower().Equals("pct-encoded".ToLower()))
        {
            rule = Rule_pct_encoded.Parse(context);
        }
        else if (rulename.ToLower().Equals("unreserved".ToLower()))
        {
            rule = Rule_unreserved.Parse(context);
        }
        else if (rulename.ToLower().Equals("sub-delims".ToLower()))
        {
            rule = Rule_sub_delims.Parse(context);
        }
        else if (rulename.ToLower().Equals("other-delims".ToLower()))
        {
            rule = Rule_other_delims.Parse(context);
        }
        else if (rulename.ToLower().Equals("pchar-no-SQUOTE".ToLower()))
        {
            rule = Rule_pchar_no_SQUOTE.Parse(context);
        }
        else if (rulename.ToLower().Equals("pct-encoded-no-SQUOTE".ToLower()))
        {
            rule = Rule_pct_encoded_no_SQUOTE.Parse(context);
        }
        else if (rulename.ToLower().Equals("qchar-no-AMP".ToLower()))
        {
            rule = Rule_qchar_no_AMP.Parse(context);
        }
        else if (rulename.ToLower().Equals("qchar-no-AMP-EQ".ToLower()))
        {
            rule = Rule_qchar_no_AMP_EQ.Parse(context);
        }
        else if (rulename.ToLower().Equals("qchar-no-AMP-EQ-AT-DOLLAR".ToLower()))
        {
            rule = Rule_qchar_no_AMP_EQ_AT_DOLLAR.Parse(context);
        }
        else if (rulename.ToLower().Equals("ALPHA".ToLower()))
        {
            rule = Rule_ALPHA.Parse(context);
        }
        else if (rulename.ToLower().Equals("DIGIT".ToLower()))
        {
            rule = Rule_DIGIT.Parse(context);
        }
        else if (rulename.ToLower().Equals("HEXDIG".ToLower()))
        {
            rule = Rule_HEXDIG.Parse(context);
        }
        else if (rulename.ToLower().Equals("A-to-F".ToLower()))
        {
            rule = Rule_A_to_F.Parse(context);
        }
        else if (rulename.ToLower().Equals("DQUOTE".ToLower()))
        {
            rule = Rule_DQUOTE.Parse(context);
        }
        else if (rulename.ToLower().Equals("SP".ToLower()))
        {
            rule = Rule_SP.Parse(context);
        }
        else if (rulename.ToLower().Equals("HTAB".ToLower()))
        {
            rule = Rule_HTAB.Parse(context);
        }
        else if (rulename.ToLower().Equals("VCHAR".ToLower()))
        {
            rule = Rule_VCHAR.Parse(context);
        }
        else
        {
            throw new ArgumentException("unknown rule");
        }

        if (rule == null)
        {
            throw new ParserException(
                      "rule \"" + (String)context.GetErrorStack().Peek() + "\" failed",
                      context.text,
                      context.GetErrorIndex(),
                      context.GetErrorStack());
        }

        if (context.text.Length > context.index)
        {
            ParserException primaryError =
                new ParserException(
                    "extra data found",
                    context.text,
                    context.index,
                    new Stack <String>());

            if (context.GetErrorIndex() > context.index)
            {
                ParserException secondaryError =
                    new ParserException(
                        "rule \"" + (String)context.GetErrorStack().Peek() + "\" failed",
                        context.text,
                        context.GetErrorIndex(),
                        context.GetErrorStack());

                primaryError.SetCause(secondaryError);
            }

            throw primaryError;
        }

        return(rule);
    }
Esempio n. 2
0
    public static Rule_did Parse(ParserContext context)
    {
        context.Push("did");

        Rule rule;
        bool parsed = true;
        ParserAlternative b;
        int s0 = context.index;
        ParserAlternative a0 = new ParserAlternative(s0);

        List <ParserAlternative> as1 = new List <ParserAlternative>();

        parsed = false;
        {
            int s1 = context.index;
            ParserAlternative a1 = new ParserAlternative(s1);
            parsed = true;
            if (parsed)
            {
                bool f1 = true;
                int  c1 = 0;
                for (int i1 = 0; i1 < 1 && f1; i1++)
                {
                    rule = Rule_did_method.Parse(context);
                    if ((f1 = rule != null))
                    {
                        a1.Add(rule, context.index);
                        c1++;
                    }
                }
                parsed = c1 == 1;
            }
            if (parsed)
            {
                bool f1 = true;
                int  c1 = 0;
                for (int i1 = 0; i1 < 1 && f1; i1++)
                {
                    rule = Rule_method_specific_idstring.Parse(context);
                    if ((f1 = rule != null))
                    {
                        a1.Add(rule, context.index);
                        c1++;
                    }
                }
                parsed = c1 == 1;
            }
            if (parsed)
            {
                as1.Add(a1);
            }
            context.index = s1;
        }

        b = ParserAlternative.GetBest(as1);

        parsed = b != null;

        if (parsed)
        {
            a0.Add(b.rules, b.end);
            context.index = b.end;
        }

        rule = null;
        if (parsed)
        {
            rule = new Rule_did(context.text.Substring(a0.start, a0.end - a0.start), a0.rules);
        }
        else
        {
            context.index = s0;
        }

        context.Pop("did", parsed);

        return((Rule_did)rule);
    }