我想模擬mqsi命令,使用ANTLR並遇到以下問題。 mqsicreateconfigurableservice的文檔針對queuePrefix說: 「前綴可以包含在WebSphere®MQ隊列名稱中有效的任何字符,但不得超過8個字符,且不得以句點(。)開頭或結尾。例如,SET.1有效,但.SET1和SET1無效,多個可配置服務可以使用相同的隊列前綴。「使用ANTLR,如何處理特定的重複而不使用語言特定的語義謂詞?
我已經使用了以下內容作爲權宜之計,但這種技術意味着我必須至少有兩個字符的名稱,並且看起來非常浪費且不可擴展的解決方案。有更好的方法嗎?
參見 'queuePrefixValue',下面...
感謝:O)
parser grammar mqsicreateconfigurableservice;
mqsicreateconfigurableservice
: 'mqsicreateconfigurableservice' ' '+ params
;
params : (broker ' '+ switches+)
;
broker : validChar+
;
switches
: AggregationConfigurableService
;
AggregationConfigurableService
: (objectName ' '+ AggregationNameValuePropertyPair)
;
objectName
: (' '+ '-o' ' '+ validChar+)
;
AggregationNameValuePropertyPair
: (' '+ '-n' ' '+ 'queuePrefix' ' '+ '-v' ' '+ queuePrefixValue)?
(' '+ '-n' ' '+ 'timeoutSeconds' ' '+ '-v' ' '+ timeoutSecondsValue)?
;
// I'm not satisfied with this rule as it means at least two digits are mandatory
//Couldn't see how to use regex or semantic predicates which appear to offer a solution
queuePrefixValue
: validChar (validChar | '.')? (validChar | '.')? (validChar | '.')? (validChar | '.')? (validChar | '.')? (validChar | '.')? validChar
;
timeoutSecondsValue //a positive integer
: ('0'..'9')+
;
//This char list is just a temporary subset which eventually needs to reflect all the WebSphere acceptable characters, apart from the dot '.'
validChar
: (('a'..'z')|('A'..'Z')|('0'..'9'))
;