Exemplo n.º 1
0
        public void ParseAsyncは内部パーサーと同じように失敗します()
        {
            var cursol = new Cursol("public");
            var parser = new CharParser('a');
            var tested = new RecursiveParser <char>(() => parser);

            (tested.Parse(cursol)).IsStructuralEqual(parser.Parse(cursol));
        }
Exemplo n.º 2
0
        public void ParseAsyncは内部パーサーと同じように成功します()
        {
            var cursol = new Cursol("public");
            var parser = new CharParser('p');
            var tested = new DebugParser <char>(parser, () => { });

            (tested.Parse(cursol)).IsStructuralEqual(parser.Parse(cursol));
        }
Exemplo n.º 3
0
    void SetCharData()
    {
        CharParser Char1 = this.GetComponent <CharParser>();

        charData2 = Char1._tempCD2;
        charcount = Char1._charData.Length;
        //Debug.Log(charData2[1, 1]);
        //Debug.Log(charcount);
    }
Exemplo n.º 4
0
        public void ParseAsyncはIgnoreCaseで大文字指定でも小文字を識別します()
        {
            var cursol = new Cursol("public");
            var tested = new CharParser('P', true);

            var(isSuccess, _, _) = tested.Parse(cursol);

            isSuccess.IsTrue();
        }
Exemplo n.º 5
0
        public void ParseAsyncは読み込みに成功した場合にその分進んだカーソルを返します()
        {
            var cursol = new Cursol("public");
            var tested = new CharParser('p');

            var result = tested.Parse(cursol);

            result.cursol.Index.Is(1);
        }
Exemplo n.º 6
0
        public void ParseAsyncはIgnoreCaseでない場合に大文字指定の場合に小文字を区別します()
        {
            var cursol = new Cursol("public");
            var tested = new CharParser('P');

            var(isSuccess, _, _) = tested.Parse(cursol);

            isSuccess.IsFalse();
        }
Exemplo n.º 7
0
        public void ParseAsyncは指定していない文字を読み込みに失敗します()
        {
            var cursol = new Cursol("internal");
            var tested = new CharParser('p');

            var result = tested.Parse(cursol);

            result.isSuccess.IsFalse();
        }
Exemplo n.º 8
0
        public void ParseAsyncは指定した文字を読み込みます()
        {
            var cursol = new Cursol("public");
            var tested = new CharParser('p');

            var result = tested.Parse(cursol);

            result.parsed.Is('p');
        }
Exemplo n.º 9
0
        public void ParseAsyncは指定した文字を読み込みに成功します()
        {
            var cursol = new Cursol("public");
            var tested = new CharParser('p');

            var result = tested.Parse(cursol);

            result.isSuccess.IsTrue();
        }
Exemplo n.º 10
0
        public void ParseAsyncはIgnoreCaseで大文字指定の場合に実際に識別した文字を結果とします()
        {
            var cursol = new Cursol("public");
            var tested = new CharParser('P', true);

            var(_, _, parsed) = tested.Parse(cursol);

            parsed.Is('p');
        }
Exemplo n.º 11
0
        public void FailParse()
        {
            IScanner   scanner = Provider.Scanner;
            CharParser parser  = Prims.CharOf(NonMatchedChar);

            ParserMatch m = parser.Parse(scanner);

            Assert.IsTrue(!m.Success);
            Assert.AreEqual(scanner.Offset, 0);
        }
Exemplo n.º 12
0
        public void ParseAsyncは指定したActionを呼びます()
        {
            bool isActioned = false;
            var  cursol     = new Cursol("public");
            var  parser     = new CharParser('a');
            var  tested     = new DebugParser <char>(parser, () => { isActioned = true; });

            isActioned.IsFalse();
            tested.Parse(cursol);
            isActioned.IsTrue();
        }
Exemplo n.º 13
0
        public void SuccessParse()
        {
            IScanner   scanner = Provider.Scanner;
            CharParser parser  = Prims.CharOf(MatchedChar);

            ParserMatch m = parser.Parse(scanner);

            Assert.IsTrue(m.Success);
            Assert.AreEqual(m.Offset, 0);
            Assert.AreEqual(m.Length, 1);
            Assert.AreEqual(scanner.Offset, 1);
        }
Exemplo n.º 14
0
        public ParserError(ParserMatch noMatch, string errorId, string errorMessage)
        {
            if (errorId == null)
            {
                throw new ArgumentNullException("errorId");
            }

            if (errorMessage == null)
            {
                throw new ArgumentNullException("errorMessage");
            }

            long errorOffset = noMatch.Offset + noMatch.Length;

            IScanner scanner        = noMatch.Scanner;
            long     originalOffset = scanner.Offset;
            long     lastLineOffset = 0;

            scanner.Offset = 0;
            Parser eol    = Prims.Eol;
            Parser notEol = new CharParser(delegate(Char c)
            {
                return(c != '\r' && c != '\n');
            });

            _line = 1; // 1 based not 0 based
            while (!scanner.AtEnd)
            {
                notEol.Parse(scanner);
                if (scanner.AtEnd)
                {
                    break;
                }
                ParserMatch match = eol.Parse(scanner);
                if (scanner.Offset > errorOffset)
                {
                    break;
                }
                if (match.Success)
                {
                    ++_line;
                    lastLineOffset = scanner.Offset;
                }
            }

            _column        = errorOffset - lastLineOffset + 1; // 1 based not 0 based
            scanner.Offset = originalOffset;
            _errorText     = errorMessage;
            _errorId       = errorId;
        }
Exemplo n.º 15
0
    private void ParseChar()
    {
        _charDic = new Dictionary <int, CharParser>();
        TableHandler handler = TableHandler.OpenFromResmap("Char");

        for (int i = 0; i < handler.GetRecordsNum() - 1; i++)
        {
            int        key  = int.Parse(handler.GetValue(i, 0));
            CharParser info = new CharParser()
            {
                sn  = int.Parse(handler.GetValue(i, 0)),
                res = handler.GetValue(i, 1),
            };
        }
    }
Exemplo n.º 16
0
    void SetCharData()
    {
        CharParser Char1 = GameObject.Find("DataObj").GetComponent <CharParser>();

        charData2 = Char1._tempCD2;
        charcount = Char1._charData.Length;

        for (int i = 1; i < charcount; i++)
        {
            charAge[i] = Convert.ToInt32(charData2[i, 4]);
            //Debug.Log(charData2[i, 4]);
        }

        //Debug.Log(charData2[1, 1]);
        //Debug.Log(charcount);
    }
Exemplo n.º 17
0
        public void Setup()
        {
            this._letterOrDigit      = Prims.LetterOrDigit;
            this._letterOrDigit.Act += OnLetterOrDigitParserSuccess;
            this._letter             = Prims.Letter;
            this._letter.Act        += OnLetterParserSuccess;
            this._symbol             = Prims.Symbol;
            this._symbol.Act        += OnSymbolParserSuccess;

            this._LetterOrDigitButNotLetterDifferenceParser      = new DifferenceParser(this._letterOrDigit, this._letter);
            this._LetterOrDigitButNotLetterDifferenceParser.Act += OnDifferenceParserSuccess;

            this._symbolParserSuccess        = false;
            this._letterParserSuccess        = false;
            this._letterOrDigitParserSuccess = false;
            this._differenceParserSuccess    = false;
        }
Exemplo n.º 18
0
		public static CharParser WsChar(CharParser parser)
		{
			return from ws in ZeroOrMany(WhiteSpace)
				   from c in parser
				   select c;
		}
Exemplo n.º 19
0
 public static Either <TLeft, char> ParseToChar <TLeft>(this string source, TLeft left)
 {
     return(CharParser.Parse(source, left));
 }
Exemplo n.º 20
0
 public static Either <TLeft, char> ParseToChar <TLeft>(this Either <TLeft, string> source, TLeft left)
 {
     return(source.FlatMap(x => CharParser.Parse(x, left)));
 }
Exemplo n.º 21
0
 public static CharParser WsChar(CharParser parser)
 {
     return(from ws in ZeroOrMany(WhiteSpace)
            from c in parser
            select c);
 }
Exemplo n.º 22
0
 internal CharOrParser(CharParser left, CharParser right) : base("Or")
 {
     Left  = left ?? throw new ArgumentNullException(nameof(left));
     Right = right ?? throw new ArgumentNullException(nameof(right));
 }
Exemplo n.º 23
0
 public static Maybe <char> ParseToChar(this string source)
 {
     return(CharParser.Parse(source));
 }
 internal CharCaptureParser(CharParser original) : base("Or")
 {
     _original = original;
 }
Exemplo n.º 25
0
        public void AnyCharTest()
        {
            CharParser test = Prims.AnyChar;

            Assert.IsTrue(test.Accepts('a'));
        }
Exemplo n.º 26
0
 public static void Test(CharParser test, Char success, Char failed)
 {
     Assert.IsTrue(test.Accepts(success));
     Assert.IsFalse(test.Accepts(failed));
 }
Exemplo n.º 27
0
            public SimpleCollationRuleParser(bool useDebugger)
            {
                // creating sub parsers
                Parser character  = new CharParser(IsCharacter);
                Parser hexDigit   = Prims.HexDigit;
                Parser newLine    = Prims.Eol;
                Parser whiteSpace = Ops.ZeroOrMore(Prims.WhiteSpace - Prims.Eol);

                Parser unicodeEscapeCharacter = Ops.Sequence('\\',
                                                             Ops.Expect("scr0001",
                                                                        "Invalid unicode character escape sequence: missing 'u' after '\\'",
                                                                        'u'),
                                                             Ops.Expect("scr0002",
                                                                        "Invalid unicode character escape sequence: missing hexadecimal digit after '\\u'",
                                                                        hexDigit),
                                                             Ops.Expect("scr0002",
                                                                        "Invalid unicode character escape sequence: missing hexadecimal digit after '\\u'",
                                                                        hexDigit),
                                                             Ops.Expect("scr0002",
                                                                        "Invalid unicode character escape sequence: missing hexadecimal digit after '\\u'",
                                                                        hexDigit),
                                                             Ops.Expect("scr0002",
                                                                        "Invalid unicode character escape sequence: missing hexadecimal digit after '\\u'",
                                                                        hexDigit));

                // creating rules and assigning names (for debugging)
                _collationElement = new Rule("collationElement");
                _collationGroup   = new Rule("collationGroup");
                _collationLine    = new Rule("collationLine");
                _collationRules   = new Rule("collationRules");

                // assigning parsers to rules
                // collationElement ::= (unicodeEscapeCharacter | character)+
                _collationElement.Parser = Ops.Expect(CollationElementIsUnique, "scr0100", "Duplicate collation element",
                                                      Ops.OneOrMore(unicodeEscapeCharacter | character));

                // collationGroup ::= '(' WS* collationElement WS+ (collationElement WS?)+ ')'
                _collationGroup.Parser = Ops.Sequence('(',
                                                      whiteSpace,
                                                      Ops.Expect("scr0003",
                                                                 "Expected: 2 or more collation elements in collation group (nested collation groups are not allowed)",
                                                                 Ops.Sequence(_collationElement,
                                                                              whiteSpace,
                                                                              _collationElement,
                                                                              whiteSpace)),
                                                      Ops.Expect("scr0004",
                                                                 "Expected: collation element or close group ')'",
                                                                 Ops.ZeroOrMore(
                                                                     Ops.Sequence(_collationElement, whiteSpace))),
                                                      Ops.Expect("scr0005", "Expected: group close ')'", ')'));

                // collationLine ::= (collationElement WS? | collationGroup WS?)+
                _collationLine.Parser = Ops.OneOrMore(Ops.Sequence(_collationGroup | _collationElement,
                                                                   whiteSpace));

                // collationRules ::= WS? collationLine? (NewLine WS? collationLine?)* EOF
                _collationRules.Parser = Ops.Expect("scr0006",
                                                    "Invalid character",
                                                    Ops.Sequence(whiteSpace,
                                                                 Ops.Optional(_collationLine),
                                                                 Ops.ZeroOrMore(Ops.Sequence(newLine,
                                                                                             whiteSpace,
                                                                                             Ops.Optional(_collationLine))),
                                                                 Prims.End));

                character.Act += new ActionHandler(OnCharacter);
                unicodeEscapeCharacter.Act += OnUnicodeEscapeCharacter;
                _collationElement.Act      += new ActionHandler(OnCollationElement);
                _collationGroup.Act        += new ActionHandler(OnCollationGroup);
                _collationGroup.PreParse   += new PreParseEventHandler(OnEnterCollationGroup);
                _collationGroup.PostParse  += new PostParseEventHandler(OnExitCollationGroup);
                _collationLine.Act         += new ActionHandler(OnCollationLine);
                _collationRules.Act        += new ActionHandler(OnCollationRules);
                if (useDebugger)
                {
                    // debuggger
                    debug  = new Debugger(Console.Out);
                    debug += _collationRules;
                    debug += _collationLine;
                    debug += _collationGroup;
                    debug += _collationElement;
                }
            }