Skip to Content.
Sympa Menu

k-user - Re: [K-user] String format parsing question

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [K-user] String format parsing question


Chronological Thread 
  • From: Radu Mereuta <headness13 AT gmail.com>
  • To: Omar Duhaiby <3omarz AT gmail.com>
  • Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
  • Subject: Re: [K-user] String format parsing question
  • Date: Fri, 28 Mar 2014 14:43:38 -0500
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Hi Omar,

Actually the manual need updating.
The rule for String is something like this:
syntax String ::= Token{"\"" ((~[\"\n\r\\])|([\\]~[\n\r]))* "\""}

It starts and ends with double quotes, and it has zero or more elements of the form:
~[\"\n\r\\] => anything except for double quotes, new line or backslash, or
[\\]~[\n\r] => backslash followed by anything except new line.

This gives us a more general definition for strings. Different languages have different escaped characters. With this we capture them all.

If you want to allow only for some characters to be escaped, you can restrict the regular _expression_ to something like this:
[\\][nrft\"\\]
I think this is the complete list of characters that Java allow for.

Radu
K developer



On Fri, Mar 28, 2014 at 2:20 PM, Omar Duhaiby <3omarz AT gmail.com> wrote:

You want to change K's predefined the lexer rules for String. You should define your own String format, call it String2 for example. K defines String like this:

syntax #String ::= Lexer{"\"" (~[\"\\] | "\\\"" | "\\")* "\""}
                   // where '\' cannot be followed by double quote

I took this from the documentation/ref-manual.k file.

All you have to do is replace "\"" with [\"\']
of course you don't need the # before your String2


I haven't tested it but it should work


_______________________________________________
k-user mailing list
k-user AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/k-user





Archive powered by MHonArc 2.6.16.

Top of Page