KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there a simpler way to parse 1-line comments than this? comment ^ '//' asParser , (#any asParser starLazy: (#newline asParser)) , #newline asParser ==> [ :result | nil "Ignore comments" ] program ^ (comment / instruction) star ==> [ :result | N2TProgramNode new setNodes: (result copyWithout: nil) ] I'm particularly unsure about the repetition of (#newline asParser) and the #copyWithout:. After Lukas' answer I came up with the much simpler following solution: program ^ programEntity star ==> [ :result | N2TProgramNode new setNodes: result] programEntity ^ instruction trim: ignorable ignorable ^ comment / #space asParser comment ^ '//' asParser , #newline asParser negate star
Tags (comma-separated)
Save Edits
Cancel