コード例 #1
0
        void ParseNumberValue()
        {
            int start = _startPosition;

            if (_numberBase != 10)
            {
                start += 2;
            }
            int stop = InputPosition;

            if (_typeSuffix != null)
            {
                stop -= _typeSuffix.Name.Length;
            }

            UString digits = CharSource.Slice(start, stop - start);
            string  error;

            if ((_value = Les2Lexer.ParseNumberCore(digits, false, _numberBase, _isFloat, _typeSuffix, out error)) == null)
            {
                _value = 0;
            }
            else if (_value == CodeSymbols.Sub)
            {
                InputPosition = _startPosition + 1;
                _type         = TT.Sub;
            }
            if (error != null)
            {
                Error(_startPosition - InputPosition, error);
            }
        }
コード例 #2
0
 protected UString UnescapeString(bool isTripleQuoted, bool allowExtraIndent = false)
 {
     if (SkipValueParsing)
     {
         return("");
     }
     if (_hasEscapes)
     {
         UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
         _textValue = Les3Lexer.UnescapeQuotedString(ref original, Error, IndentString, allowExtraIndent);
         Debug.Assert(original.IsEmpty);
     }
     else
     {
         Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
         if (isTripleQuoted)
         {
             _textValue = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
         }
         else
         {
             _textValue = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
         }
     }
     return(_textValue);
 }
コード例 #3
0
        void ParseSymbolValue()
        {
            if (SkipValueParsing)
            {
                _value = GSymbol.Empty;
                return;
            }
            Debug.Assert(CharSource[_startPosition] == '@' && CharSource[_startPosition + 1] == '@');
            UString original = CharSource.Slice(_startPosition + 2, InputPosition - _startPosition - 2);

            if (_parseNeeded)
            {
                string text = UnescapeQuotedString(ref original, Error);
                Debug.Assert(original.IsEmpty);
                _value = IdToSymbol(text);
            }
            else if (original[0, '\0'] == '`')
            {
                _value = IdToSymbol(original.Substring(1, original.Length - 2));
            }
            else
            {
                _value = IdToSymbol(original);
            }
        }
コード例 #4
0
        void ParseIdValue()
        {
            if (SkipValueParsing)
            {
                _value = GSymbol.Empty;
                return;
            }
            UString id;

            if (_parseNeeded)
            {
                // includes @etc-etc and @`backquoted`
                UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
                bool    checkForNamedLiteral;
                id = ParseIdentifier(ref original, Error, out checkForNamedLiteral);
                Debug.Assert(original.IsEmpty);
                if (checkForNamedLiteral)
                {
                    object namedValue;
                    if (NamedLiterals.TryGetValue(id, out namedValue))
                    {
                        _value = namedValue;
                        _type  = TT.Literal;
                        return;
                    }
                }
            }
            else               // normal identifier
            {
                id = CharSource.Slice(_startPosition, InputPosition - _startPosition);
            }

            _value = IdToSymbol(id);
        }
コード例 #5
0
        protected string ParseStringValue(bool parseNeeded, bool isTripleQuoted)
        {
            if (SkipValueParsing)
            {
                return(null);
            }
            string value;

            if (parseNeeded)
            {
                UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
                value = Les2Lexer.UnescapeQuotedString(ref original, Error, IndentString, true);
                Debug.Assert(original.IsEmpty);
            }
            else
            {
                Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
                if (isTripleQuoted)
                {
                    value = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
                }
                else
                {
                    value = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
                }
            }
            return(value);
        }
コード例 #6
0
ファイル: Les2Lexer.cs プロジェクト: qwertie/LoycCore
        protected object ParseSymbolValue(bool lesv3 = false)
        {
            if (SkipValueParsing)
            {
                return(_value = GSymbol.Empty);
            }
            Debug.Assert(CharSource[_startPosition] == '@' && CharSource[_startPosition + 1] == '@');
            UString original = CharSource.Slice(_startPosition + 2, InputPosition - _startPosition - 2);

            if (_parseNeeded)
            {
                string text = UnescapeQuotedString(ref original, Error);
                Debug.Assert(original.IsEmpty);
                return(_value = IdToSymbol(text));
            }
            else if (original[0, '\0'] == '`')
            {
                return(_value = IdToSymbol(original.Substring(1, original.Length - 2)));
            }
            else
            {
                if (lesv3 && NamedLiterals.TryGetValue(original, out _value))
                {
                    return(_value);
                }
                return(_value = IdToSymbol(original));
            }
        }
コード例 #7
0
ファイル: LesLexer.cs プロジェクト: bel-uwa/Loyc
        string ParseStringCore(bool isTripleQuoted)
        {
            if (SkipValueParsing)
            {
                return("");
            }
            string value;

            if (_parseNeeded)
            {
                UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
                value = UnescapeQuotedString(ref original, Error, _indent);
                Debug.Assert(original.IsEmpty);
            }
            else
            {
                Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
                if (isTripleQuoted)
                {
                    value = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
                }
                else
                {
                    value = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
                }
            }
            return(value);
        }
コード例 #8
0
        Symbol ParseIdOrSymbol(int start, bool isBQString)
        {
            UString unparsed = CharSource.Slice(start, InputPosition - start);
            UString parsed;

            Debug.Assert(isBQString == (CharSource.TryGet(start, '\0') == '`'));
            Debug.Assert(!_verbatim);
            if (_idCache.TryGetValue(unparsed, out Symbol value))
            {
                return(value);
            }
            else
            {
                if (isBQString)
                {
                    parsed = UnescapeQuotedString(start);
                }
                else if (_parseNeeded)
                {
                    parsed = ScanNormalIdentifier(unparsed);
                }
                else
                {
                    parsed = unparsed;
                }
                return(_idCache[unparsed.ShedExcessMemory(50)] = (Symbol)parsed);
            }
        }
コード例 #9
0
        string ParseStringCore(int start)
        {
            Debug.Assert(_verbatim == (CharSource[start] == '@'));
            if (_verbatim)
            {
                start++;
            }
            char q;

            Debug.Assert((q = CharSource.TryGet(start, '\0')) == '"' || q == '\'' || q == '`');
            bool tripleQuoted = (_style & NodeStyle.BaseStyleMask) == NodeStyle.TDQStringLiteral ||
                                (_style & NodeStyle.BaseStyleMask) == NodeStyle.TQStringLiteral;

            string value;

            if (!_parseNeeded)
            {
                Debug.Assert(!tripleQuoted);
                value = (string)CharSource.Slice(start + 1, InputPosition - start - 2).ToString();
            }
            else
            {
                UString original = CharSource.Slice(start, InputPosition - start);
                value = UnescapeQuotedString(ref original, _verbatim, Error, _indent);
            }
            return(value);
        }
コード例 #10
0
        protected void UnescapeSymbolValue()
        {
            Debug.Assert(CharSource[_startPosition] == '@' && CharSource[_startPosition + 1] == '@');
            if (SkipValueParsing)
            {
                return;
            }

            _value = _s;
            UString original = CharSource.Slice(_startPosition + 2, InputPosition - _startPosition - 2);

            if (_hasEscapes)
            {
                _textValue = Les3Lexer.UnescapeQuotedString(ref original, Error);
                Debug.Assert(original.IsEmpty);
            }
            else if (original[0, '\0'] == '`')
            {
                _textValue = original.Substring(1, original.Length - 2);
            }
            else
            {
                _textValue = original;
            }
        }
コード例 #11
0
ファイル: Grammar.out.cs プロジェクト: myblindy/rg
        private void Num()
        {
            int la0, la1;
            // line 116
            bool dot = false;

            // Line 117: ([.])?
            la0 = LA0;
            if (la0 == '.')
            {
                Skip();
                // line 117
                dot = true;
            }
            MatchRange('0', '9');
            // Line 118: ([0-9])*
            for (;;)
            {
                la0 = LA0;
                if (la0 >= '0' && la0 <= '9')
                {
                    Skip();
                }
                else
                {
                    break;
                }
            }
            // Line 119: (&!{dot} [.] [0-9] ([0-9])*)?
            la0 = LA0;
            if (la0 == '.')
            {
                if (!dot)
                {
                    la1 = LA(1);
                    if (la1 >= '0' && la1 <= '9')
                    {
                        Skip();
                        Skip();
                        // Line 119: ([0-9])*
                        for (;;)
                        {
                            la0 = LA0;
                            if (la0 >= '0' && la0 <= '9')
                            {
                                Skip();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            // line 120
            _value = double.Parse(CharSource.Slice(_startIndex, InputPosition - _startIndex).ToString());
        }
コード例 #12
0
        string String()
        {
            int    la0;
            string result  = default(string);
            int    start   = InputPosition;
            bool   escaped = false;

            Match('"');
            // Line 60: ([\\] [^\$] | default [^\$-\x1F"\\])*
            for (;;)
            {
                la0 = LA0;
                if (la0 == '\\')
                {
                    Skip();
                    MatchExcept();
                    // line 60
                    escaped = true;
                }
                else if (!(la0 >= -1 && la0 <= '\x1F' || la0 == '"'))
                {
                    Skip();
                }
                else if (la0 == -1 || la0 == '"')
                {
                    break;
                }
                else
                {
                    // line 60
                    Error(0, "Control character not permitted");
                    MatchExcept();
                }
            }
            // Line 61: (["])
            la0 = LA0;
            if (la0 == '"')
            {
                Skip();
            }
            else
            {
                // line 61
                Error(0, "Expected closing quote");
            }
            // line 63
            UString text = CharSource.Slice(start + 1, InputPosition - start - 2);

            if (escaped)
            {
                result = ParseHelpers.UnescapeCStyle(text);
            }
            else
            {
                result = (string)text;
            }
            return(result);
        }
コード例 #13
0
ファイル: BaseILexer.cs プロジェクト: murven/Loyc
        /// <summary>Scans indentation at the beginning of a line and updates the
        /// <see cref="IndentLevel"/> and <see cref="IndentString"/> properties.
        /// This function is called automatically by <see cref="AfterNewline()"/>,
        /// but should be called manually on the very first line of the file.</summary>
        /// <remarks>Parameters are documented at <see cref="AfterNewline(bool,bool)"/></remarks>
        protected void ScanIndent(bool skipSpaces = true)
        {
            int li = 0, indentLevel = 0;

            if (SupportDotIndents() && LA0 == '.')
            {
                for (;;)
                {
                    if (LA(li) == '.')
                    {
                        var la1 = LA(li + 1);
                        if (la1 == '\t' || la1 == ' ')
                        {
                            li          += 2;
                            indentLevel += SpacesPerTab;
                            for (; LA(li) == ' '; li++)
                            {
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            for (;;)
            {
                var la0 = LA(li);
                if (la0 == ' ')
                {
                    li++;
                    indentLevel++;
                }
                else if (la0 == '\t')
                {
                    li++;
                    indentLevel += SpacesPerTab;
                    indentLevel -= indentLevel % SpacesPerTab;
                }
                else
                {
                    break;
                }
            }
            _indentLevel  = indentLevel;
            _indentString = CharSource.Slice(InputPosition, li);
            if (skipSpaces)
            {
                InputPosition += li;
            }
        }
コード例 #14
0
ファイル: Les2LexerGrammar.out.cs プロジェクト: dadhi/ecsharp
        private void Number()
        {
            int la0;

            // Line 67: ([−])?
            la0 = LA0;
            if (la0 == '−')
            {
                Skip();
            }
            // Line 68: ( HexNumber / BinNumber / DecNumber )
            la0 = LA0;
            if (la0 == '0')
            {
                switch (LA(1))
                {
                case 'X':
                case 'x':
                    HexNumber();
                    break;

                case 'B':
                case 'b':
                    BinNumber();
                    break;

                default:
                    DecNumber();
                    break;
                }
            }
            else
            {
                DecNumber();
            }
            // line 69
            _textValue = Text();
            // Line 70: (NormalId / {..})
            la0 = LA0;
            if (Number_set0.Contains(la0))
            {
                // line 70
                int suffixStart = InputPosition;
                NormalId();
                // line 72
                _value = IdToSymbol("_" + CharSource.Slice(suffixStart, InputPosition - suffixStart));
            }
            else
            {
                // line 73
                _value = sy__;
            }
        }
コード例 #15
0
ファイル: LesLexer.cs プロジェクト: bel-uwa/Loyc
        void ParseIdValue()
        {
            if (SkipValueParsing)
            {
                _value = GSymbol.Empty;
                return;
            }
            UString id;

            if (_parseNeeded)
            {
                // includes @etc-etc and @`backquoted`
                UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
                bool    checkForNamedLiteral;
                id = ParseIdentifier(ref original, Error, out checkForNamedLiteral);
                Debug.Assert(original.IsEmpty);
                if (checkForNamedLiteral)
                {
                    if (id == TrueString)
                    {
                        _value = BoxedTrue;
                        _type  = TT.OtherLit;
                        return;
                    }
                    else if (id == FalseString)
                    {
                        _value = BoxedFalse;
                        _type  = TT.OtherLit;
                        return;
                    }
                    else if (id == NullString)
                    {
                        _value = null;
                        _type  = TT.OtherLit;
                        return;
                    }
                    else if (id == VoidString)
                    {
                        _value = BoxedVoid;
                        _type  = TT.OtherLit;
                        return;
                    }
                }
            }
            else               // normal identifier
            {
                id = CharSource.Slice(_startPosition, InputPosition - _startPosition);
            }

            _value = IdToSymbol(id);
        }
コード例 #16
0
        void ParseNumberValue()
        {
            if (SkipValueParsing)
            {
                _value = CG.Cache(0);
                return;
            }
            // Optimize the most common case: a one-digit integer
            if (InputPosition == _startPosition + 1)
            {
                Debug.Assert(char.IsDigit(CharSource[_startPosition]));
                _value = CG.Cache((int)(CharSource[_startPosition] - '0'));
                return;
            }

            int start = _startPosition;

            if (_isNegative)
            {
                start++;
            }
            if (_numberBase != 10)
            {
                start += 2;
            }
            int stop = InputPosition;

            if (_typeSuffix != null)
            {
                stop -= _typeSuffix.Name.Length;
            }

            UString digits = CharSource.Slice(start, stop - start);
            string  error;

            if ((_value = ParseNumberCore(digits, _isNegative, _numberBase, _isFloat, _typeSuffix, out error)) == null)
            {
                _value = 0;
            }
            else if (_value == CodeSymbols.Sub)
            {
                InputPosition = _startPosition + 1;
                _type         = TT.NormalOp;
            }
            if (error != null)
            {
                Error(_startPosition, error);
            }
        }
コード例 #17
0
ファイル: LesLexer.cs プロジェクト: bel-uwa/Loyc
        void ParseOp(bool backslashOp)
        {
            UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);

            Pair <Symbol, TokenType> sym;

            if (_opCache.TryGetValue(original, out sym))
            {
                _value = sym.A;
                _type  = sym.B;
            }
            else
            {
                Debug.Assert(backslashOp == (original[0] == '\\'));
                // op will be the operator text without the initial backslash, if any:
                // && => &&, \foo => foo, \`foo` => foo, \`@`\ => @\
                UString op = original;
                if (backslashOp)
                {
                    if (original.Length == 1)
                    {
                        // Just a single backslash is the "\" operator
                        _opCache[original.ToString()] = sym = Pair.Create(_Backslash, TT.NormalOp);
                        _value = sym.A;
                        _type  = sym.B;
                        return;
                    }
                    op = original.Substring(1);
                    if (_parseNeeded)
                    {
                        var  sb = TempSB();
                        bool _;
                        var  quoted = original;
                        if (quoted[0] != '`')
                        {
                            sb.Append((char)quoted.PopFront(out _));
                        }
                        UnescapeQuotedString(ref quoted, Error, sb);
                        op = sb.ToString();
                    }
                }

                string opStr = op.ToString();
                _type           = GetOpType(opStr);
                _opCache[opStr] = sym = Pair.Create(GSymbol.Get(opStr), _type);
                _value          = sym.A;
            }
        }
コード例 #18
0
        void ParseSQStringValue()
        {
            int c = -1;

            if (SkipValueParsing)
            {
                c = '\0';
            }
            else
            {
                int len = InputPosition - _startPosition;
                if (!_parseNeeded && len == 3)
                {
                    c = CharSource[_startPosition + 1];
                }
                else
                {
                    var     sb       = TempSB();
                    UString original = CharSource.Slice(_startPosition, len);
                    UnescapeQuotedString(ref original, Error, sb, IndentString);
                    Debug.Assert(original.IsEmpty);
                    if (sb.Length == 1)
                    {
                        c = sb[0];
                    }
                    else
                    {
                        _value = sb.ToString();
                        if (sb.Length == 0)
                        {
                            Error(_startPosition, Localize.Localized("Empty character literal"));
                        }
                        else
                        {
                            Error(_startPosition, Localize.Localized("Character literal has {0} characters (there should be exactly one)", sb.Length));
                        }
                    }
                }
            }
            if (c != -1)
            {
                _value = CG.Cache((char)c);
            }
        }
コード例 #19
0
ファイル: Grammar.out.cs プロジェクト: myblindy/rg
        private void Id()
        {
            int la0;

            Skip();
            // Line 111: ([0-9A-Z_a-z])*
            for (;;)
            {
                la0 = LA0;
                if (Id_set0.Contains(la0))
                {
                    Skip();
                }
                else
                {
                    break;
                }
            }
            // line 112
            _value = (Symbol)(CharSource.Slice(_startIndex, InputPosition - _startIndex).ToString());
        }
コード例 #20
0
        void Id()
        {
            int la0;

            Skip();
            // Line 116: ([0-9A-Z_a-z])*
            for (;;)
            {
                la0 = LA0;
                if (Id_set0.Contains(la0))
                {
                    Skip();
                }
                else
                {
                    break;
                }
            }
                        #line 117 "MyGrammars.ecs"
            _value = (Symbol)(CharSource.Slice(_startIndex, InputPosition - _startIndex).ToString());
                        #line default
        }
コード例 #21
0
        void ParseIdOrSymbol(int start, bool isBQString)
        {
            UString unparsed = CharSource.Slice(start, InputPosition - start);
            UString parsed;

            Debug.Assert(isBQString == (CharSource.TryGet(start, '\0') == '`'));
            Debug.Assert(!_verbatim);
            if (!_idCache.TryGetValue(unparsed, out _value))
            {
                if (isBQString)
                {
                    parsed = ParseStringCore(start);
                }
                else if (_parseNeeded)
                {
                    parsed = ScanNormalIdentifier(unparsed);
                }
                else
                {
                    parsed = unparsed;
                }
                _idCache[unparsed.ShedExcessMemory(50)] = _value = GSymbol.Get(parsed.ToString());
            }
        }
コード例 #22
0
ファイル: Les3.cs プロジェクト: dadhi/ecsharp
        protected UString GetUnescapedString(bool hasEscapes, bool isTripleQuoted)
        {
            UString value;

            if (hasEscapes)
            {
                UString original = Text();
                value = UnescapeQuotedString(ref original, Error, IndentString, true);
                Debug.Assert(original.IsEmpty);
            }
            else
            {
                Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
                if (isTripleQuoted)
                {
                    value = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
                }
                else
                {
                    value = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
                }
            }
            return(value);
        }
コード例 #23
0
        object WordLiteral()
        {
            int    la0, la1, la2, la3, la4;
            object result = default(object);
            int    start  = InputPosition;

            // Line 86: ( [t] [r] [u] [e] / [f] [a] [l] [s] [e] / [n] [u] [l] [l] / [A-Za-z] ([A-Za-z])* )
            do
            {
                la0 = LA0;
                if (la0 == 't')
                {
                    la1 = LA(1);
                    if (la1 == 'r')
                    {
                        la2 = LA(2);
                        if (la2 == 'u')
                        {
                            la3 = LA(3);
                            if (la3 == 'e')
                            {
                                switch (LA(4))
                                {
                                case -1:
                                case '\t':
                                case '\n':
                                case '\r':
                                case ' ':
                                case ',':
                                case '/':
                                case ']':
                                case '}':
                                {
                                    Skip();
                                    Skip();
                                    Skip();
                                    Skip();
                                    // line 86
                                    result = G.BoxedTrue;
                                }
                                break;

                                default:
                                    goto match4;
                                }
                            }
                            else
                            {
                                goto match4;
                            }
                        }
                        else
                        {
                            goto match4;
                        }
                    }
                    else
                    {
                        goto match4;
                    }
                }
                else if (la0 == 'f')
                {
                    la1 = LA(1);
                    if (la1 == 'a')
                    {
                        la2 = LA(2);
                        if (la2 == 'l')
                        {
                            la3 = LA(3);
                            if (la3 == 's')
                            {
                                la4 = LA(4);
                                if (la4 == 'e')
                                {
                                    switch (LA(5))
                                    {
                                    case -1:
                                    case '\t':
                                    case '\n':
                                    case '\r':
                                    case ' ':
                                    case ',':
                                    case '/':
                                    case ']':
                                    case '}':
                                    {
                                        Skip();
                                        Skip();
                                        Skip();
                                        Skip();
                                        Skip();
                                        // line 87
                                        return(G.BoxedFalse);
                                    }

                                    default:
                                        goto match4;
                                    }
                                }
                                else
                                {
                                    goto match4;
                                }
                            }
                            else
                            {
                                goto match4;
                            }
                        }
                        else
                        {
                            goto match4;
                        }
                    }
                    else
                    {
                        goto match4;
                    }
                }
                else if (la0 == 'n')
                {
                    la1 = LA(1);
                    if (la1 == 'u')
                    {
                        la2 = LA(2);
                        if (la2 == 'l')
                        {
                            la3 = LA(3);
                            if (la3 == 'l')
                            {
                                switch (LA(4))
                                {
                                case -1:
                                case '\t':
                                case '\n':
                                case '\r':
                                case ' ':
                                case ',':
                                case '/':
                                case ']':
                                case '}':
                                {
                                    Skip();
                                    Skip();
                                    Skip();
                                    Skip();
                                    // line 88
                                    return(null);
                                }

                                default:
                                    goto match4;
                                }
                            }
                            else
                            {
                                goto match4;
                            }
                        }
                        else
                        {
                            goto match4;
                        }
                    }
                    else
                    {
                        goto match4;
                    }
                }
                else
                {
                    goto match4;
                }
                break;
match4:
                {
                    MatchRange('A', 'Z', 'a', 'z');
                    // Line 89: ([A-Za-z])*
                    for (;;)
                    {
                        la0 = LA0;
                        if (la0 >= 'A' && la0 <= 'Z' || la0 >= 'a' && la0 <= 'z')
                        {
                            Skip();
                        }
                        else
                        {
                            break;
                        }
                    }
                    // line 90
                    Error(0, "JSON does not support identifiers");
                    return(CharSource.Slice(start, InputPosition - start).ToString());
                }
            } while (false);
            return(result);
        }
コード例 #24
0
 UString Text() => CharSource.Slice(_startPosition, InputPosition - _startPosition);
コード例 #25
0
 // Gets the text of the current token that has been parsed so far
 protected UString Text()
 {
     return(CharSource.Slice(_startPosition, InputPosition - _startPosition));
 }
コード例 #26
0
ファイル: Les3.cs プロジェクト: dadhi/ecsharp
 protected UString Text(int startPosition)
 {
     return(CharSource.Slice(startPosition, InputPosition - startPosition));
 }
コード例 #27
0
        void Num()
        {
            int la0, la1;

                        #line 121 "MyGrammars.ecs"
            bool dot = false;
                        #line default
            // Line 122: ([.])?
            la0 = LA0;
            if (la0 == '.')
            {
                Skip();
                                #line 122 "MyGrammars.ecs"
                dot = true;
                                #line default
            }
            MatchRange('0', '9');
            // Line 123: ([0-9])*
            for (;;)
            {
                la0 = LA0;
                if (la0 >= '0' && la0 <= '9')
                {
                    Skip();
                }
                else
                {
                    break;
                }
            }
            // Line 124: (&!{dot} [.] [0-9] ([0-9])*)?
            la0 = LA0;
            if (la0 == '.')
            {
                if (!dot)
                {
                    la1 = LA(1);
                    if (la1 >= '0' && la1 <= '9')
                    {
                        Skip();
                        Skip();
                        // Line 124: ([0-9])*
                        for (;;)
                        {
                            la0 = LA0;
                            if (la0 >= '0' && la0 <= '9')
                            {
                                Skip();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
                        #line 125 "MyGrammars.ecs"
            _value = double.Parse(CharSource.Slice(_startIndex, InputPosition - _startIndex).ToString());
                        #line default
        }
コード例 #28
0
 // Gets the text of the current token that has been parsed so far
 private UString Text()
 {
     return(CharSource.Slice(_startIndex, InputPosition - _startIndex));
 }
コード例 #29
0
        double Number()
        {
            int    la0;
            double result = default(double);
            // line 47
            int start = InputPosition;

            // Line 48: ([\-])?
            la0 = LA0;
            if (la0 == '-')
            {
                Skip();
            }
            // Line 49: ([0] | [1-9] ([0-9])*)
            la0 = LA0;
            if (la0 == '0')
            {
                Skip();
            }
            else
            {
                MatchRange('1', '9');
                // Line 49: ([0-9])*
                for (;;)
                {
                    la0 = LA0;
                    if (la0 >= '0' && la0 <= '9')
                    {
                        Skip();
                    }
                    else
                    {
                        break;
                    }
                }
            }
            // Line 50: ([.] ([0-9])*)?
            la0 = LA0;
            if (la0 == '.')
            {
                Skip();
                // Line 50: ([0-9])*
                for (;;)
                {
                    la0 = LA0;
                    if (la0 >= '0' && la0 <= '9')
                    {
                        Skip();
                    }
                    else
                    {
                        break;
                    }
                }
            }
            // Line 51: ([Ee] ([+\-])? [0-9] ([0-9])*)?
            la0 = LA0;
            if (la0 == 'E' || la0 == 'e')
            {
                Skip();
                // Line 51: ([+\-])?
                la0 = LA0;
                if (la0 == '+' || la0 == '-')
                {
                    Skip();
                }
                MatchRange('0', '9');
                // Line 51: ([0-9])*
                for (;;)
                {
                    la0 = LA0;
                    if (la0 >= '0' && la0 <= '9')
                    {
                        Skip();
                    }
                    else
                    {
                        break;
                    }
                }
            }
            // line 53
            UString str = CharSource.Slice(start, InputPosition - start);

            result = ParseHelpers.TryParseDouble(ref str, 10);
            return(result);
        }