Exemple #1
0
    static void DomainCharSeq(LexerSource <UString> src)
    {
        int la0;

        src.Match(DomainCharSeq_set0);
        // Line 150: (([\-])? [0-9A-Za-z])*
        for (;;)
        {
            la0 = src.LA0;
            if (DomainCharSeq_set1.Contains(la0))
            {
                // Line 150: ([\-])?
                la0 = src.LA0;
                if (la0 == '-')
                {
                    src.Skip();
                }
                src.Match(DomainCharSeq_set0);
            }
            else
            {
                break;
            }
        }
    }
Exemple #2
0
    /// <summary>Parses email addresses according to RFC 5322, not including
    /// quoted usernames or non-ASCII addresses (TODO: support Unicode).</summary>
    /// <exception cref="FormatException">The input is not a legal email address.</exception>
    public static EmailAddress Parse(UString email)
    {
        int la0;

        // line 153
        if (src == null)
        {
            src = new LexerSource <UString>(email, "", 0, false);
        }
        else
        {
            src.Reset(email, "", 0, false);             // re-use old object
        }
        UsernameChars(src);
        // Line 158: ([.] UsernameChars)*
        for (;;)
        {
            la0 = src.LA0;
            if (la0 == '.')
            {
                src.Skip();
                UsernameChars(src);
            }
            else
            {
                break;
            }
        }
        // line 159
        int at = src.InputPosition;
        // line 160
        UString userName = email.Substring(0, at);

        src.Match('@');
        DomainCharSeq(src);
        // Line 162: ([.] DomainCharSeq)*
        for (;;)
        {
            la0 = src.LA0;
            if (la0 == '.')
            {
                src.Skip();
                DomainCharSeq(src);
            }
            else
            {
                break;
            }
        }
        src.Match(-1);
        // line 163
        UString domain = email.Substring(at + 1);

        // line 164
        return(new EmailAddress(userName, domain));
    }
Exemple #3
0
    public static EmailAddress Parse(UString email)
    {
        int la0;

                #line 158 "Samples.ecs"
        if (src == null)
        {
            src = new LexerSource <UString>(email, "", 0, false);
        }
        else
        {
            src.Reset(email, "", 0, false);
        }
                #line default
        UsernameChars(src);
        // Line 163: ([.] UsernameChars)*
        for (;;)
        {
            la0 = src.LA0;
            if (la0 == '.')
            {
                src.Skip();
                UsernameChars(src);
            }
            else
            {
                break;
            }
        }
        int     at       = src.InputPosition;
        UString userName = email.Substring(0, at);
        src.Match('@');
        DomainCharSeq(src);
        // Line 167: ([.] DomainCharSeq)*
        for (;;)
        {
            la0 = src.LA0;
            if (la0 == '.')
            {
                src.Skip();
                DomainCharSeq(src);
            }
            else
            {
                break;
            }
        }
        src.Match(-1);
        UString domain = email.Substring(at + 1);
        return(new EmailAddress(userName, domain));
    }
Exemple #4
0
    static void UsernameChars(LexerSource <UString> src)
    {
        int la0;

        src.Match(UsernameChars_set0);
        // Line 145: ([!#-'*+\-/-9=?A-Z^-~])*
        for (;;)
        {
            la0 = src.LA0;
            if (UsernameChars_set0.Contains(la0))
            {
                src.Skip();
            }
            else
            {
                break;
            }
        }
    }
Exemple #5
0
        public static bool CanPrintAsNumber(UString textValue, Symbol typeMarker)
        {
            int la0;

            // Check if the typeMarker is potentially acceptable for printing as a number
            // line 26
            if (typeMarker.Name.TryGet(0, '\0') != '_' || !IsNormalIdentifier(typeMarker.Name))
            {
                return(false);
            }
            // line 28
            char firstTMChar = typeMarker.Name.TryGet(1, '\0');

            // line 29
            if (firstTMChar == 'e' || firstTMChar == 'E' || firstTMChar == 'p' || firstTMChar == 'P')
            {
                return(false);
            }

            // Prepare LexerSource needed by LLLPG, and our error counter
            // line 33
            if (src == null)
            {
                src           = new LexerSource <UString>(textValue, "", 0, false);
                src.ErrorSink = msgCounter = new NullMessageSink();
            }
            else
            {
                src.Reset(textValue, "", 0, false);                     // re-use old object
                msgCounter.ResetCountersToZero();
            }

            // Find out whether textValue is in numeric format
            // line 42
            bool isHex = false;

            // Line 44: ([−])?
            do
            {
                la0 = src.LA0;
                if (la0 == '−')
                {
                    src.Skip();
                }
                else if (la0 == -1 || la0 == '.' || la0 >= '0' && la0 <= '9')
                {
                    ;
                }
                else
                {
                    src.Error(0, "In rule 'CanPrintAsNumber', expected one of: [\\$.0-9−]");
                }
            } while (false);
            // Line 45: ( BinNumber / HexNumber / DecNumber )
            la0 = src.LA0;
            if (la0 == '0')
            {
                switch (src.LA(1))
                {
                case 'B':
                case 'b':
                    BinNumber();
                    break;

                case 'X':
                case 'x':
                {
                    HexNumber();
                    // line 46
                    isHex = true;
                }
                break;

                case -1:
                case '\'':
                case '.':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case 'E':
                case '_':
                case 'e':
                    DecNumber();
                    break;

                default:
                    src.Error(1, "In rule 'CanPrintAsNumber', expected one of: [\\$'.0-9BEX_bex]");
                    break;
                }
            }
            else if (la0 == '.' || la0 >= '1' && la0 <= '9')
            {
                DecNumber();
            }
            else
            {
                src.Error(0, "In rule 'CanPrintAsNumber', expected one of: [.0-9]");
            }
            src.Match(-1);
            // line 50
            return(msgCounter.ErrorCount == 0 &&
                   !(isHex && (firstTMChar >= 'a' && firstTMChar <= 'f' || firstTMChar >= 'A' && firstTMChar <= 'F')));
        }
Exemple #6
0
 public CalculatorLexer(ICharSource text, string fileName = "")
 {
     Src = new LexerSource(text);
 }
Exemple #7
0
 public CalculatorLexer(string text, string fileName = "")
 {
     Src = (LexerSource)text;
 }
Exemple #8
0
 public CalculatorLexer(string charSource)
 {
     _src = new LexerSource(charSource);
 }