Bug #1019

use of parameters in range checks

Added by planetmaker over 9 years ago. Updated over 9 years ago.

Status:ClosedStart date:2010-06-18
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:-
Target version:-

Description

In switch statements it's possible to use ranges:
switch(FEAT_RAILTYPES, SELF, depot_electric_year_switch_snow, years_since_0) {
0 .. 1964: depot_electric_rail_snow_group;
depot_modern_electric_rail_snow_group;
}

But when I parametrize the range, NML chokes on it:
switch(FEAT_RAILTYPES, SELF, depot_electric_year_switch_snow, years_since_0) {
0 .. param1: depot_electric_rail_snow_group;
depot_modern_electric_rail_snow_group;
}

gives

Error while parsing input file
Traceback (most recent call last):
File "/usr/local/bin/nml2nfo", line 7, in <module>
main.main(sys.argv[1:])
File "/Users/ingo/ottd/grfdev/nml/nml/main.py", line 82, in main
ret = nml(input, opts.debug, outputs, nml_output)
File "/Users/ingo/ottd/grfdev/nml/nml/main.py", line 101, in nml
result = nml_parser.parse(script)
File "/Users/ingo/ottd/grfdev/nml/nml/parser.py", line 14, in parse
return self.parser.parse(text, lexer = self.lexer.lexer)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ply/yacc.py", line 265, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ply/yacc.py", line 971, in parseopt_notrack
p.callable(pslice)
File "/Users/ingo/ottd/grfdev/nml/nml/parser.py", line 316, in p_switch_ranges
else: t0 = t1 + [action2var.SwitchRange(t2, t4, t6)]
File "/Users/ingo/ottd/grfdev/nml/nml/actions/action2var.py", line 192, in init
self.max = max.reduce_constant(global_constants.const_list)
File "/Users/ingo/ottd/grfdev/nml/nml/expression.py", line 57, in reduce_constant
raise generic.ConstError()
nml.generic.ConstError: 'Expected a compile-time constant'

paramswitch.diff Magnifier (1.88 KB) planetmaker, 2010-06-18 09:39

Associated revisions

Revision 368:fd3a0347d1ed
Added by yexo over 9 years ago

Feature (closes #1019): use of non-constant expression in switch ranges / results

Revision 368:fd3a0347d1ed
Added by yexo over 9 years ago

Feature (closes #1019): use of non-constant expression in switch ranges / results

History

#1 Updated by planetmaker over 9 years ago

If it helps: here a diff to check this for with SwedishRails. You might need to edit the graphics file names of the depots to src/gfx/depot_rail.png

#2 Updated by yexo over 9 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset fd3a0347d1ed.

Also available in: Atom PDF