node-llama-cpp 3.1.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/ChatWrapper.js +1 -1
- package/dist/ChatWrapper.js.map +1 -1
- package/dist/bindings/AddonTypes.d.ts +10 -3
- package/dist/bindings/Llama.d.ts +31 -1
- package/dist/bindings/Llama.js +95 -10
- package/dist/bindings/Llama.js.map +1 -1
- package/dist/bindings/getLlama.d.ts +26 -2
- package/dist/bindings/getLlama.js +60 -5
- package/dist/bindings/getLlama.js.map +1 -1
- package/dist/bindings/utils/MemoryOrchestrator.d.ts +2 -0
- package/dist/bindings/utils/MemoryOrchestrator.js +3 -2
- package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -1
- package/dist/bindings/utils/clearAllLocalBuilds.js +2 -2
- package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -1
- package/dist/bindings/utils/compileLLamaCpp.d.ts +1 -1
- package/dist/bindings/utils/compileLLamaCpp.js +54 -1
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -1
- package/dist/bindings/utils/getGpuTypesToUseForOption.js +1 -1
- package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -1
- package/dist/bindings/utils/getLinuxDistroInfo.js +1 -1
- package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -1
- package/dist/bindings/utils/testBindingBinary.d.ts +2 -1
- package/dist/bindings/utils/testBindingBinary.js +122 -37
- package/dist/bindings/utils/testBindingBinary.js.map +1 -1
- package/dist/bindings/utils/testCmakeBinary.js +1 -1
- package/dist/bindings/utils/testCmakeBinary.js.map +1 -1
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
- package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -1
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +3 -2
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -1
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.d.ts +35 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js +253 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +13 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +31 -1
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -1
- package/dist/chatWrappers/utils/chunkChatItems.js +1 -1
- package/dist/chatWrappers/utils/chunkChatItems.js.map +1 -1
- package/dist/chatWrappers/utils/getModelLinageNames.d.ts +2 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js +18 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -1
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.d.ts +2 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js +9 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js.map +1 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +4 -2
- package/dist/chatWrappers/utils/resolveChatWrapper.js +10 -32
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -1
- package/dist/cli/commands/ChatCommand.js +2 -3
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/cli/commands/CompleteCommand.js +1 -2
- package/dist/cli/commands/CompleteCommand.js.map +1 -1
- package/dist/cli/commands/InfillCommand.js +1 -2
- package/dist/cli/commands/InfillCommand.js.map +1 -1
- package/dist/cli/commands/InitCommand.d.ts +2 -1
- package/dist/cli/commands/InitCommand.js +32 -13
- package/dist/cli/commands/InitCommand.js.map +1 -1
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +0 -1
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -1
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +47 -11
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -1
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +14 -3
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -1
- package/dist/cli/recommendedModels.js +11 -0
- package/dist/cli/recommendedModels.js.map +1 -1
- package/dist/cli/utils/consolePromptQuestion.js +0 -1
- package/dist/cli/utils/consolePromptQuestion.js.map +1 -1
- package/dist/cli/utils/interactivelyAskForModel.js +3 -1
- package/dist/cli/utils/interactivelyAskForModel.js.map +1 -1
- package/dist/evaluator/LlamaChat/LlamaChat.js +37 -24
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +63 -8
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +8 -1
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +156 -138
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +1 -1
- package/dist/evaluator/LlamaCompletion.js +11 -9
- package/dist/evaluator/LlamaCompletion.js.map +1 -1
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +11 -0
- package/dist/evaluator/LlamaContext/LlamaContext.js +66 -8
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -1
- package/dist/evaluator/LlamaGrammar.js +7 -0
- package/dist/evaluator/LlamaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +3 -2
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +3 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaModel/LlamaModel.js +8 -4
- package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -1
- package/dist/gguf/fileReaders/GgufFileReader.d.ts +1 -1
- package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +1 -1
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +1 -1
- package/dist/gguf/insights/GgufInsights.d.ts +1 -0
- package/dist/gguf/insights/GgufInsights.js +8 -0
- package/dist/gguf/insights/GgufInsights.js.map +1 -1
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +40 -4
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +116 -93
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -1
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.d.ts +5 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js +7 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js.map +1 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +11 -1
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +47 -17
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -1
- package/dist/gguf/insights/utils/scoreLevels.js.map +1 -1
- package/dist/gguf/readGgufFileInfo.js +1 -1
- package/dist/gguf/readGgufFileInfo.js.map +1 -1
- package/dist/gguf/utils/getGgufMetadataKeyValue.d.ts +1 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js +27 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/utils/StopGenerationDetector.js +1 -1
- package/dist/utils/StopGenerationDetector.js.map +1 -1
- package/dist/utils/ThreadsSplitter.js +2 -2
- package/dist/utils/ThreadsSplitter.js.map +1 -1
- package/dist/utils/createModelDownloader.js.map +1 -1
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +2 -1
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +14 -1
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -1
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.d.ts +5 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js +15 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
- package/dist/utils/gbnfJson/GbnfTerminal.d.ts +3 -0
- package/dist/utils/gbnfJson/GbnfTerminal.js +25 -3
- package/dist/utils/gbnfJson/GbnfTerminal.js.map +1 -1
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +1 -1
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js +53 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +11 -2
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +64 -15
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +3 -2
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js +13 -7
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js +28 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js +90 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.d.ts +4 -1
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js +8 -1
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.d.ts +5 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js +24 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js +4 -3
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js +8 -2
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +14 -5
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +67 -9
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfOr.d.ts +2 -1
- package/dist/utils/gbnfJson/terminals/GbnfOr.js +9 -5
- package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +7 -1
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +69 -20
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +8 -1
- package/dist/utils/gbnfJson/terminals/GbnfString.js +31 -21
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.d.ts +2 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js +7 -4
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +2 -1
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +24 -5
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +16 -1
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +47 -1
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -1
- package/dist/utils/gbnfJson/types.d.ts +164 -17
- package/dist/utils/gbnfJson/types.js +6 -0
- package/dist/utils/gbnfJson/types.js.map +1 -1
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +61 -9
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +99 -8
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +125 -16
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/hashString.js +1 -1
- package/dist/utils/hashString.js.map +1 -1
- package/dist/utils/includesText.d.ts +1 -0
- package/dist/utils/includesText.js +12 -0
- package/dist/utils/includesText.js.map +1 -0
- package/dist/utils/spawnCommand.js +1 -1
- package/dist/utils/spawnCommand.js.map +1 -1
- package/dist/utils/transformPromisable.js +1 -2
- package/dist/utils/transformPromisable.js.map +1 -1
- package/dist/utils/truncateTextAndRoundToWords.d.ts +4 -3
- package/dist/utils/truncateTextAndRoundToWords.js +90 -39
- package/dist/utils/truncateTextAndRoundToWords.js.map +1 -1
- package/dist/utils/waitForLockfileRelease.js +0 -1
- package/dist/utils/waitForLockfileRelease.js.map +1 -1
- package/dist/utils/wrapAbortSignal.d.ts +1 -1
- package/dist/utils/wrapAbortSignal.js +9 -4
- package/dist/utils/wrapAbortSignal.js.map +1 -1
- package/llama/CMakeLists.txt +16 -90
- package/llama/addon/AddonContext.cpp +1 -1
- package/llama/addon/AddonGrammar.cpp +49 -1
- package/llama/addon/AddonGrammar.h +3 -0
- package/llama/addon/AddonModel.cpp +4 -4
- package/llama/addon/AddonSampler.cpp +0 -13
- package/llama/addon/AddonSampler.h +0 -2
- package/llama/addon/addon.cpp +19 -0
- package/llama/addon/globals/getGpuInfo.cpp +61 -53
- package/llama/addon/globals/getSwapInfo.cpp +69 -0
- package/llama/addon/globals/getSwapInfo.h +4 -0
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/gpuInfo/vulkan-gpu-info.cpp +15 -16
- package/llama/gpuInfo/vulkan-gpu-info.h +1 -2
- package/llama/grammars/README.md +1 -1
- package/llama/llama.cpp.info.json +1 -1
- package/package.json +57 -51
- package/templates/README.md +6 -0
- package/templates/packed/electron-typescript-react.json +1 -1
- package/templates/packed/node-typescript.json +1 -1
- package/llama/gpuInfo/cuda-gpu-info.cu +0 -120
- package/llama/gpuInfo/cuda-gpu-info.h +0 -10
- package/llama/gpuInfo/metal-gpu-info.h +0 -8
- package/llama/gpuInfo/metal-gpu-info.mm +0 -30
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
const maxSequentialUnhelpfulIterations = 100;
|
|
2
|
+
export async function findCharacterRemovalCountToFitChatHistoryInContext({ compressChatHistory, chatHistory, tokensCountToFit, tokenizer, chatWrapper, initialCharactersRemovalCount = 0, estimatedCharactersPerToken = 5, maxDecompressionAttempts = 2, failedCompressionErrorMessage = "Failed to compress chat history. Consider increasing the context size." }) {
|
|
2
3
|
let currentEstimatedCharactersPerToken = estimatedCharactersPerToken;
|
|
3
4
|
function getTokensCountForChatHistory(chatHistory) {
|
|
4
5
|
const { contextText } = chatWrapper.generateContextState({ chatHistory });
|
|
@@ -24,6 +25,8 @@ export async function findCharacterRemovalCountToFitChatHistoryInContext({ compr
|
|
|
24
25
|
}
|
|
25
26
|
let latestCompressionAttempt = await getResultForCharacterRemovalCount(initialCharactersRemovalCount);
|
|
26
27
|
const firstCompressionAttempt = latestCompressionAttempt;
|
|
28
|
+
let latestCompressionAttemptTokensCount = latestCompressionAttempt.tokensCount;
|
|
29
|
+
let sameTokensCountRepetitions = 0;
|
|
27
30
|
if (latestCompressionAttempt.tokensCount === tokensCountToFit ||
|
|
28
31
|
(latestCompressionAttempt.tokensCount < tokensCountToFit && latestCompressionAttempt.characterRemovalCount === 0))
|
|
29
32
|
return {
|
|
@@ -63,6 +66,16 @@ export async function findCharacterRemovalCountToFitChatHistoryInContext({ compr
|
|
|
63
66
|
latestCompressionAttempt.tokensCount <= tokensCountToFit &&
|
|
64
67
|
latestCompressionAttempt.characterRemovalCount < bestCompressionAttempt.characterRemovalCount))
|
|
65
68
|
bestCompressionAttempt = latestCompressionAttempt;
|
|
69
|
+
if (latestCompressionAttempt.tokensCount === latestCompressionAttemptTokensCount)
|
|
70
|
+
sameTokensCountRepetitions++;
|
|
71
|
+
else {
|
|
72
|
+
latestCompressionAttemptTokensCount = latestCompressionAttempt.tokensCount;
|
|
73
|
+
sameTokensCountRepetitions = 0;
|
|
74
|
+
}
|
|
75
|
+
if (decompressionAttempts === 0 &&
|
|
76
|
+
compressionAttempts >= maxSequentialUnhelpfulIterations &&
|
|
77
|
+
sameTokensCountRepetitions >= maxSequentialUnhelpfulIterations)
|
|
78
|
+
throw new Error(failedCompressionErrorMessage);
|
|
66
79
|
}
|
|
67
80
|
return {
|
|
68
81
|
removedCharactersCount: bestCompressionAttempt.characterRemovalCount,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findCharacterRemovalCountToFitChatHistoryInContext.js","sourceRoot":"","sources":["../../src/utils/findCharacterRemovalCountToFitChatHistoryInContext.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,kDAAkD,CAAC,EACrE,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,6BAA6B,GAAG,CAAC,EACjC,2BAA2B,GAAG,CAAC,EAC/B,wBAAwB,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"findCharacterRemovalCountToFitChatHistoryInContext.js","sourceRoot":"","sources":["../../src/utils/findCharacterRemovalCountToFitChatHistoryInContext.ts"],"names":[],"mappings":"AAGA,MAAM,gCAAgC,GAAG,GAAG,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,kDAAkD,CAAC,EACrE,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,6BAA6B,GAAG,CAAC,EACjC,2BAA2B,GAAG,CAAC,EAC/B,wBAAwB,GAAG,CAAC,EAC5B,6BAA6B,GAAG,wEAAwE,EAa3G;IAIG,IAAI,kCAAkC,GAAG,2BAA2B,CAAC;IAErE,SAAS,4BAA4B,CAAC,WAAuC;QACzE,MAAM,EAAC,WAAW,EAAC,GAAG,WAAW,CAAC,oBAAoB,CAAC,EAAC,WAAW,EAAC,CAAC,CAAC;QACtE,OAAO,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC,MAAM,CAAC;IACtE,CAAC;IAED,KAAK,UAAU,iCAAiC,CAAC,qBAA6B;QAC1E,IAAI,qBAAqB,KAAK,CAAC;YAC3B,OAAO;gBACH,iBAAiB,EAAE,WAAW;gBAC9B,WAAW,EAAE,4BAA4B,CAAC,WAAW,CAAC;gBACtD,qBAAqB;aACxB,CAAC;QAEN,MAAM,iBAAiB,GAAG,MAAM,mBAAmB,CAAC;YAChD,WAAW;YACX,kBAAkB,EAAE,qBAAqB;YACzC,2BAA2B,EAAE,kCAAkC;SAClE,CAAC,CAAC;QAEH,OAAO;YACH,iBAAiB;YACjB,WAAW,EAAE,4BAA4B,CAAC,iBAAiB,CAAC;YAC5D,qBAAqB;SACxB,CAAC;IACN,CAAC;IA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vD,CAAC;IAED,OAAO;QACH,sBAAsB,EAAE,sBAAsB,CAAC,qBAAqB;QACpE,qBAAqB,EAAE,sBAAsB,CAAC,iBAAiB;KAClE,CAAC;AACN,CAAC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export declare class GbnfGrammarGenerator {
|
|
2
2
|
rules: Map<string, string | null>;
|
|
3
|
+
ruleContentToRuleName: Map<string, string>;
|
|
4
|
+
literalValueRuleNames: Map<string | number, string>;
|
|
3
5
|
private ruleId;
|
|
6
|
+
private valueRuleId;
|
|
4
7
|
generateRuleName(): string;
|
|
8
|
+
generateRuleNameForLiteralValue(value: string | number): string;
|
|
5
9
|
generateGbnfFile(rootGrammar: string): string;
|
|
10
|
+
getProposedLiteralValueRuleNameLength(): number;
|
|
6
11
|
}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
export class GbnfGrammarGenerator {
|
|
2
2
|
rules = new Map();
|
|
3
|
+
ruleContentToRuleName = new Map();
|
|
4
|
+
literalValueRuleNames = new Map();
|
|
3
5
|
ruleId = 0;
|
|
6
|
+
valueRuleId = 0;
|
|
4
7
|
generateRuleName() {
|
|
5
8
|
const ruleId = this.ruleId;
|
|
6
9
|
this.ruleId++;
|
|
7
10
|
return `rule${ruleId}`;
|
|
8
11
|
}
|
|
12
|
+
generateRuleNameForLiteralValue(value) {
|
|
13
|
+
const existingRuleName = this.literalValueRuleNames.get(value);
|
|
14
|
+
if (existingRuleName != null)
|
|
15
|
+
return existingRuleName;
|
|
16
|
+
const ruleName = `val${this.valueRuleId}`;
|
|
17
|
+
this.valueRuleId++;
|
|
18
|
+
this.literalValueRuleNames.set(value, ruleName);
|
|
19
|
+
return ruleName;
|
|
20
|
+
}
|
|
9
21
|
generateGbnfFile(rootGrammar) {
|
|
10
22
|
const rules = [{
|
|
11
23
|
name: "root",
|
|
@@ -23,5 +35,8 @@ export class GbnfGrammarGenerator {
|
|
|
23
35
|
const gbnf = ruleStrings.join("\n");
|
|
24
36
|
return gbnf;
|
|
25
37
|
}
|
|
38
|
+
getProposedLiteralValueRuleNameLength() {
|
|
39
|
+
return `val${this.valueRuleId}`.length;
|
|
40
|
+
}
|
|
26
41
|
}
|
|
27
42
|
//# sourceMappingURL=GbnfGrammarGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfGrammarGenerator.js","sourceRoot":"","sources":["../../../src/utils/gbnfJson/GbnfGrammarGenerator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAoB;IACtB,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"GbnfGrammarGenerator.js","sourceRoot":"","sources":["../../../src/utils/gbnfJson/GbnfGrammarGenerator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAoB;IACtB,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IACzC,qBAAqB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAClD,qBAAqB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC1D,MAAM,GAAW,CAAC,CAAC;IACnB,WAAW,GAAW,CAAC,CAAC;IAEzB,gBAAgB;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,OAAO,OAAO,MAAM,EAAE,CAAC;IAC3B,CAAC;IAEM,+BAA+B,CAAC,KAAsB;QACzD,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/D,IAAI,gBAAgB,IAAI,IAAI;YACxB,OAAO,gBAAgB,CAAC;QAE5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,CAAC,WAAW,EAAE,CAAC;QAEnB,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEhD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAEM,gBAAgB,CAAC,WAAmB;QACvC,MAAM,KAAK,GAAsC,CAAC;gBAC9C,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,WAAW;aACvB,CAAC,CAAC;QAEH,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACrD,IAAI,OAAO,IAAI,IAAI;gBACf,SAAS;YAEb,KAAK,CAAC,IAAI,CAAC;gBACP,IAAI,EAAE,QAAQ;gBACd,OAAO;aACV,CAAC,CAAC;QACP,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5E,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,qCAAqC;QACxC,OAAO,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC;IAC3C,CAAC;CACJ"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { GbnfGrammarGenerator } from "./GbnfGrammarGenerator.js";
|
|
2
2
|
export declare abstract class GbnfTerminal {
|
|
3
3
|
private _ruleName;
|
|
4
|
+
/** To be used only by `getRuleName` */
|
|
5
|
+
protected generateRuleName(grammarGenerator: GbnfGrammarGenerator): string;
|
|
4
6
|
protected getRuleName(grammarGenerator: GbnfGrammarGenerator): string;
|
|
5
7
|
abstract getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
|
|
8
|
+
protected getGrammarFromResolve(grammarGenerator: GbnfGrammarGenerator): string;
|
|
6
9
|
resolve(grammarGenerator: GbnfGrammarGenerator): string;
|
|
7
10
|
}
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
export class GbnfTerminal {
|
|
2
2
|
_ruleName = null;
|
|
3
|
+
/** To be used only by `getRuleName` */
|
|
4
|
+
generateRuleName(grammarGenerator) {
|
|
5
|
+
return grammarGenerator.generateRuleName();
|
|
6
|
+
}
|
|
3
7
|
getRuleName(grammarGenerator) {
|
|
4
8
|
if (this._ruleName != null)
|
|
5
9
|
return this._ruleName;
|
|
6
|
-
const ruleName =
|
|
10
|
+
const ruleName = this.generateRuleName(grammarGenerator);
|
|
7
11
|
this._ruleName = ruleName;
|
|
8
12
|
return ruleName;
|
|
9
13
|
}
|
|
14
|
+
getGrammarFromResolve(grammarGenerator) {
|
|
15
|
+
return this.getGrammar(grammarGenerator);
|
|
16
|
+
}
|
|
10
17
|
resolve(grammarGenerator) {
|
|
18
|
+
if (this._ruleName != null)
|
|
19
|
+
return this._ruleName;
|
|
20
|
+
const grammar = this.getGrammarFromResolve(grammarGenerator);
|
|
21
|
+
const existingRuleName = grammarGenerator.ruleContentToRuleName.get(grammar);
|
|
22
|
+
if (existingRuleName != null) {
|
|
23
|
+
this._ruleName = existingRuleName;
|
|
24
|
+
return existingRuleName;
|
|
25
|
+
}
|
|
11
26
|
const ruleName = this.getRuleName(grammarGenerator);
|
|
12
|
-
if (
|
|
13
|
-
|
|
27
|
+
if (grammar === ruleName) {
|
|
28
|
+
this._ruleName = ruleName;
|
|
29
|
+
return ruleName;
|
|
30
|
+
}
|
|
31
|
+
if (!grammarGenerator.rules.has(ruleName)) {
|
|
32
|
+
grammarGenerator.rules.set(ruleName, grammar);
|
|
33
|
+
grammarGenerator.ruleContentToRuleName.set(grammar, ruleName);
|
|
34
|
+
}
|
|
35
|
+
this._ruleName = ruleName;
|
|
14
36
|
return ruleName;
|
|
15
37
|
}
|
|
16
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfTerminal.js","sourceRoot":"","sources":["../../../src/utils/gbnfJson/GbnfTerminal.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,YAAY;IACtB,SAAS,GAAkB,IAAI,CAAC;
|
|
1
|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KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC9C,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GbnfJsonSchema } from "./types.js";
|
|
2
|
-
export declare function getGbnfGrammarForGbnfJsonSchema(schema: GbnfJsonSchema
|
|
2
|
+
export declare function getGbnfGrammarForGbnfJsonSchema(schema: Readonly<GbnfJsonSchema>, { allowNewLines, scopePadSpaces }?: {
|
|
3
3
|
allowNewLines?: boolean;
|
|
4
4
|
scopePadSpaces?: number;
|
|
5
5
|
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGbnfGrammarForGbnfJsonSchema.js","sourceRoot":"","sources":["../../../src/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,oCAAoC,EAAC,MAAM,iDAAiD,CAAC;AACrG,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAGjE,MAAM,UAAU,+BAA+B,CAAC,
|
|
1
|
+
{"version":3,"file":"getGbnfGrammarForGbnfJsonSchema.js","sourceRoot":"","sources":["../../../src/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,oCAAoC,EAAC,MAAM,iDAAiD,CAAC;AACrG,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAGjE,MAAM,UAAU,+BAA+B,CAAC,MAAgC,EAAE,EAC9E,aAAa,GAAG,IAAI,EACpB,cAAc,GAAG,CAAC,KAIlB,EAAE;IACF,MAAM,gBAAgB,GAAG,IAAI,oBAAoB,EAAE,CAAC;IACpD,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,EAAC,aAAa,EAAE,cAAc,EAAC,CAAC,CAAC;IAC3E,MAAM,YAAY,GAAG,oCAAoC,CAAC,MAAM,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;IAChG,MAAM,WAAW,GAAG,YAAY,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE9D,OAAO,gBAAgB,CAAC,gBAAgB,CAAC,WAAW,GAAG,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
|
|
3
|
+
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
4
|
+
export declare class GbnfAnyJson extends GbnfTerminal {
|
|
5
|
+
readonly scopeState: GbnfJsonScopeState;
|
|
6
|
+
constructor(scopeState?: GbnfJsonScopeState);
|
|
7
|
+
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
|
|
8
|
+
protected getRuleName(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
3
|
+
import { GbnfString } from "./GbnfString.js";
|
|
4
|
+
import { GbnfOr } from "./GbnfOr.js";
|
|
5
|
+
import { GbnfNumber } from "./GbnfNumber.js";
|
|
6
|
+
import { GbnfBoolean } from "./GbnfBoolean.js";
|
|
7
|
+
import { GbnfNull } from "./GbnfNull.js";
|
|
8
|
+
import { GbnfArray } from "./GbnfArray.js";
|
|
9
|
+
import { reservedRuleNames } from "./gbnfConsts.js";
|
|
10
|
+
import { GbnfObjectMap } from "./GbnfObjectMap.js";
|
|
11
|
+
export class GbnfAnyJson extends GbnfTerminal {
|
|
12
|
+
scopeState;
|
|
13
|
+
constructor(scopeState = new GbnfJsonScopeState()) {
|
|
14
|
+
super();
|
|
15
|
+
this.scopeState = scopeState;
|
|
16
|
+
}
|
|
17
|
+
getGrammar(grammarGenerator) {
|
|
18
|
+
const subAnyJsonScopeItem = this.scopeState.settings.allowNewLines
|
|
19
|
+
? new GbnfAnyJson(new GbnfJsonScopeState({
|
|
20
|
+
allowNewLines: false,
|
|
21
|
+
scopePadSpaces: this.scopeState.settings.scopePadSpaces
|
|
22
|
+
}, this.scopeState.currentNestingScope))
|
|
23
|
+
: new GbnfSubAnyJson(this.scopeState);
|
|
24
|
+
return new GbnfOr([
|
|
25
|
+
new GbnfString(),
|
|
26
|
+
new GbnfNumber({ allowFractional: true }),
|
|
27
|
+
new GbnfBoolean(),
|
|
28
|
+
new GbnfNull(),
|
|
29
|
+
new GbnfArray({
|
|
30
|
+
items: subAnyJsonScopeItem,
|
|
31
|
+
scopeState: this.scopeState
|
|
32
|
+
}),
|
|
33
|
+
new GbnfObjectMap({
|
|
34
|
+
fields: [],
|
|
35
|
+
additionalProperties: subAnyJsonScopeItem,
|
|
36
|
+
scopeState: this.scopeState
|
|
37
|
+
})
|
|
38
|
+
]).getGrammar(grammarGenerator);
|
|
39
|
+
}
|
|
40
|
+
getRuleName() {
|
|
41
|
+
return reservedRuleNames.anyJson({
|
|
42
|
+
allowNewLines: this.scopeState.settings.allowNewLines,
|
|
43
|
+
scopeSpaces: this.scopeState.settings.scopePadSpaces,
|
|
44
|
+
nestingScope: this.scopeState.currentNestingScope
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class GbnfSubAnyJson extends GbnfAnyJson {
|
|
49
|
+
getGrammar() {
|
|
50
|
+
return this.getRuleName();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=GbnfAnyJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GbnfAnyJson.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfAnyJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAGjD,MAAM,OAAO,WAAY,SAAQ,YAAY;IACzB,UAAU,CAAqB;IAE/C,YAAmB,aAAiC,IAAI,kBAAkB,EAAE;QACxE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,UAAU,CAAC,gBAAsC;QACpD,MAAM,mBAAmB,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa;YAC9D,CAAC,CAAC,IAAI,WAAW,CACb,IAAI,kBAAkB,CAAC;gBACnB,aAAa,EAAE,KAAK;gBACpB,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc;aAC1D,EAAE,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAC1C;YACD,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE1C,OAAO,IAAI,MAAM,CAAC;YACd,IAAI,UAAU,EAAE;YAChB,IAAI,UAAU,CAAC,EAAC,eAAe,EAAE,IAAI,EAAC,CAAC;YACvC,IAAI,WAAW,EAAE;YACjB,IAAI,QAAQ,EAAE;YACd,IAAI,SAAS,CAAC;gBACV,KAAK,EAAE,mBAAmB;gBAC1B,UAAU,EAAE,IAAI,CAAC,UAAU;aAC9B,CAAC;YACF,IAAI,aAAa,CAAC;gBACd,MAAM,EAAE,EAAE;gBACV,oBAAoB,EAAE,mBAAmB;gBACzC,UAAU,EAAE,IAAI,CAAC,UAAU;aAC9B,CAAC;SACL,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,OAAO,CAAC;YAC7B,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa;YACrD,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc;YACpD,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,mBAAmB;SACpD,CAAC,CAAC;IACP,CAAC;CACJ;AAED,MAAM,cAAe,SAAQ,WAAW;IACpB,UAAU;QACtB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;CACJ"}
|
|
@@ -2,8 +2,17 @@ import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
|
2
2
|
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
|
|
3
3
|
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
4
4
|
export declare class GbnfArray extends GbnfTerminal {
|
|
5
|
-
readonly items
|
|
5
|
+
readonly items?: GbnfTerminal;
|
|
6
|
+
readonly prefixItems?: GbnfTerminal[];
|
|
7
|
+
readonly minItems: number;
|
|
8
|
+
readonly maxItems?: number;
|
|
6
9
|
readonly scopeState: GbnfJsonScopeState;
|
|
7
|
-
constructor(items
|
|
10
|
+
constructor({ items, prefixItems, minItems, maxItems, scopeState }: {
|
|
11
|
+
items?: GbnfTerminal;
|
|
12
|
+
prefixItems?: GbnfTerminal[];
|
|
13
|
+
minItems?: number;
|
|
14
|
+
maxItems?: number;
|
|
15
|
+
scopeState: GbnfJsonScopeState;
|
|
16
|
+
});
|
|
8
17
|
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
|
|
9
18
|
}
|
|
@@ -2,31 +2,80 @@ import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
|
2
2
|
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
3
3
|
import { GbnfWhitespace } from "./GbnfWhitespace.js";
|
|
4
4
|
import { GbnfGrammar } from "./GbnfGrammar.js";
|
|
5
|
-
import {
|
|
5
|
+
import { GbnfRepetition } from "./GbnfRepetition.js";
|
|
6
|
+
import { GbnfCommaWhitespace } from "./GbnfCommaWhitespace.js";
|
|
7
|
+
import { GbnfAnyJson } from "./GbnfAnyJson.js";
|
|
6
8
|
export class GbnfArray extends GbnfTerminal {
|
|
7
9
|
items;
|
|
10
|
+
prefixItems;
|
|
11
|
+
minItems;
|
|
12
|
+
maxItems;
|
|
8
13
|
scopeState;
|
|
9
|
-
constructor(items, scopeState = new GbnfJsonScopeState()) {
|
|
14
|
+
constructor({ items, prefixItems, minItems = 0, maxItems, scopeState = new GbnfJsonScopeState() }) {
|
|
10
15
|
super();
|
|
11
16
|
this.items = items;
|
|
17
|
+
this.prefixItems = prefixItems;
|
|
18
|
+
this.minItems = Math.floor(minItems);
|
|
19
|
+
this.maxItems = maxItems == null ? undefined : Math.floor(maxItems);
|
|
12
20
|
this.scopeState = scopeState;
|
|
21
|
+
if (this.prefixItems != null && this.minItems < this.prefixItems.length)
|
|
22
|
+
this.minItems = this.prefixItems.length;
|
|
23
|
+
else if (this.minItems < 0)
|
|
24
|
+
this.minItems = 0;
|
|
25
|
+
if (this.maxItems != null && this.maxItems < this.minItems)
|
|
26
|
+
this.maxItems = this.minItems;
|
|
27
|
+
else if (this.maxItems != null && this.maxItems < 0)
|
|
28
|
+
this.maxItems = 0;
|
|
13
29
|
}
|
|
14
30
|
getGrammar(grammarGenerator) {
|
|
15
|
-
const
|
|
16
|
-
? new GbnfWhitespace(this.scopeState.getForNewScope(), { newLine })
|
|
17
|
-
: new GbnfWhitespace(this.scopeState, { newLine })
|
|
18
|
-
const
|
|
31
|
+
const getWhitespaceRule = (newScope, newLine) => (newScope
|
|
32
|
+
? new GbnfWhitespace(this.scopeState.getForNewScope(), { newLine })
|
|
33
|
+
: new GbnfWhitespace(this.scopeState, { newLine }));
|
|
34
|
+
const getWhitespaceRuleName = (newScope, newLine) => (getWhitespaceRule(newScope, newLine).resolve(grammarGenerator));
|
|
35
|
+
const getCommaWhitespaceRule = (newScope, newLine) => (newScope
|
|
36
|
+
? new GbnfCommaWhitespace(this.scopeState.getForNewScope(), { newLine })
|
|
37
|
+
: new GbnfCommaWhitespace(this.scopeState, { newLine }));
|
|
38
|
+
const getCommaWhitespaceRuleName = (newScope, newLine) => (getCommaWhitespaceRule(newScope, newLine).resolve(grammarGenerator));
|
|
39
|
+
const arrayItemsGrammar = [];
|
|
40
|
+
if (this.prefixItems != null && this.prefixItems.length > 0) {
|
|
41
|
+
for (const item of this.prefixItems) {
|
|
42
|
+
if (arrayItemsGrammar.length > 0)
|
|
43
|
+
arrayItemsGrammar.push(getCommaWhitespaceRuleName(true, "before"));
|
|
44
|
+
arrayItemsGrammar.push(item.resolve(grammarGenerator));
|
|
45
|
+
}
|
|
46
|
+
if (this.minItems > this.prefixItems.length || this.maxItems == null || this.maxItems > this.prefixItems.length) {
|
|
47
|
+
const restMinRepetitions = this.minItems - this.prefixItems.length;
|
|
48
|
+
const restMaxRepetitions = this.maxItems == null
|
|
49
|
+
? undefined
|
|
50
|
+
: this.maxItems - this.prefixItems.length;
|
|
51
|
+
if (arrayItemsGrammar.length > 0)
|
|
52
|
+
arrayItemsGrammar.push(new GbnfRepetition({
|
|
53
|
+
value: new GbnfGrammar([
|
|
54
|
+
getCommaWhitespaceRuleName(true, "before"),
|
|
55
|
+
(this.items ?? new GbnfAnyJson()).resolve(grammarGenerator)
|
|
56
|
+
], true),
|
|
57
|
+
minRepetitions: restMinRepetitions,
|
|
58
|
+
maxRepetitions: restMaxRepetitions
|
|
59
|
+
}).getGrammar(grammarGenerator));
|
|
60
|
+
else
|
|
61
|
+
arrayItemsGrammar.push(new GbnfRepetition({
|
|
62
|
+
value: this.items ?? new GbnfAnyJson(),
|
|
63
|
+
separator: getCommaWhitespaceRule(true, "before"),
|
|
64
|
+
minRepetitions: restMinRepetitions,
|
|
65
|
+
maxRepetitions: restMaxRepetitions
|
|
66
|
+
}).getGrammar(grammarGenerator));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
arrayItemsGrammar.push(new GbnfRepetition({
|
|
71
|
+
value: this.items ?? new GbnfAnyJson(),
|
|
72
|
+
separator: getCommaWhitespaceRule(true, "before"),
|
|
73
|
+
minRepetitions: this.minItems,
|
|
74
|
+
maxRepetitions: this.maxItems
|
|
75
|
+
}).getGrammar(grammarGenerator));
|
|
19
76
|
return new GbnfGrammar([
|
|
20
77
|
'"["', getWhitespaceRuleName(true, "before"),
|
|
21
|
-
new
|
|
22
|
-
new GbnfGrammar([
|
|
23
|
-
"(", itemsGrammarRuleName, ")",
|
|
24
|
-
"(", '","', getWhitespaceRuleName(true, "before"), itemsGrammarRuleName, ")*"
|
|
25
|
-
]),
|
|
26
|
-
new GbnfGrammar([
|
|
27
|
-
"(", itemsGrammarRuleName, ")?"
|
|
28
|
-
])
|
|
29
|
-
]).getGrammar(grammarGenerator),
|
|
78
|
+
new GbnfGrammar(arrayItemsGrammar).getGrammar(),
|
|
30
79
|
getWhitespaceRuleName(false, "before"), '"]"'
|
|
31
80
|
]).getGrammar();
|
|
32
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfArray.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"GbnfArray.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAG7C,MAAM,OAAO,SAAU,SAAQ,YAAY;IACvB,KAAK,CAAgB;IACrB,WAAW,CAAkB;IAC7B,QAAQ,CAAS;IACjB,QAAQ,CAAU;IAClB,UAAU,CAAqB;IAE/C,YAAmB,EACf,KAAK,EAAE,WAAW,EAAE,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAC1C,UAAU,GAAG,IAAI,kBAAkB,EAAE,EAIxC;QACG,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ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AE;YAC/C,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK;SAChD,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACJ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
-
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
|
|
3
2
|
export declare class GbnfBoolean extends GbnfTerminal {
|
|
4
|
-
getGrammar(
|
|
3
|
+
getGrammar(): string;
|
|
4
|
+
protected getGrammarFromResolve(): string;
|
|
5
|
+
private _getGrammar;
|
|
5
6
|
protected getRuleName(): string;
|
|
6
7
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
-
import { GbnfOr } from "./GbnfOr.js";
|
|
3
|
-
import { GbnfGrammar } from "./GbnfGrammar.js";
|
|
4
2
|
import { reservedRuleNames } from "./gbnfConsts.js";
|
|
5
3
|
export class GbnfBoolean extends GbnfTerminal {
|
|
6
|
-
getGrammar(
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
getGrammar() {
|
|
5
|
+
return this._getGrammar();
|
|
6
|
+
}
|
|
7
|
+
getGrammarFromResolve() {
|
|
8
|
+
return this._getGrammar(false);
|
|
9
|
+
}
|
|
10
|
+
_getGrammar(wrap = true) {
|
|
11
|
+
const values = ['"true"', '"false"'];
|
|
12
|
+
if (wrap)
|
|
13
|
+
return [
|
|
14
|
+
"(", values.join(" | "), ")"
|
|
15
|
+
].join(" ");
|
|
16
|
+
return values.join(" | ");
|
|
11
17
|
}
|
|
12
18
|
getRuleName() {
|
|
13
19
|
return reservedRuleNames.boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfBoolean.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfBoolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"GbnfBoolean.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfBoolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,WAAY,SAAQ,YAAY;IAClC,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;IAEkB,qBAAqB;QACpC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,OAAgB,IAAI;QACpC,MAAM,MAAM,GAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAE/C,IAAI,IAAI;YACJ,OAAO;gBACH,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG;aAC/B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEhB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,OAAO,CAAC;IACrC,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
3
|
+
export declare class GbnfCommaWhitespace extends GbnfTerminal {
|
|
4
|
+
readonly scopeState: GbnfJsonScopeState;
|
|
5
|
+
readonly newLine: "before" | "after" | false;
|
|
6
|
+
constructor(scopeState: GbnfJsonScopeState, { newLine }?: {
|
|
7
|
+
newLine?: "before" | "after" | false;
|
|
8
|
+
});
|
|
9
|
+
getGrammar(): string;
|
|
10
|
+
protected getRuleName(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfGrammar } from "./GbnfGrammar.js";
|
|
3
|
+
import { GbnfWhitespace } from "./GbnfWhitespace.js";
|
|
4
|
+
import { reservedRuleNames } from "./gbnfConsts.js";
|
|
5
|
+
export class GbnfCommaWhitespace extends GbnfTerminal {
|
|
6
|
+
scopeState;
|
|
7
|
+
newLine;
|
|
8
|
+
constructor(scopeState, { newLine = "before" } = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.scopeState = scopeState;
|
|
11
|
+
this.newLine = newLine;
|
|
12
|
+
}
|
|
13
|
+
getGrammar() {
|
|
14
|
+
return new GbnfGrammar([
|
|
15
|
+
'","', new GbnfWhitespace(this.scopeState, { newLine: this.newLine }).getGrammar()
|
|
16
|
+
]).getGrammar();
|
|
17
|
+
}
|
|
18
|
+
getRuleName() {
|
|
19
|
+
return reservedRuleNames.commaWhitespace({
|
|
20
|
+
newLine: this.scopeState.settings.allowNewLines
|
|
21
|
+
? this.newLine
|
|
22
|
+
: false,
|
|
23
|
+
scopeSpaces: this.scopeState.settings.scopePadSpaces,
|
|
24
|
+
nestingScope: this.scopeState.currentNestingScope
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=GbnfCommaWhitespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GbnfCommaWhitespace.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfCommaWhitespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACjC,UAAU,CAAqB;IAC/B,OAAO,CAA6B;IAEpD,YAAmB,UAA8B,EAAE,EAC/C,OAAO,GAAG,QAAQ,KAGlB,EAAE;QACF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,WAAW,CAAC;YACnB,KAAK,EAAE,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,EAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAC,CAAC,UAAU,EAAE;SACnF,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,eAAe,CAAC;YACrC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa;gBAC3C,CAAC,CAAC,IAAI,CAAC,OAAO;gBACd,CAAC,CAAC,KAAK;YACX,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc;YACpD,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,mBAAmB;SACpD,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
|
|
3
|
+
import { GbnfJsonFormatStringSchema } from "../types.js";
|
|
4
|
+
export declare class GbnfFormatString extends GbnfTerminal {
|
|
5
|
+
readonly format: GbnfJsonFormatStringSchema["format"];
|
|
6
|
+
constructor(format: GbnfJsonFormatStringSchema["format"]);
|
|
7
|
+
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
|
|
8
|
+
protected getRuleName(): string;
|
|
9
|
+
private _getDateGrammar;
|
|
10
|
+
private _getTimeGrammar;
|
|
11
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { reservedRuleNames } from "./gbnfConsts.js";
|
|
3
|
+
import { GbnfGrammar } from "./GbnfGrammar.js";
|
|
4
|
+
import { GbnfString } from "./GbnfString.js";
|
|
5
|
+
export class GbnfFormatString extends GbnfTerminal {
|
|
6
|
+
format;
|
|
7
|
+
constructor(format) {
|
|
8
|
+
super();
|
|
9
|
+
this.format = format;
|
|
10
|
+
}
|
|
11
|
+
getGrammar(grammarGenerator) {
|
|
12
|
+
const quote = '"\\""';
|
|
13
|
+
if (this.format === "date")
|
|
14
|
+
return new GbnfGrammar([
|
|
15
|
+
quote,
|
|
16
|
+
this._getDateGrammar(),
|
|
17
|
+
quote
|
|
18
|
+
]).getGrammar();
|
|
19
|
+
else if (this.format === "time") {
|
|
20
|
+
return new GbnfGrammar([
|
|
21
|
+
quote,
|
|
22
|
+
this._getTimeGrammar(),
|
|
23
|
+
quote
|
|
24
|
+
]).getGrammar();
|
|
25
|
+
}
|
|
26
|
+
else if (this.format === "date-time")
|
|
27
|
+
return new GbnfGrammar([
|
|
28
|
+
quote,
|
|
29
|
+
this._getDateGrammar(),
|
|
30
|
+
'"T"',
|
|
31
|
+
this._getTimeGrammar(),
|
|
32
|
+
quote
|
|
33
|
+
]).getGrammar();
|
|
34
|
+
return new GbnfString({
|
|
35
|
+
minLength: 0,
|
|
36
|
+
maxLength: 0
|
|
37
|
+
}).resolve(grammarGenerator);
|
|
38
|
+
}
|
|
39
|
+
getRuleName() {
|
|
40
|
+
return reservedRuleNames.formatString(this.format);
|
|
41
|
+
}
|
|
42
|
+
_getDateGrammar() {
|
|
43
|
+
return new GbnfGrammar([
|
|
44
|
+
"[0-9]{4}",
|
|
45
|
+
'"-"',
|
|
46
|
+
or([
|
|
47
|
+
'"0" [1-9]',
|
|
48
|
+
'"1" [012]'
|
|
49
|
+
]),
|
|
50
|
+
'"-"',
|
|
51
|
+
or([
|
|
52
|
+
'"0" [1-9]',
|
|
53
|
+
"[12] [0-9]",
|
|
54
|
+
'"3" [01]'
|
|
55
|
+
])
|
|
56
|
+
]).getGrammar();
|
|
57
|
+
}
|
|
58
|
+
_getTimeGrammar() {
|
|
59
|
+
return new GbnfGrammar([
|
|
60
|
+
or([
|
|
61
|
+
"[01] [0-9]",
|
|
62
|
+
'"2" [0-3]'
|
|
63
|
+
]),
|
|
64
|
+
'":"',
|
|
65
|
+
"[0-5] [0-9]",
|
|
66
|
+
'":"',
|
|
67
|
+
"[0-5] [0-9]",
|
|
68
|
+
'( "." [0-9]{3} )?',
|
|
69
|
+
or([
|
|
70
|
+
'"Z"',
|
|
71
|
+
new GbnfGrammar([
|
|
72
|
+
or([
|
|
73
|
+
'"+"',
|
|
74
|
+
'"-"'
|
|
75
|
+
]),
|
|
76
|
+
or([
|
|
77
|
+
"[01] [0-9]",
|
|
78
|
+
'"2" [0-3]'
|
|
79
|
+
]),
|
|
80
|
+
'":"',
|
|
81
|
+
"[0-5] [0-9]"
|
|
82
|
+
]).getGrammar()
|
|
83
|
+
])
|
|
84
|
+
]).getGrammar();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function or(values) {
|
|
88
|
+
return "(" + values.join(" | ") + ")";
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=GbnfFormatString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GbnfFormatString.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfFormatString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAG3C,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9B,MAAM,CAAuC;IAE7D,YAAmB,MAA4C;QAC3D,KAAK,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;gBACZ,WAAW;aACd,CAAC;YACF,KAAK;YACL,aAAa;YACb,KAAK;YACL,aAAa;YACb,mBAAmB;YACnB,EAAE,CAAC;gBACC,KAAK;gBACL,IAAI,WAAW,CAAC;oBACZ,EAAE,CAAC;wBACC,KAAK;wBACL,KAAK;qBACR,CAAC;oBACF,EAAE,CAAC;wBACC,YAAY;wBACZ,WAAW;qBACd,CAAC;oBACF,KAAK;oBACL,aAAa;iBAChB,CAAC,CAAC,UAAU,EAAE;aAClB,CAAC;SACL,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACJ;AAED,SAAS,EAAE,CAAC,MAAgB;IACxB,OAAO,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;AAC1C,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
|
|
2
3
|
export declare class GbnfGrammar extends GbnfTerminal {
|
|
3
4
|
readonly grammar: string | string[];
|
|
4
|
-
|
|
5
|
+
readonly resolveToRawGrammar: boolean;
|
|
6
|
+
constructor(grammar: string | string[], resolveToRawGrammar?: boolean);
|
|
5
7
|
getGrammar(): string;
|
|
8
|
+
resolve(grammarGenerator: GbnfGrammarGenerator): string;
|
|
6
9
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
2
|
export class GbnfGrammar extends GbnfTerminal {
|
|
3
3
|
grammar;
|
|
4
|
-
|
|
4
|
+
resolveToRawGrammar;
|
|
5
|
+
constructor(grammar, resolveToRawGrammar = false) {
|
|
5
6
|
super();
|
|
6
7
|
this.grammar = grammar;
|
|
8
|
+
this.resolveToRawGrammar = resolveToRawGrammar;
|
|
7
9
|
}
|
|
8
10
|
getGrammar() {
|
|
9
11
|
if (this.grammar instanceof Array)
|
|
@@ -12,5 +14,10 @@ export class GbnfGrammar extends GbnfTerminal {
|
|
|
12
14
|
.join(" ");
|
|
13
15
|
return this.grammar;
|
|
14
16
|
}
|
|
17
|
+
resolve(grammarGenerator) {
|
|
18
|
+
if (this.resolveToRawGrammar)
|
|
19
|
+
return this.getGrammar();
|
|
20
|
+
return super.resolve(grammarGenerator);
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
23
|
//# sourceMappingURL=GbnfGrammar.js.map
|