internal void ParseGlobals(Lines lines) { if (lines.FirstLineTryMatch(Patterns.BlankLine)) { return; } lines.FirstLineMustMatch(Patterns.Variables); while (true) { if (lines.FirstLineTryMatch(Patterns.ProcedureSignature, false)) { break; } if (!lines.FirstLineTryMatch(Patterns.BlankLine)) { if (!ParseVariable(lines)) { if (!ParseMultiLineTextConstant(lines)) { break; } } } } }
internal bool ParseMultiLineTextConstant(Lines lines) { Match match = null; if (!lines.FirstLineTryMatch(Patterns.MultiLineTextConst, out match)) { return(false); } var variableName = match.Groups[1].Value; var variableID = match.Groups[2].Value.ToInteger(); var stringBuilder = new StringBuilder(); while (lines.FirstLineTryMatch(Patterns.MultiLineTextConstValue, out match)) { var languageCode = match.Groups[1].Value; var languageValue = match.Groups[2].Value; var separator = match.Groups[3].Value; if (String.IsNullOrEmpty(separator)) //TextConst value is multiline { while (!lines.FirstLineTryMatch(Patterns.EndMultiLineTextConstValue, true)) { var valuePart = lines.First(); lines.Consume(0, 0, valuePart.Length); languageValue += valuePart + "\n"; } } stringBuilder.AppendFormat("{0}={1};", languageCode, languageValue); } Listener.OnVariable(variableID, variableName, VariableType.TextConst, "", null, null, stringBuilder.ToString(), false, null, false, false, null, false, false); return(true); }
internal bool ParseMultiLineTextConstant(Lines lines) { Match match = null; if (!lines.FirstLineTryMatch(Patterns.MultiLineTextConst, out match)) { return(false); } var variableName = match.Groups[1].Value; var variableID = match.Groups[2].Value.ToInteger(); var stringBuilder = new StringBuilder(); while (lines.FirstLineTryMatch(Patterns.MultiLineTextConstValue, out match)) { var languageCode = match.Groups[1].Value; var languageValue = match.Groups[2].Value; stringBuilder.AppendFormat("{0}={1};", languageCode, languageValue); } Listener.OnVariable(variableID, variableName, VariableType.TextConst, "", null, null, stringBuilder.ToString(), false, null, false, false, null, false); return(true); }
internal bool ParseTrigger(Lines lines) { Match match; if (!lines.FirstLineTryMatch(Patterns.TriggerSignature, out match)) { return(false); } lines.LastLineTryMatch(Patterns.BlankLine); var triggerName = match.Groups [1].Value; var firstStatement = match.Groups [3].Value; Listener.OnBeginTrigger(triggerName); lines.Unindent(triggerName.Length + 1); if (firstStatement == "VAR") { ParseLocals(lines); } ParseCodeLines(lines); Listener.OnEndTrigger(); return(true); }
internal void ParseLocals(Lines lines) { // Note: assumes the "VAR" keyword has already been consumed while (!lines.FirstLineTryMatch(Patterns.BeginCodeBlock)) { ParseVariable(lines); } }
internal void ParseFormMenuItem(Lines lines) { var match = lines.FirstLineMustMatch(Patterns.BeginMenuItem); Listener.OnBeginFormMenuItem(); lines.Unindent(2); lines.FirstLineTryMatch(Patterns.BlankLine); FormMenuItemProperties(lines); Listener.OnEndFormMenuItem(); }
internal void ParseCodeLines(Lines lines) { lines.LastLineTryMatch(Patterns.BlankLine); lines.FirstLineTryMatch(Patterns.BeginCodeBlock); lines.LastLineMustMatch(Patterns.EndCodeBlock); lines.Unindent(2); foreach (var line in lines) { Listener.OnCodeLine(line); } }
internal bool ParseEvent(Lines lines) { Match match; if (!lines.FirstLineTryMatch(Patterns.EventSignature, out match)) { return(false); } var variableName = match.Groups[1].Value; var variableID = match.Groups[2].Value.ToInteger(); var eventName = match.Groups[3].Value; var eventID = match.Groups[4].Value.ToInteger(); Listener.OnBeginEvent(variableID, variableName, eventID, eventName); ParseParameters(lines); lines.FirstLineMustMatch(Patterns.ProcedureNoReturnValue); if (lines.FirstLineTryMatch(Patterns.Variables)) { ParseLocals(lines); } else { lines.FirstLineMustMatch(Patterns.BeginCodeBlock); } while (!lines.FirstLineTryMatch(Patterns.EndCodeBlock)) { Listener.OnCodeLine(lines.FirstLineMustMatch(Patterns.Any).Value.UnIndent(2)); } Listener.OnEndEvent(); lines.FirstLineTryMatch(Patterns.BlankLine); return(true); }
internal void ParseReturnValue(Lines lines) { if (lines.FirstLineTryMatch(Patterns.ProcedureNoReturnValue)) { return; } var match = lines.FirstLineMustMatch(Patterns.ProcedureReturnValue); var returnValueName = match.Groups[1].Value.Trim(); var returnValueType = match.Groups[2].Value; var returnValueLength = ParseVariableLength(ref returnValueType); var returnValueDimensions = ParseDimensions(ref returnValueType); Listener.OnReturnValue(returnValueName, returnValueType.ToEnum <FunctionReturnValueType>(), returnValueLength, returnValueDimensions); }
internal void ParseDocumentation(Lines lines) { lines.FirstLineMustMatch(Patterns.BeginDocumentation); lines.LastLineMustMatch(Patterns.EndDocumentation); if (lines.FirstLineTryMatch(Patterns.BeginSection)) { lines.LastLineMustMatch(Patterns.EndSection); } lines.Unindent(2); while (lines.Any()) { Listener.OnCodeLine(lines.FirstLineMustMatch(Patterns.Any).Value); } }
internal bool ParseVariable(Lines lines) { Match match = null; if (!lines.FirstLineTryMatch(Patterns.Variable, out match)) { return(false); } var variableName = match.Groups[1].Value; var variableID = match.Groups[2].Value.ToInteger(); var variableType = match.Groups[3].Value; var variableRunOnClient = ParseRunOnClient(ref variableType); var variableWithEvents = ParseWithEvents(ref variableType); var variableSecurityFiltering = ParseSecurityFiltering(ref variableType); var variableInDataSet = ParseInDataSet(ref variableType); var variableDimensions = ParseDimensions(ref variableType); var variableTemporary = ParseTemporary(ref variableType); var variableConstValue = ParseTextConstant(ref variableType); //.ToConstValue(); var variableSubType = ParseVariableSubType(ref variableType); var variableLength = ParseVariableLength(ref variableType); var variableOptionString = ParseOptionString(ref variableType); Listener.OnVariable( variableID, variableName, variableType.ToEnum <VariableType>(), variableSubType, variableLength, variableOptionString, variableConstValue, variableTemporary, variableDimensions, variableRunOnClient, variableWithEvents, variableSecurityFiltering, variableInDataSet); return(true); }
internal bool ParseProcedure(Lines lines) { #if NAV2016 lines.FirstLineTryMatch(Patterns.EventSubscriberAttribute, out Match eventSubscriberMatch); lines.FirstLineTryMatch(Patterns.TryFunctionAttribute, out Match tryFunctionMatch); #endif #if NAV2018 lines.FirstLineTryMatch(Patterns.ServiceEnabledAttribute, out Match serviceEnabledMatch); #endif #if NAV2016 lines.FirstLineTryMatch(Patterns.BusinessEventPublisherAttribute, out Match businessEventPublisherMatch); lines.FirstLineTryMatch(Patterns.IntegrationEventPublisherAttribute, out Match integrationEventPublisherMatch); #endif lines.FirstLineTryMatch(Patterns.FunctionTypeAttribute, out Match functionTypeMatch); lines.FirstLineTryMatch(Patterns.HandlerFunctionsAttribute, out Match handlerFunctionsMatch); lines.FirstLineTryMatch(Patterns.TransactionModelAttribute, out Match transactionModelMatch); #if NAV2017 lines.FirstLineTryMatch(Patterns.TestPermissionsAttribute, out Match testPermissionsMatch); #endif #if NAV2018 lines.FirstLineTryMatch(Patterns.FunctionVisibilityAttribute, out Match functionVisibilityMatch); #endif #if NAVBC2 lines.FirstLineTryMatch(Patterns.LineStartAttribute, out Match lineStartMatch); #endif if (!lines.FirstLineTryMatch(Patterns.ProcedureSignature, out Match procedureSignatureMatch)) { return(false); } var procedureLocal = procedureSignatureMatch.Groups[1].Value == "LOCAL "; var procedureName = procedureSignatureMatch.Groups[2].Value; var procedureID = procedureSignatureMatch.Groups[3].Value.ToInteger(); Listener.OnBeginFunction(procedureID, procedureName, procedureLocal); #if NAV2016 if (businessEventPublisherMatch.Success) { Listener.OnFunctionAttribute("Business", businessEventPublisherMatch.Groups[2].Value); } else if (integrationEventPublisherMatch.Success) { Listener.OnFunctionAttribute("Integration", integrationEventPublisherMatch.Groups[2].Value, integrationEventPublisherMatch.Groups[4].Value); } else if (eventSubscriberMatch.Success) { Listener.OnFunctionAttribute( "EventSubscriber", eventSubscriberMatch.Groups["ObjectType"].Value, eventSubscriberMatch.Groups["ObjectID"].Value, eventSubscriberMatch.Groups["Function"].Value, eventSubscriberMatch.Groups["Element"].Value, eventSubscriberMatch.Groups["OnMissingLicense"].Value, eventSubscriberMatch.Groups["OnMissingPermission"].Value); } //else #endif if (functionTypeMatch.Success) { Listener.OnFunctionAttribute(functionTypeMatch.Groups[1].Value); } #if NAV2016 if (tryFunctionMatch.Success) { Listener.OnFunctionAttribute("TryFunction"); } #endif if (handlerFunctionsMatch.Success) { Listener.OnFunctionAttribute("HandlerFunctions", handlerFunctionsMatch.Groups[1].Value); } if (transactionModelMatch.Success) { Listener.OnFunctionAttribute("TransactionModel", transactionModelMatch.Groups[1].Value); } #if NAV2017 if (testPermissionsMatch.Success) { Listener.OnFunctionAttribute("TestPermissions", testPermissionsMatch.Groups[1].Value); } #endif #if NAV2018 if (functionVisibilityMatch.Success) { Listener.OnFunctionAttribute("FunctionVisibility", functionVisibilityMatch.Groups[1].Value); } if (serviceEnabledMatch.Success) { Listener.OnFunctionAttribute("ServiceEnabled"); } #endif #if NAVBC if (lineStartMatch.Success) { Listener.OnFunctionAttribute("LineStart", lineStartMatch.Groups[1].Value); } #endif ParseParameters(lines); ParseReturnValue(lines); if (lines.FirstLineTryMatch(Patterns.Variables)) { ParseLocals(lines); } else { lines.FirstLineMustMatch(Patterns.BeginCodeBlock); } while (!lines.FirstLineTryMatch(Patterns.EndCodeBlock)) { Listener.OnCodeLine(lines.FirstLineMustMatch(Patterns.Any).Value.UnIndent(2)); } Listener.OnEndFunction(); lines.FirstLineTryMatch(Patterns.BlankLine); return(true); }
internal bool ParseVariable(Lines lines) { var variablePattern = CodeStyle.NoVariableIds ? Patterns.VariableNoId : Patterns.Variable; Match match = null; lines.FirstLineTryMatch(Patterns.BlankLine); if (!lines.FirstLineTryMatch(Patterns.MultiLineTextConst, out match)) { if (!lines.FirstLineTryMatch(variablePattern, out match)) { return(false); } } var variableName = match.Groups[1].Value.TrimEnd(); var variableID = match.Groups[2].Value.ToInteger(); var variableType = match.Groups[3].Value; if (String.IsNullOrEmpty(variableType)) { variableType = "TextConst"; } var variableSuppressDispose = ParseSuppressDispose(ref variableType); var variableRunOnClient = ParseRunOnClient(ref variableType); var variableWithEvents = ParseWithEvents(ref variableType); var variableSecurityFiltering = ParseSecurityFiltering(ref variableType); var variableInDataSet = ParseInDataSet(ref variableType); var variableDimensions = ParseDimensions(ref variableType); var variableTemporary = ParseTemporary(ref variableType); var variableConstValue = ParseTextConstant(ref variableType); //.ToConstValue(); var variableSubType = ParseVariableSubType(ref variableType); var variableLength = ParseVariableLength(ref variableType); var variableOptionString = ParseOptionString(ref variableType); if (variableType == "TextConst") { var stringBuilder = new StringBuilder(); while (lines.FirstLineTryMatch(Patterns.MultiLineTextConstValue, out match)) { var languageCode = match.Groups[1].Value; var languageValue = match.Groups[2].Value; var separator = match.Groups[3].Value; if (String.IsNullOrEmpty(separator)) //TextConst value is multiline { while (!lines.FirstLineTryMatch(Patterns.EndMultiLineTextConstValue, true)) { var valuePart = lines.First(); lines.Consume(0, 0, valuePart.Length); languageValue += valuePart + "\n"; } } stringBuilder.AppendFormat("{0}={1};", languageCode, languageValue); } variableConstValue = stringBuilder.ToString(); if (String.IsNullOrEmpty(variableConstValue)) { lines.FirstLineTryMatch(Patterns.EndOfCodeLine, true); } } Listener.OnVariable( variableID, variableName, variableType.ToEnum <VariableType>(), variableSubType, variableLength, variableOptionString, variableConstValue, variableTemporary, variableDimensions, variableRunOnClient, variableWithEvents, variableSecurityFiltering, variableInDataSet, variableSuppressDispose); return(true); }