Exemplo n.º 1
0
        public static TypeNameInfo Parse(string typeName)
        {
            var input = new InputStream(typeName);

            ParseResult result = Sequence(Match_TypeName, EOF)(input);
            if(!result.Matched) return null;

            var typeNameResult = new SequenceResult(result)[0];
            return (TypeNameInfo) typeNameResult.ResultData;
        }
Exemplo n.º 2
0
        // Parsing expressions from our grammar.
        private static ParseResult Match_TypeName(InputStream input)
        {
            var resultData = new TypeNameInfo();

            ParseResult result = Sequence(
                WithAction(Match_UnqualifiedName, r => InitializeTypeNameInfo((ParsedUnqualifiedName)r.ResultData, resultData)),
                ZeroOrOne(Sequence(Match_Comma, WithAction(Match_AssemblyName, r => resultData.AssemblyName = r.MatchedString))))(input);
            
            if (!result.Matched) return result;
            return new ParseResult(result.MatchedString, resultData);
        }
Exemplo n.º 3
0
        /// <summary>
        /// The PEG "dot" operator that matches and consumes one character.
        /// </summary>
        /// <param name="input">Input to the parser.</param>
        /// <returns>The parse result.</returns>
        public static ParseResult Any(InputStream input)
        {
            if (input.AtEnd)
            {
                return matchFailed;
            }

            var result = new ParseResult(input.CurrentChar.ToString());

            input.Consume(1);
            return result;
        }
Exemplo n.º 4
0
 private static ParseResult Match_AssemblyName(InputStream input)
 {
     return ParseBuilder.Sequence(Match_SimpleName, ParseBuilder.ZeroOrMore(ParseBuilder.Sequence(Match_Comma, Match_AssemblyNamePart)))(input);
 }
Exemplo n.º 5
0
 private static ParseResult Match_Space(InputStream input)
 {
     return ParseBuilder.FirstOf(
         ParseBuilder.Match(' '),
         ParseBuilder.Match('\t'),
         Match_Eol)(input);
 }
Exemplo n.º 6
0
 private static ParseResult Match_Equals(InputStream input)
 {
     return ParseBuilder.Sequence(ParseBuilder.Match('='), Match_Spacing)(input);
 }
Exemplo n.º 7
0
 private static ParseResult Match_Plus(InputStream input)
 {
     return ParseBuilder.Match('+')(input);
 }
Exemplo n.º 8
0
 private static ParseResult Match_RightBracket(InputStream input)
 {
     return ParseBuilder.Sequence(ParseBuilder.Match(']'), Match_Spacing)(input);
 }
Exemplo n.º 9
0
 private static ParseResult Match_HexDigit(InputStream input)
 {
     return ParseBuilder.Match(ch => "0123456789ABCDEFabcdef".Contains(ch))(input);
 }
Exemplo n.º 10
0
 private static ParseResult Match_AssemblyNameStart(InputStream input)
 {
     return ParseBuilder.Sequence(ParseBuilder.Not(Match_Dot), Match_AssemblyNameChar)(input);
 }
Exemplo n.º 11
0
        private static ParseResult Match_PublicKeyValue(InputStream input)
        {
            var seq = Enumerable.Repeat<Func<InputStream, ParseResult>>(Match_HexDigit, 16)
                .Concat(new Func<InputStream, ParseResult>[] { Match_Spacing });

            return ParseBuilder.Sequence(seq.ToArray())(input);
        }
Exemplo n.º 12
0
 private static ParseResult Match_PublicKeyToken(InputStream input)
 {
     return ParseBuilder.Sequence(ParseBuilder.Match("PublicKeyToken"), Match_Spacing, Match_Equals, Match_PublicKeyValue)(input);
 }
Exemplo n.º 13
0
 private static ParseResult Match_PublicKey(InputStream input)
 {
     return
         ParseBuilder.Sequence(ParseBuilder.Match("PublicKey"), Match_Spacing, Match_Equals, ParseBuilder.OneOrMore(Match_HexDigit), Match_Spacing)(
             input);
 }
Exemplo n.º 14
0
 private static ParseResult Match_VersionNumber(InputStream input)
 {
     return
         ParseBuilder.Sequence(Match_Int, Match_Dot, Match_Int, Match_Dot, Match_Int, Match_Dot, Match_Int)(input);
 }
Exemplo n.º 15
0
 private static ParseResult Match_Version(InputStream input)
 {
     return ParseBuilder.Sequence(ParseBuilder.Match("Version"), Match_Spacing, Match_Equals, Match_VersionNumber, Match_Spacing)(input);
 }
Exemplo n.º 16
0
 private static ParseResult Match_IdNonAlpha(InputStream input)
 {
     return ParseBuilder.Match(ch => "_$@?".Contains(ch))(input);
 }
Exemplo n.º 17
0
 private static ParseResult Match_Digit(InputStream input)
 {
     return ParseBuilder.Match(ch => char.IsDigit(ch))(input);
 }
Exemplo n.º 18
0
 private static ParseResult Match_AssemblyNameContinuation(InputStream input)
 {
     return Match_AssemblyNameChar(input);
 }
Exemplo n.º 19
0
 private static ParseResult Match_Int(InputStream input)
 {
     return ParseBuilder.WithAction(ParseBuilder.Sequence(Match_Digit, ParseBuilder.ZeroOrMore(Match_Digit)),
         r => new ParseResult(r.MatchedString, int.Parse(r.MatchedString, CultureInfo.InvariantCulture)))(input);
 }
Exemplo n.º 20
0
 private static ParseResult Match_AssemblyNameChar(InputStream input)
 {
     return ParseBuilder.FirstOf(Match_QuotedChar, ParseBuilder.Match(ch => !"^/\\:?\"<>|,[]".Contains(ch)))(input);
 }
Exemplo n.º 21
0
 private static ParseResult Match_Backquote(InputStream input)
 {
     return ParseBuilder.Match('`')(input);
 }
Exemplo n.º 22
0
 private static ParseResult Match_Id(InputStream input)
 {
     return ParseBuilder.Sequence(Match_IdStart, ParseBuilder.ZeroOrMore(Match_IdContinuation))(input);
 }
Exemplo n.º 23
0
 private static ParseResult Match_Backslash(InputStream input)
 {
     return ParseBuilder.Match('\\')(input);
 }
Exemplo n.º 24
0
 private static ParseResult Match_IdStart(InputStream input)
 {
     return ParseBuilder.FirstOf(Match_IdNonAlpha, Match_IdAlpha)(input);
 }
Exemplo n.º 25
0
 private static ParseResult Match_Spacing(InputStream input)
 {
     return ParseBuilder.ZeroOrOne(Match_Space)(input);
 }
Exemplo n.º 26
0
 private static ParseResult Match_IdContinuation(InputStream input)
 {
     return ParseBuilder.FirstOf(Match_IdNonAlpha, Match_IdAlphanumeric)(input);
 }
Exemplo n.º 27
0
 private static ParseResult Match_Eol(InputStream input)
 {
     return ParseBuilder.FirstOf(
         ParseBuilder.Match("\r\n"),
         ParseBuilder.Match('\r'),
         ParseBuilder.Match('\n'))(input);
 }
Exemplo n.º 28
0
 private static ParseResult Match_IdAlphanumeric(InputStream input)
 {
     return ParseBuilder.FirstOf(Match_QuotedChar, ParseBuilder.Match(ch => char.IsLetterOrDigit(ch)))(input);
 }
Exemplo n.º 29
0
        private static ParseResult Match_UnqualifiedName(InputStream input)
        {
            var resultData = new ParsedUnqualifiedName();

            var result =
                Sequence(
                    WithAction(ZeroOrOne(Match_Namespace), r => resultData.Namespace = (string)r.ResultData),
                    WithAction(Match_RootName, r => resultData.Rootname = r.MatchedString),
                    WithAction(ZeroOrOne(Match_GenericParameters), r => resultData.GenericParameters = (GenericParameters)r.ResultData))(
                input);

            if (result.Matched)
            {
                return new ParseResult(result.MatchedString, resultData);
            }
            return result;
        }
Exemplo n.º 30
0
 private static ParseResult Match_QuotedChar(InputStream input)
 {
     return ParseBuilder.WithAction(
         ParseBuilder.Sequence(Match_Backslash, ParseBuilder.Any),
         result =>
         {
             string ch = new SequenceResult(result)[1].MatchedString;
             return new ParseResult(ch);
         })(input);
 }