1. Is there a way of reading a sequence from a variable?

What I am looking for is a function like get() which works on a variable not a file.

Value() will not read quoted text from a sequence only numbers and sequences of numbers.

Get() only works on files.

new topic     » topic index » view message » categorize

2. Re: Is there a way of reading a sequence from a variable?

bill said...

What I am looking for is a function like get() which works on a variable not a file.

Value() will not read quoted text from a sequence only numbers and sequences of numbers.

Get() only works on files.

I'm not sure what you are doing but value() works correctly with quoted text. Can you give us an example of where it is failing? Here is what I tried ...

include std/get.e 
? value("{0,\"123\",1,2,{3,\"AAA\"},\"456\"}") 

And the result was

{ 
  0, 
  { 
    0, 
    {49,50,51}, 
    1, 
    2, 
    { 
      3, 
      {65,65,65} 
    }, 
    {52,53,54} 
  } 

new topic     » goto parent     » topic index » view message » categorize

3. Re: Is there a way of reading a sequence from a variable?

What I want to read is any Eu object - eg "\"Hello\"".

That is given something like:

"\"alpha\" = 3.456"

I can read out "alpha",
drop the white space
see I've got '=',
drop it and any white space following,
then read out the value (which culd be any Eu object),
checking at the end I've consumed the whole string.

Sort of get() for strings, or
Poor man's parsing.

Thanks

new topic     » goto parent     » topic index » view message » categorize

4. Re: Is there a way of reading a sequence from a variable?

bill said...

What I want to read is any Eu object - eg "\"Hello\"".

That is given something like:

"\"alpha\" = 3.456"

I can read out "alpha",
drop the white space
see I've got '=',
drop it and any white space following,
then read out the value (which culd be any Eu object),
checking at the end I've consumed the whole string.

Sort of get() for strings, or
Poor man's parsing.

Thanks

You can do that with value().

Something like this:

integer pos = 1 
sequence s 
sequence objects = {} 
while pos <= length("\"alpha\" = 3.456") do  
s = value("\"alpha\" = 3.456", pos, GET_LONG_ANSWER) 
objects &= s[2] 
pos += s[3] 
end while 
new topic     » goto parent     » topic index » view message » categorize

5. Re: Is there a way of reading a sequence from a variable?

bill said...

What I want to read is any Eu object - eg "\"Hello\"".

That is given something like:

"\"alpha\" = 3.456"

I can read out "alpha",
drop the white space
see I've got '=',
drop it and any white space following,
then read out the value (which culd be any Eu object),
checking at the end I've consumed the whole string.

Sort of get() for strings, or
Poor man's parsing.

Thanks

I see, so it's not that value() can't do quoted strings, but that you want to parse a string, one 'token' at a time.

There are a number of ways to do this. Jim has mentioned one way with using GET_LONG_ANSWER and value().

You could also use the keyvalues() function found in std/text.e or the split() function found in std/sequence.e

include std/text.e 
sequence text =  "\"alpha\" = 3.456" 
sequence result 
 
result = keyvalues(text) 

gives ...

{{"alpha","3.456"}} 
Which is a lot easier to parse now.

Or using split() ...

include std/sequence.e 
sequence text =  "\"alpha\" = 3.456" 
sequence result 
 
result = split(text,,1) 
 

which gives ...

{"\"alpha\"","=","3.456"} 
which is also easy to parse now.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Is there a way of reading a sequence from a variable?

Derek and Jim,

Thank you,

It's more complicated than the simple example so splitting will not work. (What if ' ' appears in a string for example.) Also, the text may not be well-formed Euphoria code.

In any case I can verify both key and value with value() and GET_LONG_ANSWER. I had intended doing this but was misled by the documentation.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu