Example #1
0
/*
** Process time function arguments.  argv[0] is a date-time stamp.
** argv[1] and following are modifiers.  Parse them all and write
** the resulting time into the DateTime structure p.  Return 0
** on success and 1 if there are any errors.
**
** If there are zero parameters (if even argv[0] is undefined)
** then assume a default value of "now" for argv[0].
*/
static int isDate(
  sqlite3_context *context, 
  int argc, 
  sqlite3_value **argv, 
  DateTime *p
){
  int i;
  const unsigned char *z;
  int eType;
  memset(p, 0, sizeof(*p));
  if( argc==0 ){
    return setDateTimeToCurrent(context, p);
  }
  if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
                   || eType==SQLITE_INTEGER ){
    p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
    p->validJD = 1;
  }else{
    z = sqlite3_value_text(argv[0]);
    if( !z || parseDateOrTime(context, (char*)z, p) ){
      return 1;
    }
  }
  for(i=1; i<argc; i++){
    z = sqlite3_value_text(argv[i]);
    if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
  }
  return 0;
}
Example #2
0
/*
** Process time function arguments.  argv[0] is a date-time stamp.
** argv[1] and following are modifiers.  Parse them all and write
** the resulting time into the DateTime structure p.  Return 0
** on success and 1 if there are any errors.
*/
static int isDate(int argc, const char **argv, DateTime *p){
  int i;
  if( argc==0 ) return 1;
  if( argv[0]==0 || parseDateOrTime(argv[0], p) ) return 1;
  for(i=1; i<argc; i++){
    if( argv[i]==0 || parseModifier(argv[i], p) ) return 1;
  }
  return 0;
}
static WKEventModifiers parseModifierArray(JSContextRef context, JSValueRef arrayValue)
{
    if (!arrayValue)
        return 0;
    if (!JSValueIsObject(context, arrayValue))
        return 0;
    JSObjectRef array = const_cast<JSObjectRef>(arrayValue);
    unsigned length = arrayLength(context, array);
    WKEventModifiers modifiers = 0;
    for (unsigned i = 0; i < length; i++) {
        JSValueRef exception = 0;
        JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception);
        if (exception)
            continue;
        JSRetainPtr<JSStringRef> string(Adopt, JSValueToStringCopy(context, value, &exception));
        if (exception)
            continue;
        modifiers |= parseModifier(string.get());
    }
    return modifiers;
}
void GrammarParser::parseRightSide(int leftSide) {
  Production prod(leftSide, m_lex.getSourcePos());
  while(m_token == NAME) {
    const String         name = m_lex.getText();
    const SourcePosition pos  = m_lex.getSourcePos();

    next();
    const SymbolModifier modifier   = parseModifier();
    int rightIndex = m_grammar.findSymbol(name);
    if(rightIndex < 0) {
      rightIndex = m_grammar.addNonTerminal(name, pos);
    } else if(m_grammar.isTerminal(rightIndex)) {
      prod.m_precedence = m_grammar.getSymbol(rightIndex).m_precedence;
    }
    prod.m_rightSide.add(RightSideSymbol(rightIndex, modifier));
  }
  if(m_token == PREC) { // %prec specifier
    next();
    switch(m_token) {
    case NUMBER:
      { prod.m_precedence = (short)m_lex.getNumber();
        next();
      }
      break;

    case NAME:
      { const String name = m_lex.getText();
        next();
        int tokenIndex = m_grammar.findSymbol(name);
        bool ok = true;
        if(tokenIndex < 0) {
          m_lex.error(_T("Unknown symbol in %%prec-clause:%s."), name.cstr());
          ok = false;
        } else if(!m_grammar.isTerminal(tokenIndex)) {
          m_lex.error(_T("Symbol %s must be terminal in %%prec-clause."), name.cstr());
          ok = false;
        }
        if(ok) {
          prod.m_precedence = m_grammar.getSymbol(tokenIndex).m_precedence;
        }
      }
      break;

    default:
      m_lex.error(_T("Expected NAME of NUMBER."));
    }
  }

  if(m_token == LCURL) {
    const SourcePosition sourcePos = m_lex.getSourcePos();
    CompactShortArray usedDollar;
    m_actionBody = EMPTYSTRING;
    m_lex.collectBegin();
    next();
    parseActionBody(sourcePos, usedDollar, prod);
    if(m_token != RCURL) {
      m_lex.error(_T("Expected '}'."));
    } else {
      next();
    }
    m_lex.collectEnd();
    SourceText tmp;
    m_lex.getCollected(tmp);
    prod.m_actionBody.m_sourceText = trim(m_actionBody + tmp.m_sourceText);
    prod.m_actionBody.m_pos        = SourcePositionWithName(m_lex.getAbsoluteFileName(), sourcePos);
/*
    printf("body:<%s> at line %d\n",
      prod.m_actionBody.m_sourceText.cstr(),
      prod.m_actionBody.m_lineno);
*/
  }

  m_grammar.addProduction(prod);
}