9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] equality sign in Rc
Date: Sun, 14 May 2017 15:31:31 -0700	[thread overview]
Message-ID: <e5638d7b51cbc62a5f47c6e14f6eec41@lilly.quanstro.net> (raw)
In-Reply-To: <5053931494776177@web35j.yandex.ru>

On Sun May 14 08:32:47 PDT 2017, trebol55555@yandex.ru wrote:
>  > That isn't sh's rule. x=y is fine as an assignment without spaces.
>
> Yes, sorry, in fact I was thinking on the contrary I wrote: don't set a variable like in sh.
>
> I like the use of spaces permitted in rc, as I said.

i was about to make this correction myself.  in any event, this is a sloppy but effective pure extension
to the grammar that allows everything but the first word to contain an '='.

since this is done at the grammar level, and not as one would expect at the lexer level, there are some
surprises like a function with "echo x=1" will deparse as echo 'x='^1.  not perfect, but workable

here's the code change

../rc/syn.y:24,35 - syn.y:24,47
  	return !i;
  }

+ tree*
+ treeeq(int type, tree *c0, tree *c1)
+ {
+ 	char *old;
+
+ 	old = c0->str;
+ 	c0->str = smprint("%s=", c0->str);
+ 	c0->quoted = 1;
+ 	free(old);
+ 	return tree2(type, c0, c1);
+ }
+
  %}
  %union{
  	struct tree *tree;
  };
  %type<tree> line paren brace body cmdsa cmdsan assign epilog redir
- %type<tree> cmd simple first word nkword comword keyword nkwords words wordsnl
+ %type<tree> cmd simple first nexteq word nkword comword keyword nkwords words wordsnl
  %type<tree> NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN BREAK
  %type<tree> WORD REDIR DUP PIPE
  %%
../rc.me5/syn.y:84,89 - syn.y:96,102
  |	FN nkwords brace		{$$=tree2(FN, $2, $3);}
  |	FN nkwords		{$$=tree1(FN, $2);}
  simple:	first
+ |	simple nexteq		{$$=tree2(ARGLIST, $1, $2);}
  |	simple word		{$$=tree2(ARGLIST, $1, $2);}
  |	simple redir		{$$=tree2(ARGLIST, $1, $2);}
  first:	comword
../rc.me5/syn.y:111,113 - syn.y:124,127
  |	words word		{$$=tree2(WORDS, $1, $2);}
  nkwords:				{$$=(struct tree*)0;}
  |	nkwords nkword		{$$=tree2(WORDS, $1, $2);}
+ nexteq:	word '=' word		{$$=treeeq('^', $1, $3);}

here are some test cases

; ./o.rc
broken! x=1 echo $x
1
broken! whatis zot
zot: not found
broken! zot=1 echo $zot
1
broken! whatis one
one: not found
broken! one=1 two=2 echo $one $two
1 2
broken! echo one=1
one=1
broken! echo if=1
if=1
broken! fn eq {echo one=1 two=2}
broken! eq
one=1 two=2

- erik



  reply	other threads:[~2017-05-14 22:31 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-13 12:36 trebol
2017-05-13 13:42 ` Charles Forsyth
2017-05-13 14:21   ` trebol
2017-05-13 16:53     ` Charles Forsyth
2017-05-13 22:41       ` Bruce Ellis
2017-05-14  9:56 ` Charles Forsyth
2017-05-14 15:36   ` trebol
2017-05-14 22:31     ` erik quanstrom [this message]
2017-05-15  8:58       ` Charles Forsyth
2017-05-15 11:48         ` trebol
2017-05-15 11:54           ` Charles Forsyth
2017-05-15 11:55             ` Charles Forsyth
2017-05-15 11:56             ` Charles Forsyth
2017-05-15 15:37               ` Erik Quanstrom
2017-05-15 15:42                 ` Charles Forsyth
2017-05-15 15:54                   ` Erik Quanstrom
2017-05-15 15:59                     ` Charles Forsyth
2017-05-15 16:30                       ` Giacomo Tesio
2017-05-15 16:36                         ` Charles Forsyth
2017-05-15 18:25                           ` Giacomo Tesio
2017-05-15 16:43                         ` trebol
2017-05-15 18:33                           ` trebol
2017-05-15 21:06                             ` Charles Forsyth
2017-05-15 21:48                               ` trebol
2017-05-15 23:38                                 ` trebol
2017-05-15 23:59                                   ` trebol
2017-05-14 22:36     ` trebol
2017-05-14 22:38 ` erik quanstrom
2017-05-15 11:35   ` hiro
2017-05-15 11:45     ` trebol
  -- strict thread matches above, loose matches on Subject: below --
2017-05-15 19:32 sl
2017-05-15 20:15 ` Erik Quanstrom
2017-05-16 17:11 ` Kurt H Maier
2017-05-16 18:27   ` hiro
2017-05-16 18:40   ` Giacomo
2017-05-15 16:44 trebol
2017-05-15 21:02 ` Charles Forsyth
2017-05-16  9:24 ` Charles Forsyth
2017-05-16 15:59   ` Erik Quanstrom
2017-05-16 17:07     ` Giacomo Tesio
2017-05-01 19:27 dexen deVries
2017-05-06  1:53 ` tty0
2017-05-06  7:43   ` Sean Callanan
2017-05-06 13:20     ` Steve Simon
2017-05-06 19:09       ` Sean Callanan
2017-05-06 20:14     ` Nick Owens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e5638d7b51cbc62a5f47c6e14f6eec41@lilly.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).