Hot answers tagged parsing
16
Symbols are created in the current context during parsing. This should not be a problem in normal circumstances as the symbols are merely "initialized" without values or properties.
See these posts for more information:
Is it possible to use Begin and End inside a Manipulate?
Why doesn't this use of Begin[] work?
You raise good questions in the ...
12
The main points of this answer are that,first, it seems rather difficult to have a fully universal mechanism for option-validation, and second, such a mechanism is not currently available in Mathematica on the language level (meaning automation of complete option-checking, including both the option's name and value).
In the particular case in question, ...
7
tokenize[str_] := Module[{exp,
nb = CreateDocument[{ExpressionCell@
InputForm@MakeExpression[str, StandardForm]},
Visible -> False]},
SelectionMove[nb, Next, Cell];
exp = Flatten[
NotebookRead[nb][[1, 1]] /. {RowBox -> List,
i_String /; StringMatchQ[i, Whitespace ..] :> Sequence[]}];
NotebookClose[nb];
exp[[3 ...
6
This seems to work:
StringCases["blabla ...Hello Hello ... blabla ... Goobye Goobye ..",
Longest[___ ~~ a : "Hello"] ~~ b : Shortest[___ ~~ "Goobye"] :> a ~~ b]
Update
If there are multiple substrings to extract you can use recursion:
extractbetween[str_, x_, y_] := Module[{f},
f[s_] := StringCases[s,
Longest[a___ ~~ x] ~~ b : Shortest[___ ~~ ...
6
I think this particular scenario has to do with how you can create your own Import/Export filters: Developing an Import Converter
Regarding 'verification' as in the Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, FrameTicksStyle -> Red] example given by Nasser, keep in mind that you might have options parameterized like so:
Manipulate[
Plot[Sin[x], {x, ...
6
The simple answer is, if you want a string converted to StandardForm, you could wrap BoxData around it. E.g.,
CellPrint[Cell[BoxData["myFunction::usage=\"myFunction does ...\";"], "Input"]]
But, in general, I wouldn't structure this as a question of CellPrint vs. FrontEnd`CellPrint. FrontEnd`CellPrint is undocumented, and therefore there is no contract ...
2
A possible solution is just to replace your boundary words with single characters. I think what you are venturing into is something akin to look-behind, which I don't think is supported. Anyways here's how I would do it:
boundary = {"Hello", "Goobye"};
limits = {"\[FormalCapitalX]", "\[FormalCapitalY]"};
shift[str_, from_, to_] := StringReplace[str, Rule ...
2
Figured out what I'm going to do:
Read a line from the file.
Try converting it to an expression (ToExpression[]).
If successful, I've found an expression (or a comment or a blank line).
If not, grab additional lines and concatenate them with the line that failed to parse until I find a series of lines that succeeds.
The code:
ClearAll[breakExpressions]; ...
1
If you have a more powerful box available, you could install Mathematica there, and run it from the netbook using X forwarding over SSH (ssh -X). The UI should be responsive as long as you have a good network connection and you aren't displaying large graphics or plots.
Some documentation for setting up an SSH server:
...
1
This, with a suitable transform function to traverse the tree, would be an adequate tokenizer:
TreeForm[Hold[
Plot3D[{x^2 + y^2, -x^2 - y^2}, {x, -2, 2}, {y, -2, 2},
RegionFunction -> Function[{x, y, z}, x^2 + y^2 <= 4]]]]
Only top voted, non community-wiki answers of a minimum length are eligible

