< Summary

Class:NanoCLang.NanoCParserExtensions
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\NanoCParserExtensions.cs
Covered lines:12
Uncovered lines:5
Coverable lines:17
Total lines:108
Line coverage:70.5% (12 of 17)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_ParseException()100%10%
ParseEntity(...)50%4100%
ParseProgram(...)100%1100%
ParsePureExpression(...)100%1100%
ParseExpression(...)100%1100%
ParseLocation(...)100%10%
ParseIndex(...)100%10%
ParseBasicType(...)100%1100%
ParseRefinedType(...)100%1100%
ParseHeap(...)100%1100%
ParseHeapElements(...)100%1100%
ParseBlock(...)100%10%
ParseFunctionDefinition(...)100%10%
ParseFunctionSchema(...)100%1100%

File(s)

C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\NanoCParserExtensions.cs

#LineLine coverage
 1using NanoCLang.Entities;
 2using NanoCLang.Environemnts;
 3using System;
 4
 5namespace NanoCLang {
 6    /// <summary>
 7    /// Provides an extension class for the NanoC parser that extends it by shortcuts for <see cref="Base"/> entity pars
 8    /// </summary>
 9    public static class NanoCParserExtensions {
 010        internal static Exception ParseException => new FormatException("No entity was parsed!");
 11        /// <summary>
 12        /// Use the parser to parse an entity and check if the entity was parsed successfully without syntax errors.
 13        /// </summary>
 14        /// <typeparam name="T">Type of entity to parse.</typeparam>
 15        /// <param name="parser">Parser that executes the parsing.</param>
 16        /// <param name="parse">Function that invokes the parser and returns the entity.</param>
 17        /// <returns>Parsed entity.</returns>
 18        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 12619        public static T ParseEntity<T>(this NanoCParser parser, Func<NanoCParser, T?> parse) where T : class {
 12620            var entity = parse(parser);
 12621            return entity is null || parser.NumberOfSyntaxErrors > 0 ? throw ParseException : entity;
 12622        }
 23        /// <summary>
 24        /// Parses a compilation unit including a single program before the end of input.
 25        /// </summary>
 26        /// <param name="parser">Parser that is used to parse the input.</param>
 27        /// <returns>Parsed compilation unit</returns>
 28        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 3829        public static Program ParseProgram(this NanoCParser parser) => parser.ParseEntity(parser => parser.singleProgram
 30        /// <summary>
 31        /// Parses a single pure expression before the end of input.
 32        /// </summary>
 33        /// <param name="parser">Parser that is used to parse the input.</param>
 34        /// <returns>Parsed pure expression.</returns>
 35        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 5036        public static PureExpression ParsePureExpression(this NanoCParser parser) => parser.ParseEntity(parser => parser
 37        /// <summary>
 38        /// Parses a single expression before the end of input.
 39        /// </summary>
 40        /// <param name="parser">Parser that is used to parse the input.</param>
 41        /// <returns>Parsed expression.</returns>
 42        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 9843        public static Expression ParseExpression(this NanoCParser parser) => parser.ParseEntity(parser => parser.singleE
 44        /// <summary>
 45        /// Parses a single location before the end of input.
 46        /// </summary>
 47        /// <param name="parser">Parser that is used to parse the input.</param>
 48        /// <returns>Parsed location.</returns>
 49        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 050        public static Location ParseLocation(this NanoCParser parser) => parser.ParseEntity(parser => parser.singleLocat
 51        /// <summary>
 52        /// Parses a single index before the end of input.
 53        /// </summary>
 54        /// <param name="parser">Parser that is used to parse the input.</param>
 55        /// <returns>Parsed index.</returns>
 56        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 057        public static Entities.Index ParseIndex(this NanoCParser parser) => parser.ParseEntity(parser => parser.singleIn
 58        /// <summary>
 59        /// Parses a single basic type before the end of input.
 60        /// </summary>
 61        /// <param name="parser">Parser that is used to parse the input.</param>
 62        /// <returns>Parsed basic type.</returns>
 63        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 1064        public static BasicType ParseBasicType(this NanoCParser parser) => parser.ParseEntity(parser => parser.singleBas
 65        /// <summary>
 66        /// Parses a single refined type before the end of input.
 67        /// </summary>
 68        /// <param name="parser">Parser that is used to parse the input.</param>
 69        /// <returns>Parsed refined type.</returns>
 70        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 3871        public static RefinedType ParseRefinedType(this NanoCParser parser) => parser.ParseEntity(parser => parser.singl
 72        /// <summary>
 73        /// Parses a single heap before the end of input.
 74        /// </summary>
 75        /// <param name="parser">Parser that is used to parse the input.</param>
 76        /// <returns>Parsed heap.</returns>
 77        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 678        public static Heap ParseHeap(this NanoCParser parser) => parser.ParseEntity(parser => parser.ParseHeapElements()
 79        /// <summary>
 80        /// Parses a single list of heap elements before the end of input.
 81        /// </summary>
 82        /// <param name="parser">Parser that is used to parse the input.</param>
 83        /// <returns>Parsed heap elements.</returns>
 84        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 685        public static IHeapElement[] ParseHeapElements(this NanoCParser parser) => parser.ParseEntity(parser => parser.s
 86        /// <summary>
 87        /// Parses a single block before the end of input.
 88        /// </summary>
 89        /// <param name="parser">Parser that is used to parse the input.</param>
 90        /// <returns>Parsed block.</returns>
 91        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 092        public static BlockType[] ParseBlock(this NanoCParser parser) => parser.ParseEntity(parser => parser.singleBlock
 93        /// <summary>
 94        /// Parses a single function definition before the end of input.
 95        /// </summary>
 96        /// <param name="parser">Parser that is used to parse the input.</param>
 97        /// <returns>Parsed function definition.</returns>
 98        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 099        public static FunctionDefinition ParseFunctionDefinition(this NanoCParser parser) => parser.ParseEntity(parser =
 100        /// <summary>
 101        /// Parses a single function schema before the end of input.
 102        /// </summary>
 103        /// <param name="parser">Parser that is used to parse the input.</param>
 104        /// <returns>Parsed function schema.</returns>
 105        /// <exception cref="FormatException">No entity was parsed successfully.</exception>
 6106        public static RawFunctionSchema ParseFunctionSchema(this NanoCParser parser) => parser.ParseEntity(parser => par
 107    }
 108}