本文整理汇总了C#中ParserOptions类的典型用法代码示例。如果您正苦于以下问题:C# ParserOptions类的具体用法?C# ParserOptions怎么用?C# ParserOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParserOptions类属于命名空间,在下文中一共展示了ParserOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecodePhrase
/// <summary>
/// Decodes the specified number of bytes of the phrase starting
/// at the specified starting index.
/// </summary>
/// <returns>The decoded phrase.</returns>
/// <param name="options">The parser options to use.</param>
/// <param name="phrase">The phrase to decode.</param>
/// <param name="startIndex">The starting index.</param>
/// <param name="count">The number of bytes to decode.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="phrase"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> and <paramref name="count"/> do not specify
/// a valid range in the byte array.
/// </exception>
public static string DecodePhrase(ParserOptions options, byte[] phrase, int startIndex, int count)
{
if (options == null)
throw new ArgumentNullException ("options");
if (phrase == null)
throw new ArgumentNullException ("phrase");
if (startIndex < 0 || startIndex > phrase.Length)
throw new ArgumentOutOfRangeException ("startIndex");
if (count < 0 || startIndex + count > phrase.Length)
throw new ArgumentOutOfRangeException ("count");
if (count == 0)
return string.Empty;
unsafe {
fixed (byte* inbuf = phrase) {
var tokens = TokenizePhrase (options, inbuf, startIndex, count);
return DecodeTokens (options, tokens, phrase, inbuf, count);
}
}
}
示例2: GenerateCodeBlockFromFile
private static string GenerateCodeBlockFromFile(string languageAsString, string value, string documentationVersion, ParserOptions options)
{
var language = (Language)Enum.Parse(typeof(Language), languageAsString, true);
var samplesDirectory = options.GetPathToCodeDirectory(language, documentationVersion);
var values = value.Split('@');
var section = values[0];
var file = values[1];
string content;
var builder = new StringBuilder();
switch (language)
{
case Language.Csharp:
content = ExtractSectionFromCsharpFile(section, Path.Combine(samplesDirectory, file));
break;
case Language.Java:
content = ExtractSectionFromJavaFile(section, Path.Combine(samplesDirectory, file));
break;
default:
throw new NotSupportedException(language.ToString());
}
builder.AppendLine(string.Format("<pre class='line-numbers'><code class='{0}'>{1}</code></pre>", ConvertLanguageToCssClass(language), content));
return builder.ToString();
}
示例3: Parse
public dynamic Parse(string code, ParserOptions options)
{
dynamic program = null;
_lineNumber = (code.Length > 0) ? 1 : 0;
_lineStart = 0;
_length = code.Length;
_buffer = null;
_state = new State
{
AllowIn = true,
LabelSet = new Dictionary<string, object>(),
LastParenthesized = null,
InFunctionBody = false,
InIteration = false,
InSwitch = false
};
if (_length > 0)
{
_source = StringToArray(code).ToList();
}
return ParseProgram();
}
示例4: ValidateArguments
public static void ValidateArguments (ParserOptions options, byte[] buffer)
{
if (options == null)
throw new ArgumentNullException ("options");
if (buffer == null)
throw new ArgumentNullException ("buffer");
}
示例5: LoadPublicGoogleDoc
public static JObject LoadPublicGoogleDoc(string docIdOrUrl, ParserOptions options = ParserOptions.None)
{
const string GDRIVE_DOWNLOAD = @"https://docs.google.com/feeds/download/documents/export/Export?id={0}&exportFormat=txt";
// extract document ID from url
var match = Regex.Match(docIdOrUrl, @"[-\w]{25,}");
var docId = (match.Success) ? match.Value : docIdOrUrl;
return LoadUrl(string.Format(GDRIVE_DOWNLOAD, docId));
}
示例6: GenerateCodeBlocks
public static string GenerateCodeBlocks(string content, string documentationVersion, ParserOptions options)
{
content = CodeTabsFinder.Replace(content, match => GenerateCodeTabsBlock(match.Groups[1].Value.Trim(), documentationVersion, options));
content = CodeWithLanguageFinder.Replace(content, match => GenerateCodeBlockFromFile(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim(), documentationVersion, options));
content = CodeWithoutLanguageFinder.Replace(content, match => GenerateCodeBlockFromFile("csharp", match.Groups[1].Value.Trim(), documentationVersion, options));
content = CodeBlockFinder.Replace(content, match => GenerateCodeBlock(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim()));
return content;
}
示例7: FromArgumentString
public static FlagMatch FromArgumentString(string arg, ParserOptions options)
{
var match = Regex.Match(arg, string.Format("{0}(.+?)({1}(.*))?$",
Util.RegexForAnyLiteral(options.LongFlagHeaders.Union(options.ShortFlagHeaders)),
Util.RegexForAnyLiteral(options.FlagValueSeparators)
));
return match.Success ? new FlagMatch(match, options) : null;
}
示例8: ToParserOptions
public ParserOptions ToParserOptions()
{
var parserOptions = new ParserOptions();
foreach (var variable in Variables)
{
parserOptions.AddVariable(variable);
}
return parserOptions;
}
示例9: TypeParser
internal TypeParser(ParserOptions parserOptions)
: base(parserOptions)
{
_typeRefParser = new TypeRefParser(new StrangerTypeParser(parserOptions), parserOptions);
_typeParameterParser = new TypeParameterParser(_typeRefParser, parserOptions);
_eventParser = new EventParser(_typeRefParser, parserOptions);
_fieldParser = new FieldParser(_typeRefParser, parserOptions);
_methodParser = new MethodParser(_typeParameterParser, _typeRefParser, parserOptions);
_propertyParser = new PropertyParser(_typeRefParser, parserOptions);
}
示例10: FlagMatch
private FlagMatch(Match match, ParserOptions options)
: this(options)
{
Header = match.Groups[1].Value;
FlagName = match.Groups[2].Value;
AssignmentOperator = match.Groups.Count >= 5 ? match.Groups[4].Value : null;
AssignmentValue = match.Groups.Count >= 6 ? match.Groups[5].Value : null;
Type |= options.ShortFlagHeaders.Contains(Header) ? FlagType.Short : 0;
Type |= options.LongFlagHeaders.Contains(Header) ? FlagType.Long : 0;
}
示例11: Scanner
//
// Constructor takes the string to parse and the culture.
//
internal Scanner(string expressionToParse, ParserOptions options)
{
// We currently have no support (and no scenarios) for disallowing property references
// in Conditions.
ErrorUtilities.VerifyThrow(0 != (options & ParserOptions.AllowProperties),
"Properties should always be allowed.");
_expression = expressionToParse;
_parsePoint = 0;
_errorState = false;
_errorPosition = -1; // invalid
_options = options;
}
示例12: ValidateArguments
public static void ValidateArguments (ParserOptions options, byte[] buffer, int startIndex, int length)
{
if (options == null)
throw new ArgumentNullException (nameof (options));
if (buffer == null)
throw new ArgumentNullException (nameof (buffer));
if (startIndex < 0 || startIndex > buffer.Length)
throw new ArgumentOutOfRangeException (nameof (startIndex));
if (length < 0 || length > (buffer.Length - startIndex))
throw new ArgumentOutOfRangeException (nameof (length));
}
示例13: GenerateCodeTabsBlock
private static string GenerateCodeTabsBlock(string content, string documentationVersion, ParserOptions options)
{
var tabs = new List<CodeTab>();
var matches = CodeTabFinder.Matches(content);
foreach (Match match in matches)
{
var languageAndTitle = match.Groups[1].Value.Trim();
var parts = languageAndTitle.Split(':');
var languageAsString = parts[0];
var title = parts.Length > 1 ? parts[1] : null;
var value = match.Groups[2].Value.Trim();
tabs.Add(GenerateCodeTabFromFile(languageAsString, title, value, documentationVersion, options));
}
matches = CodeTabBlockFinder.Matches(content);
foreach (Match match in matches)
tabs.Add(GenerateCodeTab(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim()));
var builder = new StringBuilder();
builder.AppendLine("<div class='code-tabs'>");
builder.AppendLine("<ul class='nav nav-tabs'>");
for (int index = 0; index < tabs.Count; index++)
{
var tab = tabs[index];
builder.AppendLine(string.Format("<li class='code-tab {2}'><a href='#{0}' data-toggle='tab'>{1}</a></li>", tab.Id, tab.Title ?? ConvertLanguageToDisplayName(tab.Language), index == 0 ? "active" : string.Empty));
}
builder.AppendLine("</ul>");
builder.AppendLine("<div class='tab-content'>");
for (int index = 0; index < tabs.Count; index++)
{
var tab = tabs[index];
builder.AppendLine(string.Format("<div class='tab-pane code-tab {1}' id='{0}'>", tab.Id, index == 0 ? "active" : string.Empty));
builder.AppendLine(string.Format("<pre class='line-numbers'><code class='{0}'>{1}</code></pre>", ConvertLanguageToCssClass(tab.Language), tab.Content));
builder.AppendLine("</div>");
}
builder.AppendLine("</div>");
builder.AppendLine("</div>");
return builder.ToString();
}
示例14: TokenizeText
static unsafe IList<Token> TokenizeText (ParserOptions options, byte* inbuf, int startIndex, int length)
{
byte* text, word, inptr = inbuf + startIndex;
byte* inend = inptr + length;
var tokens = new List<Token> ();
bool encoded = false;
Token token = null;
Token lwsp = null;
bool ascii;
int n;
while (inptr < inend) {
text = inptr;
while (inptr < inend && IsLwsp (*inptr))
inptr++;
if (inptr > text)
lwsp = new Token ((int) (text - inbuf), (int) (inptr - text));
else
lwsp = null;
if (inptr < inend) {
word = inptr;
ascii = true;
if (options.Rfc2047ComplianceMode == RfcComplianceMode.Loose) {
// Make an extra effort to detect and separate encoded-word
// tokens that have been merged with other words.
bool is_rfc2047 = false;
if (inptr + 2 < inend && *inptr == '=' && *(inptr + 1) == '?') {
inptr += 2;
// skip past the charset (if one is even declared, sigh)
while (inptr < inend && *inptr != '?') {
ascii = ascii && IsAscii (*inptr);
inptr++;
}
// sanity check encoding type
if (inptr + 3 >= inend || *inptr != '?' || !IsBbQq (*(inptr + 1)) || *(inptr + 2) != '?') {
ascii = true;
goto non_rfc2047;
}
inptr += 3;
// find the end of the rfc2047 encoded word token
while (inptr + 2 < inend && !(*inptr == '?' && *(inptr + 1) == '=')) {
ascii = ascii && IsAscii (*inptr);
inptr++;
}
if (inptr + 2 > inend || *inptr != '?' || *(inptr + 1) != '=') {
// didn't find an end marker...
inptr = word + 2;
ascii = true;
goto non_rfc2047;
}
is_rfc2047 = true;
inptr += 2;
}
non_rfc2047:
if (!is_rfc2047) {
// stop if we encounter a possible rfc2047 encoded
// token even if it's inside another word, sigh.
while (inptr < inend && !IsLwsp (*inptr)) {
if (inptr + 2 < inend && *inptr == '=' && *(inptr + 1) == '?')
break;
ascii = ascii && IsAscii (*inptr);
inptr++;
}
}
} else {
// find the end of a run of text...
while (inptr < inend && !IsLwsp (*inptr)) {
ascii = ascii && IsAscii (*inptr);
inptr++;
}
}
n = (int) (inptr - word);
if (TryGetEncodedWordToken (inbuf, word, n, out token)) {
// rfc2047 states that you must ignore all whitespace between
// encoded-word tokens
if (!encoded && lwsp != null) {
// previous token was not encoded, so preserve whitespace
tokens.Add (lwsp);
}
tokens.Add (token);
encoded = true;
} else {
// append the lwsp and atom tokens
if (lwsp != null)
tokens.Add (lwsp);
//.........这里部分代码省略.........
示例15: ParserOptions
protected ParserOptions(ParserOptions.Internal* native, bool isInternalImpl = false)
{
__Instance = new global::System.IntPtr(native);
}