BBx-Kitchen / bbj-language-server

BBj Language Server
MIT License
7 stars 6 forks source link

DIM of an Array but also a Templated String #51

Closed StephanWald closed 1 year ago

StephanWald commented 1 year ago
dim rd_open_tables$[1:rd_num_files],rd_open_opts$[1:rd_num_files],rd_open_chans$[1:rd_num_files],rd_open_tpls$[1:rd_num_files]

https://documentation.basis.cloud/BASISHelp/WebHelp/commands/dim_verb.htm https://documentation.basis.cloud/BASISHelp/WebHelp/commands/bbj-commands/dim_verb_bbj.htm

and for templated strings:

X$="STRING:C(6)"
DIM A$:X$
REDIM A$

https://documentation.basis.cloud/BASISHelp/WebHelp/usr/BBj_Enhancements/string_templates_bbj.htm

dhuebner commented 1 year ago

Difficult to estimate. Needs grammar changes that also affects string template syntax which is currently not good supported. Needs a good test coverage.

StephanWald commented 1 year ago

The following sample tries to give examples for all combinations. It seems like in the current version, only the DIM for a String with round parentheses is a problem:

REM numeric arrays

REM square brackets with one or multiple dimensions
DIM Y1[22]
DIM Y2[10,10,20]

REM same with Strings arrays:
DIM Y1$[22]
DIM Y2$[10,10,20]

REM now this is pre-sizing a String with length 20
DIM Z1$(20)

REM same, initialize it with dots
DIM Z2$(10,".")

REM now the combination: a String array of pre-dimensioned strings:
DIM Y3$[22](20)
DIM Y4$[10,10,20](30,".")

REM object arrays
DIM X![20]
DIM X![20,10,4]

REM Java arrays:
REM https://documentation.basis.cloud/BASISHelp/WebHelp/gridctrl/Working_with_Java_Arrays.htm

use java.awt.Color
use java.lang.reflect.Array

colorx! = Array.newInstance(Class.forName("java.awt.Color"),2) 
Array.set(colorx!,0,Color.RED)
Array.set(colorx!,1,Color.BLUE)
print "colorx![0]=",Array.get(colorx!,0)
print "colorx![1]=",Array.get(colorx!,1)

declare Color[] Color!
color! = new Color[2]
color![0] = Color.RED
color![1] = Color.BLUE
print "color![0]=",color![0]
print "color![1]=",color![1]

REM String Templates

tpl$="NAME:C(25*),FIRSTNAME:C(25*),SCORE:N(4)"
DIM rec$:tpl$
rec.name$="Wallace"
rec.firstname$="Marcellus"
rec.score=2.3
print rec.name$,": ",rec.score
dhuebner commented 1 year ago

Todo:

dhuebner commented 1 year ago

@StephanWald Your example is now completely supported. Please open a new issue if something is still missing.