示例#1
0
        private static IList <Tuple <string, bool> > Split(string line, int max, int min)
        {
            var lines = new List <Tuple <string, bool> >();
            int nLine = (line.Length / max) + ((line.Length % max) != 0 ? 1 : 0);

            if (nLine == 1)
            {
                lines.Add(new Tuple <string, bool>(line, false));
                return(lines);
            }
            if (line.Length < 1)
            {
                lines.Add(new Tuple <string, bool>(line, false));
            }
            else
            {
                for (int i = 0; i < line.Length; i += (i == 0 ? max : min))
                {
                    lines.Add(new Tuple <string, bool>(line.Substring(i, Math.Min((i == 0 ? max : min), line.Length - i)), true));
                }
            }
            TokensLine tempTokensLine = TokensLine.CreateVirtualLineForInsertedToken(0, line);

            tempTokensLine.InitializeScanState(new MultilineScanState(false, false, false, IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147)));

            Scanner.Scanner scanner          = new Scanner.Scanner(line, 0, line.Length - 1, tempTokensLine, null, false);
            Token           t                = null;
            int             nCurLength       = 0;
            int             nSpan            = max;
            int             index            = 0;
            bool            bNextNoIndicator = false;

            while ((t = scanner.GetNextToken()) != null)
            {
                nCurLength += t.Length;
                if (nCurLength >= nSpan)
                {
                    if (t.TokenFamily == TokenFamily.Whitespace || (nCurLength == nSpan))
                    {
                        bNextNoIndicator = true;
                    }
                    nSpan += min;
                    index++;
                }
                else if (bNextNoIndicator)
                {
                    lines[index]     = new Tuple <string, bool>(lines[index].Item1, false);
                    bNextNoIndicator = false;
                }
            }
            return(lines);
        }
        private ReplaceStatus TryAndReplace(Token nextToken, ReplaceOperation replaceOperation)
        {
            ReplaceStatus status = new ReplaceStatus();
            IList <Token> originalMatchingTokens;

#if EUROINFO_RULES
            if (CompilerOptions.UseEuroInformationLegacyReplacingSyntax)
            {
                // Support for legacy replacing syntax semantics :
                // Insert Suffix before the first '-' in all user defined words found in the COPY text
                // before copying it into the main program
                if (CopyReplacingDirective != null && CopyReplacingDirective.InsertSuffixChar && nextToken.TokenType == TokenType.UserDefinedWord)
                {
                    string originalText = nextToken.Text;
                    if (originalText.Contains(CopyReplacingDirective.PreSuffix))
                    {
                        string     replacedText      = originalText.Replace(CopyReplacingDirective.PreSuffix, CopyReplacingDirective.PreSuffix.Insert(3, CopyReplacingDirective.Suffix));
                        TokensLine virtualTokensLine = TokensLine.CreateVirtualLineForInsertedToken(0, replacedText);
                        Token      replacementToken  = new Token(TokenType.UserDefinedWord, 0, replacedText.Length - 1,
                                                                 virtualTokensLine);

                        status.replacedToken         = new ReplacedToken(replacementToken, nextToken);
                        currentPosition.CurrentToken = status.replacedToken;
                    }
                }
            }
#endif

            if (replaceOperation != null && TryMatchReplaceOperation(nextToken, replaceOperation, out originalMatchingTokens))
            {
                status.replacedToken = CreateReplacedTokens(nextToken, replaceOperation, originalMatchingTokens);
                if (status.replacedToken != null)
                {
                    // REPLACE pattern matched => return the first replaced token
                    currentPosition.CurrentToken = status.replacedToken;
                }
                else
                {
                    // If the replacement token set is empty (REPLACE == ... = BY == ==), get next token and try again
                    status.tryAgain = true;
                }
            }
            return(status);
        }
示例#3
0
        private static Nodes.TypeDefinition CreateCurrency()
        {
            var entry = new DataTypeDescriptionEntry();

            entry.LevelNumber = new GeneratedIntegerValue(1);
            entry.DataName    = new SymbolDefinition(new GeneratedAlphanumericValue("CURRENCY"), SymbolType.DataName);
            entry.Picture     = new GeneratedAlphanumericValue(string.Format("{0}({1})", 'X', 3));
            entry.DataType    = DataType.Currency;
            var tokenLine = TokensLine.CreateVirtualLineForInsertedToken(entry.Line, "01 CURRENCY TYPEDEF STRICT PUBLIC PIC X(03).");

            entry.ConsumedTokens.Add(new Token(TokenType.LevelNumber, 0, 1, tokenLine));
            entry.ConsumedTokens.Add(new Token(TokenType.UserDefinedWord, 3, 10, tokenLine));
            entry.ConsumedTokens.Add(new Token(TokenType.TYPEDEF, 12, 18, tokenLine));
            entry.ConsumedTokens.Add(new Token(TokenType.STRICT, 20, 25, tokenLine));
            entry.ConsumedTokens.Add(new Token(TokenType.PUBLIC, 27, 32, tokenLine));
            entry.ConsumedTokens.Add(new Token(TokenType.PIC, 34, 36, tokenLine));
            entry.ConsumedTokens.Add(new Token(TokenType.PictureCharacterString, 38, 42, tokenLine));
            entry.ConsumedTokens.Add(new Token(TokenType.PeriodSeparator, 43, 43, tokenLine));
            return(new Nodes.TypeDefinition(entry));
        }