New answers tagged

4

For producing a NB file without line breaks you can Get it as a Notebook expression, then Export it with PageWidth -> Infinity as "Package" (other possible options does not work correctly: Export ignores PageWidth -> Infinity when exporting as "NB" and corrupts the code when exporting as "Text"): Export["document.nb", Get["ExampleData/document.nb"], ...


16

First of all, I agree, as OP mentioned in his comment, ANTLR is one of the proper ways to go. Now for this specific task, it might be easier to just compose a parser in the "dirty" way, except we don't have to go so far to regex. In my opinion Mathematica's StringExpression is much more powerful and very suitable for the job. All we have to do is (as OP ...


8

I extended the original question to support piping like the following. wget -qO- "http://google.com" // cat and it outputs the following. cat[][wget[-qO-,http://google.com][]] To get the following. CellPrint@ Cell[BoxData[""], "Input", Evaluatable -> True, CellEvaluationFunction -> Function[ Module[{t}, t = List@ReplaceRepeated[ ...


5

Remember that the internal form of an expression is often not the same as what you type as input or is displayed as output. For example the input 0.. is interpreted as Repeated[0] and Repeated[0] is displayed in output as (0).. Hold and HoldForm prevent evaluation but do not prevent parsing of input and formatting of output, so it is no surprise that ...



Top 50 recent answers are included