mgcp: Reduce the amount of parsers needed and maybe speed-up parsing
Do not create so many blank/word/: parsers and simplify the parameter matching. We can check for legal keywords in a better and probably more quick way in case we need to. I could use "trim" instead of matching blanks and throwing them away.
This commit is contained in:
parent
d5248eceec
commit
31c7c8e55b
|
@ -86,7 +86,7 @@ Object subclass: MGCPCommandBase [
|
|||
<category: 'private'>
|
||||
"TODO: Share code with MGCPResponse"
|
||||
anArray do: [:each |
|
||||
self addParameter: each first first asString with: each first fourth].
|
||||
self addParameter: each first first with: each first fourth].
|
||||
]
|
||||
|
||||
parameterAt: aKey [
|
||||
|
|
|
@ -86,7 +86,7 @@ Object subclass: MGCPResponse [
|
|||
<category: 'creation'>
|
||||
|
||||
aList do: [:each |
|
||||
params at: each first first asString put: each first fourth].
|
||||
params at: each first first put: each first fourth].
|
||||
]
|
||||
|
||||
addSDPFromDict: aDict [
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
PackageLoader fileInPackage: 'PetitParser'.
|
||||
|
||||
PP.PPCompositeParser subclass: MGCPGrammar [
|
||||
| MGCPMessage EOL One_WSP MGCPMessage MGCPCommandLine MGCPVerb transaction_id endpointName MGCPversion MGCPParameter MGCPCommand ParameterValue SDPRecord SDPLine SDPinformation MGCPResponseLine responseCode responseString packageName |
|
||||
| MGCPMessage EOL One_WSP MGCPMessage MGCPCommandLine MGCPVerb transaction_id endpointName MGCPversion MGCPParameter MGCPCommand ParameterValue SDPRecord SDPLine SDPinformation MGCPResponseLine responseCode responseString packageName wordParser |
|
||||
<category: 'OsmoMGCP-Core'>
|
||||
<comment: 'I am a the Grammar of the Media Gateway Control Protocol'>
|
||||
|
||||
|
@ -99,39 +99,17 @@ PP.PPCompositeParser subclass: MGCPGrammar [
|
|||
]
|
||||
|
||||
wordParser [
|
||||
^ #word asParser / #punctuation asParser / ' ' asParser
|
||||
^ (#word asParser / #punctuation asParser / ' ' asParser) star flatten
|
||||
]
|
||||
|
||||
ParameterValue [
|
||||
^ ($K asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($B asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($C asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($I asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($N asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($X asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($L asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($M asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($R asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($S asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($D asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($O asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($P asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($E asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($Z asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($Z asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('Z2' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('I2' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($F asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($Q asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($T asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('RM' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('RD' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
($A asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('ES' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('PL' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('MD' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('X-Osmo-CP' asParser, $: asParser, #blank asParser star, self wordParser star flatten) /
|
||||
('X-Osmux' asParser, $: asParser, #blank asParser star, self wordParser star flatten)
|
||||
"This code used to check for legal variable names but the way
|
||||
it was done created a lot of parsers and choice. Norbert has
|
||||
pointed me to use >=> (or >< in GST) to make the keyword check
|
||||
in the parser. One example is >>#failOnReservedWords: inside
|
||||
the ASN1 code."
|
||||
^ (#word asParser / $- asParser) plus flatten, $: asParser,
|
||||
#blank asParser plus, wordParser
|
||||
]
|
||||
|
||||
MGCPResponse [
|
||||
|
@ -179,7 +157,7 @@ PP.PPCompositeParser subclass: MGCPGrammar [
|
|||
]
|
||||
|
||||
SDPLine [
|
||||
^ self wordParser star flatten
|
||||
^wordParser
|
||||
]
|
||||
]
|
||||
|
||||
|
|
Reference in New Issue