Exemplo n.º 1
0
static struct phyloTree *parseSubTree(char **ptrPtr)
/* the recursive workhorse function, parses a tree from ptr */
{
struct phyloTree *node = NULL;
char *ptr = *ptrPtr;

/* trees are terminated by one of these three chars */
if ((*ptr == ';') || (*ptr == ',') || (*ptr == ')') )
    return NULL;

AllocVar(node);
if (*ptr == '(') 
    {
    struct phyloTree *edge;

    ptr++;

    do
	{
	struct phyloTree *child = parseSubTree(&ptr);
	if (!child)
	    errAbort("missing child/subTree at (%s)",ptr-1);
	edge = newEdge(node,child);
	edge->parent = node;
	} while (*ptr++ == ',');
    --ptr;
    if (*ptr++ != ')') 
	errAbort("unbalanced parenthesis at (%s)",ptr-1);
    node->ident = parseIdent(&ptr);
    }
else 
    if ((*ptr == ':') || (isalpha(*ptr))|| (isdigit(*ptr)) 
	 || (*ptr == '\'') || (*ptr == '.'))
	node->ident = parseIdent(&ptr);
else
    errAbort("illegal char '%c' in phyloString",*ptr);

if (*ptr == '[')
    {
    if (startsWith("[&&NHX:D=Y]",ptr))
	node->isDup = TRUE;

    while(*ptr != ']')
	ptr++;

    ptr++;

    }

*ptrPtr = ptr;


return node;
}
Exemplo n.º 2
0
/*
 * Parse an external acl helper line.
 *
 * Squid can be configured to pass various formats, we assume something
 * similar to the normal redirector format:
 *
 *   %URI %SRC %LOGIN
 *
 * For example:
 *   external_acl_type foo ttl=60 children=1 %URI %SRC %LOGIN /path/to/sg
 */
int parseAuthzLine(char *line, struct SquidInfo *s)
{
	char *field = NULL;

	sgLogDebug("got authz line %s", line);

	resetSquidInfo(s);

	/* get the URL and parse */
	if ((field = strtok(line, "\t ")) == NULL)
		return 0;

	HTUnEscape(field);
	if (!parseUrl(field, s))
		return 0;

	/* get the source address and parse */
	if ((field = strtok(NULL, " \t\n")) == NULL)
		return 0;

	HTUnEscape(field);      /* just in case, IPs should not need escaping */
	strcpy(s->src, field);

	/* get the login and parse */
	if ((field = strtok(NULL, " \t\n")) == NULL)
		return 0;

	if (!parseIdent(field,s))
		return 0;

	sgLogDebug("parsed authz line: furl='%s' domain='%s' surl='%s' src=%s ident='%s'",
		   s->furl, s->domain, s->surl, s->src, s->ident);

	return 1;
}
Exemplo n.º 3
0
bool TScanner::nextToken()
{	
	skipSpace();	
	tokenCol=current-lineStart;
	tokenLine=line;
	if(current>=condition.length()){
		token=TToken::FILE_END;
		tokenText="";
		return false;
	}	

	QChar l_ch=condition.at(current);
	
	if(l_ch=='"'||l_ch=='\''){		
		return parseString(l_ch);
	} else if((l_ch>='a' && l_ch <='z') ||(l_ch>='A' && l_ch<='Z') || l_ch=='_'){
		return parseIdent();
	} 
	token=TToken::CHAR;
	tokenText=l_ch;
	current++;
	if(l_ch=='='){
		token=TToken::COND_EQUAL;
	} else if(l_ch=='>'){
		token=TToken::COND_BIGGER;		
		if(current<condition.length()){			
			if(condition.at(current)=='='){			
				token=TToken::COND_BE;
				tokenText=">=";
				current++;
			}
		}
	} else if(l_ch=='<'){
		token=TToken::COND_SMALLER;		
		if(current<condition.length()){
			if(condition.at(current)=='='){
				token=TToken::COND_SE;
				tokenText="<=";
				current++;
			}
		}
		
	} else if(l_ch=='!'){
		token=TToken::COND_NOT;		
		if(current<condition.length()){
			if(condition.at(current)=='='){
				token=TToken::COND_NE;
				tokenText="!=";
				current++;
			}
		}
		
	} else if(l_ch=='('){
		token=TToken::HOOK_L;		
	} else if(l_ch==')'){
		token=TToken::HOOK_R;		
	}
	return false;
}
Exemplo n.º 4
0
/*
 * Parse a redirector input line, format is:
 *
 *   URL ip-address/fqdn ident method
 *
 * for example
 *    http://www.example.com/page1.html 192.168.2.3/- andi GET
 */
int parseLine(char *line, struct SquidInfo *s)
{
	char *field = NULL;
	char *p = NULL;

	sgLogDebug("got redirector line %s", line);

	resetSquidInfo(s);

	/* get the URL and parse */
	if ((field = strtok(line, "\t ")) == NULL)
		return 0;

	HTUnEscape(field);
	if (!parseUrl(field, s))
		return 0;

	/* get the source address and parse */
	if ((field = strtok(NULL, " \t\n")) == NULL)
		return 0;

	if ((p = strchr(field, '/')) != NULL) {
		*p = 0;
		strcpy(s->src, field);
		strcpy(s->srcDomain, p + 1);
		if (s->srcDomain[0] == '-' && s->srcDomain[1] == 0)
			s->srcDomain[0] = 0;
	} else {
		strcpy(s->src, field);
	}

	/* get the identity */
	if ((field = strtok(NULL, " \t\n")) == NULL)
		return 0;

	if (!parseIdent(field,s))
		return 0;

	/* get the method */
	if ((field = strtok(NULL, " \t\n")) == NULL)
		return 0;

	strcpy(s->method, field);
	if (s->method[0] == '\0')
		return 0;

	sgLogDebug("parsed redirector line: furl='%s' domain='%s' surl='%s' src=%s ident='%s'",
		   s->furl, s->domain, s->surl, s->src, s->ident);

	return 1;
}
Exemplo n.º 5
0
void parseExpr(B& in, S& solver, vec<Lit>& out_ps, vec<Int>& out_Cs, vec<char>& tmp)
    // NOTE! only uses "getVar()" method of solver; doesn't add anything.
    // 'tmp' is a tempory, passed to avoid frequent memory reallocation.
{
    bool empty = true;
    for(;;){
        skipWhitespace(in);
        if ((*in < '0' || *in > '9') && *in != '+' && *in != '-') break;
        out_Cs.push(parseInt(in));
        skipWhitespace(in);
        if (*in != '*') throw xstrdup("Missing '*' after coefficient.");
        ++in;
        out_ps.push(Lit(solver.getVar(parseIdent(in, tmp))));
        empty = false;
    }
    if (empty) throw xstrdup("Empty expression.");
}
Exemplo n.º 6
0
FlowToken FlowLexer::nextToken()
{
	bool expectsValue = token() == FlowToken::Ident || FlowTokenTraits::isOperator(token());

	lastPos_ = currPos_;

	if (consumeSpace())
		return token_ = FlowToken::Eof;

//	printf("FlowLexer.nextToken: currentChar %s curr[%zu:%zu.%zu] next[%zu:%zu.%zu]\n",
//		escape(currentChar_).c_str(),
//		currPos_.line, currPos_.column, currPos_.offset,
//		nextPos_.line, nextPos_.column, nextPos_.offset);

	content_.clear();
	content_ += static_cast<char>(currentChar_);
	lastLocation_ = currLocation_;
	currLocation_.begin = currPos_;

	switch (currentChar_) {
	case EOF: // (-1)
		return token_ = FlowToken::Eof;
	case '=':
		switch (nextChar()) {
		case '=':
			nextChar();
			return token_ = FlowToken::Equal;
		case '^':
			nextChar();
			return token_ = FlowToken::PrefixMatch;
		case '$':
			nextChar();
			return token_ = FlowToken::SuffixMatch;
		case '~':
			nextChar();
			return token_ = FlowToken::RegexMatch;
		case '>':
			nextChar();
			return token_ = FlowToken::HashRocket;
		default:
			return token_ = FlowToken::Assign;
		}
	case '<':
		switch (nextChar()) {
			case '<':
				nextChar();
				return token_ = FlowToken::Shl;
			case '=':
				nextChar();
				return token_ = FlowToken::LessOrEqual;
			default:
				return token_ = FlowToken::Less;
		}
	case '>':
		switch (nextChar()) {
			case '>':
				nextChar();
				return token_ = FlowToken::Shr;
			case '=':
				nextChar();
				return token_ = FlowToken::GreaterOrEqual;
			default:
				return token_ = FlowToken::Greater;
		}
	case '|':
		switch (nextChar()) {
			case '|':
				nextChar();
				return token_ = FlowToken::Or;
			case '=':
				nextChar();
				return token_ = FlowToken::OrAssign;
			default:
				return token_ = FlowToken::BitOr;
		}
	case '&':
		switch (nextChar()) {
			case '&':
				nextChar();
				return token_ = FlowToken::And;
			case '=':
				nextChar();
				return token_ = FlowToken::AndAssign;
			default:
				return token_ = FlowToken::BitAnd;
		}
	case '.':
		if (nextChar() == '.') {
			if (nextChar() == '.') {
				nextChar();
				return token_ = FlowToken::Ellipsis;
			}
			return token_ = FlowToken::DblPeriod;
		}
		return token_ = FlowToken::Period;
	case ':':
		if (peekChar() == ':') {
			stringValue_.clear();
			return continueParseIPv6(false);
		} else {
			nextChar();
			return token_ = FlowToken::Colon;
		}
	case ';':
		nextChar();
		return token_ = FlowToken::Semicolon;
	case ',':
		nextChar();
		return token_ = FlowToken::Comma;
	case '{':
		nextChar();
		return token_ = FlowToken::Begin;
	case '}':
		if (interpolationDepth_) {
			return token_ = parseInterpolationFragment(false);
		} else {
			nextChar();
			return token_ = FlowToken::End;
		}
	case '(':
		nextChar();
		return token_ = FlowToken::RndOpen;
	case ')':
		nextChar();
		return token_ = FlowToken::RndClose;
	case '[':
		nextChar();
		return token_ = FlowToken::BrOpen;
	case ']':
		nextChar();
		return token_ = FlowToken::BrClose;
	case '+':
		nextChar();
		return token_ = FlowToken::Plus;
	case '-':
		nextChar();
		return token_ = FlowToken::Minus;
	case '*':
		switch (nextChar()) {
			case '*':
				nextToken();
				return token_ = FlowToken::Pow;
			default:
				return token_ = FlowToken::Mul;
		}
	case '/':
		if (expectsValue)
			return token_ = parseString('/', FlowToken::RegExp);

		nextChar();
		return token_ = FlowToken::Div;
	case '%':
		nextChar();
		return token_ = FlowToken::Mod;
	case '!':
		switch (nextChar()) {
			case '=':
				nextChar();
				return token_ = FlowToken::UnEqual;
			default:
				return token_ = FlowToken::Not;
		}
	case '\'':
		return token_ = parseString(true);
	case '"':
		++interpolationDepth_;
		return token_ = parseInterpolationFragment(true);
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
		return parseNumber();
	default:
		if (std::isalpha(currentChar()) || currentChar() == '_')
			return token_ = parseIdent();

		if (std::isprint(currentChar()))
			printf("lexer: unknown char %c (0x%02X)\n", currentChar(), currentChar());
		else
			printf("lexer: unknown char %u (0x%02X)\n", currentChar() & 0xFF, currentChar() & 0xFF);

		nextChar();
		return token_ = FlowToken::Unknown;
	}
}
Exemplo n.º 7
0
/**
Implements the parsing of expressions that are part of the core language

The core language supports:
- Functions (but not closures)
- Integer literals (decimal only)
- String literals
- Tuple literals [a,b]
- If-else expressions
- Sequencing blocks with {a;b}
- Function calls fun(a,b)
*/
Tuple coreParseExpr(Input* input)
{
    // Consume whitespace
    input->eatWS();

    // Numerical constant
    if (isdigit(input->peekCh()))
    {
        return parseInt(input);
    }

    // String literal
    if (input->matchCh('\''))
    {
        return parseStringLit(input, '\'');
    }
    if (input->matchCh('\"'))
    {
        return parseStringLit(input, '\"');
    }

    // Tuple expression
    if (input->matchCh('['))
    {
        return Tuple{
            Tuple("tuple"),
            parseExprList(input, ']')
        };
    }

    // Block/sequence expression (i.e { a; b; c }
    if (input->matchCh('{'))
    {
        return parseBlockExpr(input, '}');
    }

    // Keywords
    if (isalnum(input->peekCh()))
    {
        // If expression
        if (input->matchStr("if"))
            return parseIfExpr(input);

        // Let expression
        if (input->matchStr("let"))
            return parseLetExpr(input);

        // Function definition expression
        if (input->matchStr("fun"))
            return parseFunExpr(input);

        // Function call expression
        if (input->matchStr("call"))
            return parseCallExpr(input);
    }

    // Host/magic constants
    if (input->matchCh('$'))
    {
        return parseHostRef(input);
    }

    // Variable references
    if (input->peekCh() == '_' || isalpha(input->peekCh()))
    {
        return parseIdent(input);
    }

    // Parsing failed
    throw ParseError(input, "failed to parse expression");
}