Misc #20035
closedCommand-line settings move from parser to compiler
Description
Right now, when you pass -n
, -p
, -l
, or -a
, these options are all passed to the parser to manipulate the parse tree into giving you the desired behavior. For example:
$ ruby --dump=parsetree -p -e "foo"
###########################################################
## Do NOT use this node dump for any purpose other than ##
## debug and research. Compatibility is not guaranteed. ##
###########################################################
# @ NODE_SCOPE (id: 1, line: 1, location: (1,0)-(1,3))
# +- nd_tbl: (empty)
# +- nd_args:
# | (null node)
# +- nd_body:
# @ NODE_WHILE (id: 10, line: 1, location: (1,0)-(1,0))
# +- nd_state: 1 (while-end)
# +- nd_cond:
# | @ NODE_FCALL (id: 9, line: 1, location: (1,0)-(1,0))
# | +- nd_mid: :gets
# | +- nd_args:
# | @ NODE_LIST (id: 8, line: 1, location: (1,0)-(1,0))
# | +- nd_alen: 1
# | +- nd_head:
# | | @ NODE_GVAR (id: 7, line: 1, location: (1,0)-(1,0))
# | | +- nd_entry: :$/
# | +- nd_next:
# | (null node)
# +- nd_body:
# @ NODE_BLOCK (id: 5, line: 1, location: (1,0)-(1,0))
# +- nd_head (1):
# | @ NODE_VCALL (id: 0, line: 1, location: (1,0)-(1,3))*
# | +- nd_mid: :foo
# +- nd_head (2):
# @ NODE_FCALL (id: 4, line: 1, location: (1,0)-(1,0))
# +- nd_mid: :print
# +- nd_args:
# @ NODE_LIST (id: 3, line: 1, location: (1,0)-(1,0))
# +- nd_alen: 1
# +- nd_head:
# | @ NODE_GVAR (id: 2, line: 1, location: (1,0)-(1,0))
# | +- nd_entry: :$_
# +- nd_next:
# (null node)
Could this mutation be moved into the compiler? That way it could be shared by prism, but also because it would make it less confusing when people are running --dump=parsetree
as to why a loop is being inserted.
Updated by nobu (Nobuyoshi Nakada) over 1 year ago
Moving -n
/-p
makes impossible to check break
/next
/redo
in parser.
$ ruby -c -p -e break < /dev/null
Syntax OK
$ ruby -c -e break < /dev/null
-e:1: Invalid break
break
-e: compile error (SyntaxError)
Updated by kddnewton (Kevin Newton) over 1 year ago
I assume in this case that you would still pass the settings into the parser so that it could be aware of it. In looking at parse.y, I think this would amount to calling allow_block_exit
at the start.
Updated by nobu (Nobuyoshi Nakada) over 1 year ago
Do you mean passing these to both of the parser and the compiler?
Updated by kddnewton (Kevin Newton) over 1 year ago
I don't think you would have to pass all of the options, I think the only thing you would need to pass is "this is inside a while loop" in order to set up allow_block_exit
properly.
Updated by kddnewton (Kevin Newton) about 1 year ago
- Status changed from Open to Closed