मैं नई Parsec करने के लिए (और सामान्य में पारसर्स करने के लिए), और मैं इस पार्सर मैंने लिखा के साथ कुछ समस्या हो रही है:कठिनाई एक Parsec पार्सर रिक्त स्थान को छोड़ने के लिए हो रही है सही ढंग से
list = char '(' *> many (spaces *> some letter) <* spaces <* char ')'
विचार करने के लिए है इस प्रारूप में सूचियों को पार्स (मैं s-भाव करने के लिए काम कर रहा हूँ):
import Control.Applicative
import Text.ParserCombinators.Parsec hiding (many)
list = char '(' *> many (spaces *> some letter) <* spaces <* char ')'
test s = do
putStrLn $ "Testing " ++ show s ++ ":"
parseTest list s
putStrLn ""
main = do
test "()"
test "(hello)"
test "(hello world)"
test "(hello world)"
test "(hello world)"
test "()"
टी:
(firstElement secondElement thirdElement and so on)
मैं इसे परीक्षण करने के लिए इस कोड को लिखा था उसकी है उत्पादन मैं:
Testing "()":
[]
Testing "(hello)":
["hello"]
Testing "(hello world)":
["hello","world"]
Testing "(hello world)":
["hello","world"]
Testing "(hello world)":
parse error at (line 1, column 14):
unexpected ")"
expecting space or letter
Testing "()":
parse error at (line 1, column 3):
unexpected ")"
expecting space or letter
आप देख सकते हैं, यह विफल है जब वहाँ सूची के अंतिम तत्व है, और समापन )
के बीच सफेद स्थान। मुझे समझ में नहीं आता है कि spaces
द्वारा सफेद जगह का उपभोग क्यों नहीं किया जाता है, मैंने <* char ')'
से पहले रखा था। मैंने क्या मूर्खतापूर्ण गलती की है?