Jane's Units Syntax

Note: Syntax is not "units" specific

Unit Syntax

	blanks 		AND (with a white space)
	comma		OR
	(syntax-name)	run a sub-syntax
	{ }		optional
	[ ]		1 or more
	| |		look only
	!		not
	`		partial word match
	:		alias (first one is the result value)
	/		added name=value or value to result
	%any		any word
	%number		any number format (integer 123, binary - 0b0111, hex - 0xFF, octal 0o77, decimals 1.45, scientific 3.02E23, English - twenty three,...)
	%alpha 		A word starting with an Alpha
	%variable 	A run time valuable value
	%exit		Fail and exit the complete syntax
	example 1:  eagle = 1 foot per second per pound is speed of eagle while diving or 0.85 when in normal flight;
	result is an object with a value of 1;
	eagle = { 	text		:'1 foot per second per pound as speed of eagle',
			is		: 'speed', 
			of		: 'eagle',
			si_base_units	: 'MKS',
			when		: [	{name: 'diving', value: 1},
						{name: 'in normal flight', value: 0.85}],	
			per		: [	{Length: {name:'feet', scale: 0.3048}},  	// base units meters
						{Time: {name: 'seconds', scale: 1}},		// base unit seconds
						{Weight: {name: 'pound', scale: 0.453592] }] };	// base units kilograms
	A = speed of eagle while diving in km per hour per ounce * 3.57 hours * 5 pounds;

	1. create a known structure
	2. set a base unit (all syntax table values based on a given unit)
	3. globally change base units (Standard or Metric)
	4. standardize field names (rename "while" to "when")
	5. standardize unit names (plural / singular sensitive)
	6. permit multiple conditions (or when in normal flight)
	7. rename syntax field names ("Standard_length" to "length")
---------------------------------- Jane Units Syntax (not finished)--------------------------------------------------------

//			Units language Function 
language function '# !|%alpha|, (units)'()
	if (!this.units) return null;
	this.units.text = this.text;
	return this.units;
	event onSuccessfulSyntax(syntaxName,text,name,value,index)
		if (this.units) this.units = {si_base_units:'MKS'};	
		switch (name)
		case               'units':
		case           'per_units':
		case          'units_kind':
		case  'units_user_defined':
		case              'Metric':
		case   'Metric_scale_word':
		case    'metric_type_word':
		case 'Metric_scale_symbol':
		case  'metric_type_symbol':
		case      'Dimensions_pre':
		case     'Dimensions_post':
		case         'Standard_US':
		case  'Standard_US_length':
		case     'electromagnetic':
		case          'mechanical':
		case       'radioactivity':
		case               'angle':
		case           'tempature':
		case                'Time':

Syntax(units) 			= '{per} (units_kind) {[(per_units)]}';
Syntax(per_units) 		= 'per (units_kind)';			// per second per meter per pound ...

Syntax(units_kind/required) 	= '(Time), (Standard_US), (Metric), (Temperatue), (Angle), (CGS), (MKS), (MTS), (MKSA), (Units_User_defined)';
Syntax(units_user_defined)	= '[%fail]';				// an array of words, place holder, application can override

Syntax(Metric)			= '(Metric_scale_word) (metric_type_word), (Metric_scale_symbol) (metric_type_symbol) ';

Syntax(Metric_scale_word)	= '`yotta/10**24,`zetta/10**21,`exa/10**18,`peta/10**15,`tera/10**12,`giga/10**9,`meta/10**6,`kilo/10**3,`hecto/10**2,`deka/10**1,`deci/10**0-1,`centi/10**-2,`milli/10**-3,`mikro/10**-6,`nano/10**-9,`piko/10**-12,`femto/10**-15,`atto/10**-18,`zepto/10**-21/,`yocto/10**-24';
Syntax(metric_type_word)	= 'meter:meters,gram:grams,second:seconds,gal,dyne,barye,erg,poise,byte:bytes,(electromagnetic),(mechanical)';

Syntax(Metric_scale_symbol)	= '`Y/yotta=10**24,`Z/zetta=10**21,`E/exa=10**18,`P/peta=10**15,`T/10**12,`G/10**9,`M/10**6,`k/10**3,`h/10**2,`da/10**1,`d/10**0-1,`c:10**-2,`m/10**3,`/10**-6,`n/10**-9,`p/10**-12,`f/10**-15,`a/10**-18,`z/10**-21,`y/10**-24';
Syntax(metric_type_symbol)	= 'm,g,s,Gal,dyn,Ba,erg,P,B';

Syntax(Dimensions_pre)		= 'square,cubic';
Syntax(Dimensions_post)		= '^ %number';
Syntax(Standard_US) 		= '(dimension_pre) (standard_US_length), (standard_US_length) (dimensions_post), (standard_US_length), (standard_US_volume_liquid), (standard_US_weight)';
Syntax(Standard_US_length) 	= 'feet:ft:foot:\'/1, inches:inch:in:"/0.08333333333333333, yard:yards/36, mile:miles/4280';	// base unit = feet

Syntax(electromagnetic)		= 'volt,ohm,tesla,weber,farad,henry,siemens,coulomb';
Syntax(mechanical)		= 'watt:watts,newton:newtons,joule:joules,pascal:pascals';
Syntax(radioactivity)		= 'becquerel:becquerels,sievert;sieverts,gray:grays,lux:luxes,lumen:lumens';
Syntax(angle)			= 'degree:degrees,radian:radians,steradian:sterdians';
Syntax(tempature)		= 'fahrenheit:F,celsius:centigrade:C';

Syntax(Time)	 		= 'second:seconds/1, minute:minutes/60, hour:hours/3600, day:days/86400, week:weeks/604800, month:months/30.4167*86400, quarter:quarters/30.4167*86400*4, year:years\365.2425*';
Syntax(TimePeriod)		= 'years:year,decade:decades/10,centry:centries/100,millennia:millennias/1000';