// Extract content from the document at the current position, converting it to // the appropriate content type if requested. void ProcessByByteFormat( ByteFormatContext byteFormat, int bytes, string byteLabel, string regionName, string ruleLabel, string describedBy, string ruleComment) { this.parseActions[regionName].Add( new ParseAction((content, startingContentPosition, contentPosition) => { if (!String.IsNullOrEmpty(byteLabel)) { bytes = GetByteCountFromLabel(byteLabel); } string parser = byteFormat.GetText(); object element = null; // If this is a native expression, process it that way if (parser[0] == '{') { element = EvaluateNativeExpression <Object>(parser, results.Peek(), content, contentPosition, bytes); } else { ValidateRuleByteSize(ruleLabel, bytes, ByteParsers[byteFormat.GetText()].Item1); element = ByteParsers[parser].Item2(content, (int)contentPosition, (int)bytes); } ParseElement(ruleLabel, element, describedBy, ruleComment); return((int)bytes); } )); }
// Extract content from the document at the current position, converting it to // the appropriate content type if requested. void ProcessByByteFormat( ByteFormatContext byteFormat, int bytes, string byteLabel, string regionName, string ruleLabel, string describedBy, string ruleComment) { this.parseActions[regionName].Add( new ParseAction((content, contentPosition) => { if (!String.IsNullOrEmpty(byteLabel)) { bytes = GetByteCountFromLabel(byteLabel); } ValidateRuleByteSize(ruleLabel, bytes, ByteParsers[byteFormat.GetText()].Item1); object element = ByteParsers[byteFormat.GetText()].Item2(content, (int)contentPosition, (int)bytes); ParseElement(ruleLabel, element, describedBy, ruleComment); return((int)bytes); } )); }
private void ProcessByteExtraction(string regionName, string ruleLabel, string ruleComment, ByteOptionContext byteOptions, int bytes, string byteLabel) { // See if it has a "described by" annotation, which we'll use // as a lookup table to augment the comment. string describedBy = null; if (byteOptions.label() != null) { describedBy = byteOptions.label().GetText(); } // Process the bytes based on the byte format (i.e.: "as ASCII") ByteFormatContext byteFormat = byteOptions.byteFormat(); if (byteFormat != null) { ProcessByByteFormat(byteFormat, (int)bytes, byteLabel, regionName, ruleLabel, describedBy, ruleComment); } else { // This has no byte format. It is just bytes. this.parseActions[regionName].Add( new ParseAction((content, contentPosition) => { if (!String.IsNullOrEmpty(byteLabel)) { bytes = GetByteCountFromLabel(byteLabel); } byte[] element = new byte[bytes]; Array.Copy(content, (int)contentPosition, element, 0, bytes); ParseElement(ruleLabel, element, describedBy, ruleComment); return((int)bytes); } )); } }
public ByteFormatContext byteFormat() { ByteFormatContext _localctx = new ByteFormatContext(Context, State); EnterRule(_localctx, 18, RULE_byteFormat); int _la; try { EnterOuterAlt(_localctx, 1); { State = 103; _la = TokenStream.La(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << ASCII) | (1L << UNICODE) | (1L << UTF8) | (1L << UINT64) | (1L << UINT32) | (1L << UINT16) | (1L << INT64) | (1L << INT32) | (1L << INT16) | (1L << SINGLE) | (1L << FLOAT) | (1L << DOUBLE))) != 0)) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }