Getting text into another text

0

I want to get a List(Of String) of text blocks, however there is a problem:

{ --isso é um bloco;
  echo "Aqui tem um } no meio";}

And I would like to get this:

--isso é um bloco;
echo "Aqui tem um } no meio";

but it's coming back to my method:

--isso é um bloco;
echo "Aqui tem um 

And just over there, is there any way you can get multiple blocks except when they are within the "..." characters?

Here is my method code:

Dim tmpBlocks() As String = theFile.Split({"{"}, StringSplitOptions.RemoveEmptyEntries)
Dim Blocks As New List(Of String)

For i As Integer = 0 To tmpBlocks.Length - 1
    Blocks.Add(tmpBlocks(i).Split(New [String]() {"}"}, 
    StringSplitOptions.RemoveEmptyEntries)(0))
Next

' Blocks é a variável de cara bloco

Regex and Regular Expressions     

asked by anonymous 16.06.2015 / 00:22

1 answer

2

Without knowing the grammar specification of your programming language, it is difficult to solve the general case - you should consider seriously stop everything you are doing, pick up a book of compilers, a book of formal languages and automata, and after of having studied both topics, studying a type library ANTLR , which generates parsers for C # and Java.

If you absolutely insist on writing a compiler without studying the theory behind it, the first thing you need to know is that your language is not regular, but #, and therefore can not be processed by regular expressions (Google has a lot of information if you want to study the subject).

You'll need to do something in that line from here if you make a point of writing the code on the line (and note that I did not deal with leaks inside of strings, {} within {}, ...).

    
16.06.2015 / 00:55