2011-05-10 10 views
9

में सी-स्टाइल टिप्पणियों को अनदेखा करना मेरे पार्सर सम्मान (अनदेखा) सी-शैली टिप्पणियों को बनाने का सबसे आसान तरीका क्या है। मुझे दोनों टिप्पणी प्रकारों में दिलचस्पी है, हालांकि केवल एक ही प्रकार का समाधान भी स्वागत है।स्कैला संयोजक पार्सर

मैं वर्तमान में बस जावाटोकनर्स को विस्तारित कर रहा हूं।

+0

आप किस पार्सर लाइब्रेरी का उपयोग कर रहे हैं? –

उत्तर

11

आप एक साधारण नियमित अभिव्यक्ति का उपयोग कर सकते हैं, जब तक कि आप घोंसला न करें। इसे whiteSpace के अंदर रखें:

scala> object T extends JavaTokenParsers { 
    | protected override val whiteSpace = """(\s|//.*|(?m)/\*(\*(?!/)|[^*])*\*/)+""".r 
    | def simpleParser = ident+ 
    | } 
defined module T 

scala> val testString = """ident // comment to the end of line 
    | another ident /* start comment 
    | end comment */ final ident""" 
testString: java.lang.String = 
ident // comment to the end of line 
another ident /* start comment 
end comment */ final ident 

scala> T.parseAll(T.simpleParser, testString) 
res0: T.ParseResult[List[String]] = [3.27] parsed: List(ident, another, ident, final, ident) 
+0

@ziggystar ठीक है, एक सेकंड प्रतीक्षा करें ... –

संबंधित मुद्दे