Beispiel #1
0
static int
parsenumber(Parser *p, JSON *parent, JSON **prev)
{
	char c;
	JSON *v = inititem(p, parent, prev, '0');
	if (*p->s == '-') {
		p->s++;
	}
	c = *p->s;
	if ('0' <= c && c <= '9') {
		p->s++;
		if (c != '0') {
			scandigits(p);
		}
	} else {
		return 0;
	}
	if (*p->s == '.') {
		p->s++;
		must('0' <= *p->s && *p->s <= '9');
		scandigits(p);
	}
	if (*p->s == 'e' || *p->s == 'E') {
		p->s++;
		if (*p->s == '+' || *p->s == '-') {
			p->s++;
		}
		must('0' <= *p->s && *p->s <= '9');
		scandigits(p);
	}
	if (v) {
		v->end = p->s;
	}
	return 1;
}
Beispiel #2
0
static int
parsestring(Parser *p, JSON *parent, JSON **prev)
{
	JSON *v = inititem(p, parent, prev, '"');
	p->s++; // consume "
	while (*p->s != '"') {
		char c = *p->s;
		must(c >= ' '); // no control chars
		p->s++;
		if (c == '\\') {
			switch (c = *p->s++) {
			case 'b': case 'f': case 'n': case 'r':
			case 't': case '"': case '\\': case '/':
				continue;
			case 'u':
				must(scanhex4(p));
				continue;
			}
			return 0;
		}
	}
	p->s++; // consume "
	if (v) {
		v->end = p->s;
	}
	return 1;
}
Beispiel #3
0
Result validate_named_entity(const base::NamedEntity<T> &named_entity) {
    Result result_base = validate_entity<T>(named_entity);
    Result result = validator({
        must(named_entity, &base::NamedEntity<T>::name, notEmpty(), "no name set!"),
        must(named_entity, &base::NamedEntity<T>::type, notEmpty(), "no type set!")
    });

    return result.concat(result_base);
}
Beispiel #4
0
Result validate(const Feature &feature) {
    Result result_base = validate_entity(feature);
    Result result = validator({
        must(feature, &Feature::data, notFalse(), "data is not set!"),
        must(feature, &Feature::linkType, notSmaller(0), "linkType is not set!")
    });

    return result.concat(result_base);
}
Beispiel #5
0
Result validate(const RangeDimension &range_dim) {
    return validator({
        must(range_dim, &RangeDimension::index, notSmaller(1), "index is not set to valid value (size_t > 0)!"),
        must(range_dim, &RangeDimension::ticks, notEmpty(), "ticks are not set!"),
        must(range_dim, &RangeDimension::dimensionType, isEqual<DimensionType>(DimensionType::Range), "dimension type is not correct!"),
        could(range_dim, &RangeDimension::unit, notFalse(), {
            must(range_dim, &RangeDimension::unit, isAtomicUnit(), "Unit is set but not an atomic SI. Note: So far composite units are not supported!") }),
        must(range_dim, &RangeDimension::ticks, isSorted(), "Ticks are not sorted!")
    });
}
Beispiel #6
0
Result validate(const SampledDimension &sampled_dim) {
    return validator({
        must(sampled_dim, &SampledDimension::index, notSmaller(1), "index is not set to valid value (size_t > 0)!"),
        must(sampled_dim, &SampledDimension::samplingInterval, isGreater(0), "samplingInterval is not set to valid value (> 0)!"),
        must(sampled_dim, &SampledDimension::dimensionType, isEqual<DimensionType>(DimensionType::Sample), "dimension type is not correct!"),
        could(sampled_dim, &SampledDimension::offset, notFalse(), {
            should(sampled_dim, &SampledDimension::unit, isAtomicUnit(), "offset is set, but no valid unit set!") }),
        could(sampled_dim, &SampledDimension::unit, notFalse(), {
            must(sampled_dim, &SampledDimension::unit, isAtomicUnit(), "Unit is set but not an atomic SI. Note: So far composite units are not supported!") })
    });
}
Beispiel #7
0
static int
parsepair(Parser *p, JSON *parent, JSON **kprev, JSON **vprev)
{
	must(*p->s == '"');
	must(parsestring(p, parent, kprev));
	skipws(p);
	must(consume(p, ":"));
	skipws(p);
	must(parsevalue(p, parent, vprev));
	return 1;
}
Beispiel #8
0
static void
derived_type (void)
{
  tab (1, "DERIVED TYPE");

  while (1)
    {
      if (opt (IT_dpp_CODE))
	{
	  dump_symbol_info ();
	  must (IT_dpp_CODE);
	}
      else if (opt (IT_dfp_CODE))
	{
	  dump_symbol_info ();
	  must (IT_dfp_CODE);
	}
      else if (opt (IT_den_CODE))
	{
	  dump_symbol_info ();
	  must (IT_den_CODE);
	}
      else if (opt (IT_den_CODE))
	{
	  dump_symbol_info ();
	  must (IT_den_CODE);
	}
      else if (opt (IT_dds_CODE))
	{
	  dump_symbol_info ();
	  must (IT_dds_CODE);
	}
      else if (opt (IT_dar_CODE))
	{
	}
      else if (opt (IT_dpt_CODE))
	{
	}
      else if (opt (IT_dul_CODE))
	{
	}
      else if (opt (IT_dse_CODE))
	{
	}
      else if (opt (IT_dot_CODE))
	{
	}
      else
	break;
    }

  tab (-1, "");
}
Beispiel #9
0
Result validate(const Property &property) {
    Result result_base = validate_entity(property);
    Result result = validator({
        must(property, &Property::name, notEmpty(), "name is not set!"),
        could(property, &Property::valueCount, notFalse(), {
            should(property, &Property::unit, notFalse(), "values are set, but unit is missing!") }),
        could(property, &Property::unit, notFalse(), {
            must(property, &Property::unit, isValidUnit(), "Unit is not SI or composite of SI units.") })
        // TODO: dataType to be tested too?
    });

    return result.concat(result_base);
}
Beispiel #10
0
	// returns true if satisfiable, false otherwise
	// on completion, val[x] is the assigned value of variable x
	// note, val[x] = 0 implies val[x^1] = 1
	bool two_sat() {
		scnt = 0;
		for (int i = 0; i < n; i++) {
			dfs1(i);
		}
		while (!stk.empty()) {
			int v = stk.top(); stk.pop();
			if (vis[v]) {
				scc.push_back(vector<int>());
				dfs2(v);
				scnt++;
			}
		}
		for (int i = 0; i < n; i += 2) {
			if (sid[i] == sid[i+1]) return false;
		}
		vector<int> must(scnt);
		for (int i = 0; i < scnt; i++) {
			for (int j = 0; j < scc[i].size(); j++) {
				val[scc[i][j]] = must[i];
				must[sid[scc[i][j]^1]] = !must[i];
			}
		}
		return true;
	}
Beispiel #11
0
static void
dump_symbol_info (void)
{
  tab (1, "SYMBOL INFO");

  while (opt (IT_dsy_CODE))
    {
      if (opt (IT_dty_CODE))
	{
	  must (IT_dbt_CODE);
	  derived_type ();
	  must (IT_dty_CODE);
	}
    }

  tab (-1, "");
}
Beispiel #12
0
Result validate(const DataArray &data_array) {
    Result result_base = validate_entity_with_sources(data_array);
    Result result = validator({
        must(data_array, &DataArray::dataType, notEqual<DataType>(DataType::Nothing), "data type is not set!"),
        must(data_array, &DataArray::dimensionCount, isEqual<size_t>(data_array.dataExtent().size()), "data dimensionality does not match number of defined dimensions!", {
            could(data_array, &DataArray::dimensions, notEmpty(), {
                must(data_array, &DataArray::dimensions, dimTicksMatchData(data_array), "in some of the Range dimensions the number of ticks differs from the number of data entries along the corresponding data dimension!"),
                must(data_array, &DataArray::dimensions, dimLabelsMatchData(data_array), "in some of the Set dimensions the number of labels differs from the number of data entries along the corresponding data dimension!") }) }),
        could(data_array, &DataArray::unit, notFalse(), {
            should(data_array, &DataArray::unit, isValidUnit(), "Unit is not SI or composite of SI units.") }),
        could(data_array, &DataArray::polynomCoefficients, notEmpty(), {
            should(data_array, &DataArray::expansionOrigin, notFalse(), "polynomial coefficients for calibration are set, but expansion origin is missing!") }),
        could(data_array, &DataArray::expansionOrigin, notFalse(), {
            should(data_array, &DataArray::polynomCoefficients, notEmpty(), "expansion origin for calibration is set, but polynomial coefficients are missing!") })
    });

    return result.concat(result_base);
}
Beispiel #13
0
Result validate(const File &file) {
    return validator({
        could(file, &File::isOpen, notFalse(), {
            must(file, &File::createdAt, notFalse(), "date is not set!"),
            should(file, &File::version, notEmpty(), "version is not set!"),
            should(file, &File::format, notEmpty(), "format is not set!"),
            should(file, &File::location, notEmpty(), "location is not set!") })
    });
}
Beispiel #14
0
static int
scanhex4(Parser *p)
{
	for (int i = 0; i < 4; i++) {
		char c = *p->s++;
		must(('0'<=c && c<='9') || ('a'<=c && c<='f') || ('A'<=c && c<='F'));
	}
	return 1;
}
Beispiel #15
0
/* a bit naughty; take the TOS and do an indirection on it,
	directly accessing ev++ for the .w/b/l */
word do_indirection(void)
{
ulong ind;
long result;
char *p,s;
word err;
bool got;

	if (topitem==botitem)
		return ERRE_ITEMUNDERFLOW;
	must(coerce_type(--topitem,EXPR_LONG,&ind));	/* pops it */
	p=ev;
	got=FALSE;
	if (*p++=='.')
		{
		s=upper(*p++);
		if (s=='B')
			{
			result=peekb(ind);
			if (upper(*p)==s)
				{
				p++;
				result=(signed char)result;
				}
			ev=p; got=TRUE;
			}
		else if (s=='W')
			{
			if (checking)
				result=0;
			else
				{
				must(safe_peekw(ind,(uword*)&result));
				result>>=16;
				}
			if (upper(*p)==s)
				{
				p++;
				result=(word)result;
				}
			ev=p; got=TRUE;
			}
		else if (s=='L')
Beispiel #16
0
static int
parsenull(Parser *p, JSON *parent, JSON **prev)
{
	JSON *v = inititem(p, parent, prev, 'n');
	must(consume(p, "null"));
	if (v) {
		v->end = p->s;
	}
	return 1;
}
Beispiel #17
0
static int
parsetrue(Parser *p, JSON *parent, JSON **prev)
{
	JSON *v = inititem(p, parent, prev, 't');
	must(consume(p, "true"));
	if (v) {
		v->end = p->s;
	}
	return 1;
}
Beispiel #18
0
static int
consume(Parser *p, char *s)
{
	while (*s) {
		must(*p->s == *s);
		p->s++;
		s++;
	}
	return 1;
}
Beispiel #19
0
// Scans src and writes pointers to the lexical bounds of JSON values
// to elements of part.
//
// Returns the total number of values in src, regardless of npart.
// If src is not well-formed JSON, returns 0.
int
jsonparse(char *src, JSON *part, int npart)
{
	Parser p = {};
	p.s = src;
	p.j = part;
	p.nj = npart;
	skipws(&p);
	must(parsetext(&p));
	skipws(&p);
	must(*p.s == '\0');
	if (part) {
		if (p.n < npart) {
			npart = p.n;
		}
		for (int i = 0; i < npart; i++) {
			part[i].len = part[i].end - part[i].src;
		}
	}
	return p.n;
}
Beispiel #20
0
static int
parsearray(Parser *p, JSON *parent, JSON **prev)
{
	JSON *v = inititem(p, parent, prev, '[');
	must(consume(p, "["));
	skipws(p);
	if (*p->s != ']') {
		JSON *aprev = nil;
		must(parsevalue(p, v, &aprev));
		for (skipws(p); *p->s == ','; skipws(p)) {
			p->s++; // consume ,
			skipws(p);
			must(parsevalue(p, v, &aprev));
		}
	}
	must(consume(p, "]"));
	if (v) {
		v->end = p->s;
	}
	return 1;
}
Beispiel #21
0
static int
parseobject(Parser *p, JSON *parent, JSON **prev)
{
	JSON *kprev = nil, *vprev = nil;
	JSON *v = inititem(p, parent, prev, '{');
	must(consume(p, "{"));
	skipws(p);
	if (*p->s != '}') {
		must(parsepair(p, v, &kprev, &vprev));
		for (skipws(p); *p->s == ','; skipws(p)) {
			p->s++; // consume ,
			skipws(p);
			must(parsepair(p, v, &kprev, &vprev));
		}
	}
	must(consume(p, "}"));
	if (v) {
		v->end = p->s;
	}
	return 1;
}
Beispiel #22
0
CFSWString palat_vru (CFSWString s) {
    CFSWString res;
    bool m = false;
    if (s == L"är'") res = L"ärq"; 
    else
    if (s == L"ar'") res = L"arq"; 
    else
    if (s == L"jäl'") res = L"jälq"; 
    else
    if (s == L"jal'") res = L"jalq"; 
    else
    if (s == L"kül'") res = L"külq"; 
    else
    if (s == L"pan'") res = L"panq"; 
    else
    if (s == L"tul'") res = L"tulq"; 
    else
    if (s == L"ol'") res = L"olq"; 
    else
        for (INTPTR i = s.GetLength()-1; i >= 0; i--) {
        CFSWString c = s.GetAt(i);
        if (c == L"'") {
            m = true;
        } else 
            if (must(c)) {
                res = c + res;
                m = true;
            }
            else
        if (m) {
            if (can_palat_vr(c)) {
                c = c.ToUpper();
                res = c + res;
            } else {
                res = c + res;
                m = false;
            }
        } else {
            res = c + res;
        }
        
       
    }    
    return res;
}
Beispiel #23
0
Result validate(const Tag &tag) {
    Result result_base = validate_entity_with_sources(tag);
    Result result = validator({
        must(tag, &Tag::position, notEmpty(), "position is not set!"),
        could(tag, &Tag::references, notEmpty(), {
            must(tag, &Tag::position, positionsMatchRefs(tag.references()),
                "number of entries in position does not match number of dimensions in all referenced DataArrays!"),
            could(tag, &Tag::extent, notEmpty(), {
                must(tag, &Tag::position, extentsMatchPositions(tag.extent()), "Number of entries in position and extent do not match!"),
                must(tag, &Tag::extent, extentsMatchRefs(tag.references()),
                    "number of entries in extent does not match number of dimensions in all referenced DataArrays!") })
        }),
        // check units for validity
        could(tag, &Tag::units, notEmpty(), {
            must(tag, &Tag::units, isValidUnit(), "Unit is invalid: not an atomic SI. Note: So far composite units are not supported!"),
            must(tag, &Tag::references, tagRefsHaveUnits(tag.units()), "Some of the referenced DataArrays' dimensions don't have units where the tag has. Make sure that all references have the same number of dimensions as the tag has units and that each dimension has a unit set."),
                must(tag, &Tag::references, tagUnitsMatchRefsUnits(tag.units()), "Some of the referenced DataArrays' dimensions have units that are not convertible to the units set in tag. Note: So far composite SI units are not supported!")}),
    });

    return result.concat(result_base);
}
Beispiel #24
0
Result validate(const MultiTag &multi_tag) {
    Result result_base = validate_entity_with_sources(multi_tag);
    Result result = validator({
        must(multi_tag, &MultiTag::positions, notFalse(), "positions are not set!"),
        // check units for validity
        could(multi_tag, &MultiTag::units, notEmpty(), {
            must(multi_tag, &MultiTag::units, isValidUnit(), "Some of the units in tag are invalid: not an atomic SI. Note: So far composite SI units are not supported!"),
            must(multi_tag, &MultiTag::references, tagUnitsMatchRefsUnits(multi_tag.units()), "Some of the referenced DataArrays' dimensions have units that are not convertible to the units set in tag. Note: So far composite SI units are not supported!")}),
        // check positions & extents
        could(multi_tag, &MultiTag::extents, notFalse(), {
            must(multi_tag, &MultiTag::positions, extentsMatchPositions(multi_tag.extents()), "Number of entries in positions and extents do not match!") }),
        could(multi_tag, &MultiTag::references, notEmpty(), {
            could(multi_tag, &MultiTag::extents, notFalse(), {
                must(multi_tag, &MultiTag::extents, extentsMatchRefs(multi_tag.references()), "number of entries (in 2nd dim) in extents does not match number of dimensions in all referenced DataArrays!") }),
            must(multi_tag, &MultiTag::positions, positionsMatchRefs(multi_tag.references()), "number of entries (in 2nd dim) in positions does not match number of dimensions in all referenced DataArrays!") })
    });

    return result.concat(result_base);
}
Beispiel #25
0
/* takes care with symbols ending in .bwl or .bb/ww/ll */
word parse_symbol(void *result,bool getaddr, byte *etype)
{
char *p;
void *value;
byte ssize;
word err;
ubyte len; char size;

/*	if (!isalpha(*ev))		already done for us
		return ERRM_INVALIDSYM;	*/
	p=ev++;
	while (issym(*ev))
		ev++;
	if (issymend(*ev))
		ev++;
	len=(ubyte)(ev-p);	
	if ( (len>2) && (*(ev-2)=='.') )
		{
		size=upper(*(ev-1));
		if ( (size=='B') || (size=='W') || (size=='L') )
			{
			ev-=2;
			len-=2;
			}
		}
	else if ( (len>3) && (*(ev-3)=='.') )
		{
		size=upper(*(ev-1));
		if (
			( (size=='B') || (size=='W') || (size=='L') ) &&
				(upper(*(ev-2))==size)
		   )
			{
			ev-=3;
			len-=3;
			}
		}
	/* try general table */
	if (!checking)
		{
		must( find_general_sym(p,len,&value,&ssize,getaddr) );
		#if DOUBLES
		if (ssize<EXPR_NOTINT)
			{
			must( coerce_value(value,ssize,result,EXPR_LONG) );
			*etype=E_NUMBER;
			}
		else
			{
			*(double*)result=
				ssize==EXPR_DOUBLE ?
					*(double*)value : *(float*)value;		/* cope with singles & doubles */
			*etype=E_DBLNUMBER;
			}
		#else
		must( coerce_value(value,ssize,result,EXPR_LONG) );
		*etype=E_NUMBER;
		#endif
		}
	else
		{
		*etype=E_NUMBER;
		}
	return 0;
}
Beispiel #26
0
Result validate(const Dimension &dim) {
    return validator({
        must(dim, &Dimension::index, notSmaller(1), "index is not set to valid value (> 0)!")
    });
}
Beispiel #27
0
Result validate(const SetDimension &set_dim) {
    return validator({
        must(set_dim, &SetDimension::index, notSmaller(1), "index is not set to valid value (size_t > 0)!"),
        must(set_dim, &SetDimension::dimensionType, isEqual<DimensionType>(DimensionType::Set), "dimension type is not correct!")
    });
}
Beispiel #28
0
Result validate_entity(const base::Entity<T> &entity) {
    return validator({
        must(entity, &base::Entity<T>::id, notEmpty(), "id is not set!"),
        must(entity, &base::Entity<T>::createdAt, notFalse(), "date is not set!")
    });
}