Questions tagged [parsing]

Questions about built-in/custom parsers or parsing techniques.

Filter by
Sorted by
Tagged with
44
votes
1answer
2k views

Local variables in Module leak into the Global context

From the Mathematica documentation on Module: Module allows you to set up local variables with names that are local to the module. But after using ...
15
votes
4answers
506 views

balanced Shortest[] and string-patterns

The pattern Shortest["A"~~__~~"B"] is oriented : It assumes the text is read from left to right and it takes the text between the first "A" and the next "B". Any "A"...
9
votes
2answers
247 views

FullForm with context for each symbol?

FullForm strips the context for any symbol that can be found on the Append[$ContextPath, $Context]: ...
10
votes
4answers
1k views

How to get the longest bracket pairs from a string

In C#, we can use regular expression to do some balancing groups, like we can get {<aa <bbb> <bbb> aa>, <<dfa>a>} from ...
21
votes
3answers
633 views

Tokenize Mathematica input in a simple way

Background Usually, I give detailed descriptions when I have a question which sometimes lead to that users don't write their answers because they maybe think their answer is too simple. Therefore, I ...
16
votes
0answers
215 views

Why does the FrontEnd lose matching of parentheses when we insert quotations?

Bug introduced in V10.0 and resolved in V11.3 (These are guesses. It is likely to have been resolved in an earlier version V11.X, but V11.3 is what I have access to.) I am running Mathematica 10.0....
7
votes
2answers
472 views

Using MatchQ (or other means) to parse an expression using sums of COS or SIN correctly

I am writing a function that will take an expression as input. I want to make sure the expression is valid first before processing it. Looking for a correct to use ...
14
votes
2answers
925 views

How to parse a clojure expression?

Clojure is a lisp-like language that runs on JVM and in Javascript. I just started learning it and I'm building a simple parser with Mathematica to understand and visualize it. Like other lisps every ...
33
votes
0answers
557 views

Front end goes wild with named slots

Bug introduced in 10 and persisting through 12.0.0 Assume the following simple expression {#"Test"}& Now go in front of the ...
4
votes
3answers
1k views

Importing CSV with multiline text fields

Bug introduced in 8 or earlier and fixed in 11.2.0 Here is a valid CSV: a1,b1,c1,d1,"e1 e1 e1" a2,b2,"c2 c2 c2",d2,e2 It has two rows and five columns, and ...
12
votes
0answers
337 views

After editing a file Mathematica 10 interprets […]^2 as […(])^2

Bug introduced in 10.0 and persisting through 10.2 or later This is a very weird bug and I don't really know how to reproduce it, so I'll just copy-paste the whole code ...
15
votes
3answers
2k views

How to implement a regular grammar?

What is the most simple, elegant way of implementing a rewrite-system defined as: $$ \begin{aligned} \Sigma &= \{a_1, a_2, a_3, ...\} \\ N &= \{A_1, A_2, A_3, ...\} \\ \{\alpha_1 , \...
17
votes
2answers
462 views

Why doesn't Mathematica use uniform criteria for validating Options?

Plot[Sin[x], {x, 0, 1}, pp -> 0] Gives as expected: Plot::optx: Unknown option pp in Plot[Sin[x],{x,0,1},pp->0]. >> However: ...
13
votes
2answers
1k views

Parsing a CSV file using Interpreter

The new Interpreter functionality in version 10 looks like it has the potential to make parsing custom data formats very easy. I'm trying to create a CSV parser. ...
5
votes
1answer
204 views

How to get “one Cell - one line” code format inside of NB files?

The PageWidth option controls the way the Cell's content is displayed, not the manner it's written in a ...
9
votes
1answer
189 views

Bug in grouping after editing code?

Bug introduced in 7.0 or earlier and persisting through 11.0 While looking at A question about conditional replacement I think I discovered a bug in the Front End that affects both 7.0.1 and 10.0.1 ...
9
votes
1answer
214 views

Why is this syntax for patterns with Optional values not supported?

I want to express Optional[PatternTest[Pattern[a,Blank[]],t],1] concisely. a : _?t : 1 is not quite this but works: ...
8
votes
3answers
1k views

How to parse information contained in a file name

I have a set of files containing my data, and the file-names contain relevant information that I would like to extract. What I have is: ...
6
votes
1answer
68 views

Can Read[] apply a custom function automatically to the read values?

Read[stream, Number] will return a single read number. We can use a number of standard, documented types instead of Number, ...
10
votes
4answers
531 views

What is the correct way to use specific rule for specific pattern match when parsing an expression?

update: Thanks for the answers below. But I noticed they do not handle the following special cases: lis=1 and lis=z , ...
4
votes
1answer
1k views

Extracting text from nested HTML lists <ul> <li>

We wish to analyze the tree structure of HTML documents that consist of nested lists, ie, using the HTML tags <ul> and ...
5
votes
1answer
54 views

Can we make preread replacements in an *.m* file before being run?

This the second question of (152743), the preamble of which is reproduced here: Those who don't have/prefer the front end of Mathematica will either use a plain ASCII editor to write a script in an ...
5
votes
1answer
51 views

Can we make new definitions for InputForm in packages?

Those who don't have/prefer the front end of Mathematica will either use a plain ASCII editor to write a script in an .m file or just use Mathematica directly from ...
8
votes
1answer
938 views

View the FullForm of ^^

Why am I unable to see the FullForm of ^^ (the shorthand notation for BaseForm)? ...
4
votes
1answer
244 views

Parsing string with nested information

I am trying to parse a string, but I have no idea how to solve the following problem ...
0
votes
1answer
169 views

How to read a part of huge matrix saved in a TXT file as single expression?

I saved a huge matrix of numbers with dimensions {400, 4001, 2} using Put and got a TXT file formatted in the following way: <...