示例#1
0
void DirectiveParser::lex(Token *token)
{
    do
    {
        mTokenizer->lex(token);

        if (token->type == Token::PP_HASH)
        {
            parseDirective(token);
            mPastFirstStatement = true;
        }

        if (token->type == Token::LAST)
        {
            if (!mConditionalStack.empty())
            {
                const ConditionalBlock &block = mConditionalStack.back();
                mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNTERMINATED,
                                     block.location, block.type);
            }
            break;
        }

    }
    while (skipping() || (token->type == '\n'));

    mPastFirstStatement = true;
}
void ScriptPreprocessor::process(std::string & str, const std::string & fileName)
{
	m_fileName = fileName;

	if (str.empty())
		return;

	size_t i = 0;

	while (true)
	{
		char c = str[i];
		i = str.find_first_not_of(" \n\r\t", i);
		if (i == std::string::npos)
			break;
		if (str[i] == m_beginChar)
		{
			parseDirective(str, i);
		}
		else
		{
			i = str.find_first_of("\n\r", i);
			if (i == std::string::npos)
				break;
		}
	}
}
示例#3
0
std::unique_ptr<DirectivesAST> Parser::parseDirectives() {

	std::vector<std::unique_ptr<DirectiveAST>> directives;

	do {

		lexer->getNextToken();
		auto directive = parseDirective();
		directives.push_back (std::move(directive));

	} while (lexer->currentToken == ',');

	return std::make_unique<DirectivesAST> (std::move(directives));

}
示例#4
0
/* 
	Description- parses a line, and exit when setect error.
	GET-
		line: struct that whlie hold info about this line.
		lineStr: the line that we parse.
		lineNum: line number in the file.
		(IC, DC). 
*/
bool parseLine(lineInfo *line, char *lineStr, int lineNum, int *IC, int *DC)
{
	char *startOfNextPart = lineStr;

	line->lineNum = lineNum;
	line->address = FIRST_ADDRESS + *IC;
	line->originalString = allocString(lineStr);
	line->lineStr = line->originalString;
	line->label = NULL;
	line->commandStr = NULL;
	line->cmd = NULL;

	if (!line->originalString)
	{
		printf("ERR:\tNot enough memory - malloc falied.\n");
		return TRUE;
	}

	/* Check if the line is a comment */
	if (isCommentOrEmpty(line))
	{	
		return FALSE;
	}

	/* Find label and add it to the label list */
	startOfNextPart = findLabel(line, *IC);

	/* Update the line if startOfNextPart isn't NULL */
	if (startOfNextPart)
	{
		line->lineStr = startOfNextPart;
	}

	/* Find the command token */
	line->commandStr = getFirstTok(line->lineStr, &startOfNextPart);
	line->lineStr = startOfNextPart;
	/* Parse the command / directive */
	if (isDirective(line->commandStr))
	{
		line->commandStr++; /* Remove the '.' from the command */
		parseDirective(line, IC, DC);
	}
	else
	{
		parseCommand(line, IC, DC);
	}
	return TRUE;
}
示例#5
0
文件: Parser.cpp 项目: flame1/armips
CAssemblerCommand* Parser::parseCommand()
{
	CAssemblerCommand* command;

	while (checkEquLabel() || checkMacroDefinition())
	{
		// do nothing, just parse all the equs and macros there are
		if (hasError())
			return handleError();
	}
	
	updateFileInfo();

	if (atEnd())
		return new DummyCommand();
	
	if ((command = parseLabel()) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = parseMacroCall()) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = Arch->parseDirective(*this)) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = parseDirective(directives)) != nullptr)
		return command;
	if (hasError())
		return handleError();

	if ((command = Arch->parseOpcode(*this)) != nullptr)
		return command;
	if (hasError())
		return handleError();

	const Token& token = peekToken();
	printError(token,L"Parse error '%s'",token.getOriginalText());
	return handleError();
}
示例#6
0
文件: elixir.c 项目: jsvisa/ctags
static void findElixirTags (void)
{
    vString *const module = vStringNew ();
    const unsigned char *line;

    while ((line = fileReadLine ()) != NULL)
    {
        const unsigned char *cp = line;

        skipWhitespace(&cp);

        if (*cp == '#')  /* skip initial comment */
            continue;
        if (*cp == '@')  /* strings sometimes start in column one */
            continue;

        if (*cp == 'd')
            parseDirective(cp, module);
    }
    vStringDelete (module);
}
示例#7
0
// policy            = directive-list
// directive-list    = [ directive *( ";" [ directive ] ) ]
//
void CSPDirectiveList::parse(const UChar* begin, const UChar* end)
{
    m_header = String(begin, end - begin);

    if (begin == end)
        return;

    const UChar* position = begin;
    while (position < end) {
        const UChar* directiveBegin = position;
        skipUntil<UChar>(position, end, ';');

        String name, value;
        if (parseDirective(directiveBegin, position, name, value)) {
            ASSERT(!name.isEmpty());
            addDirective(name, value);
        }

        ASSERT(position == end || *position == ';');
        skipExactly<UChar>(position, end, ';');
    }
}
示例#8
0
bool Engine::executeDirective(std::string directive,HttpServerRequest &httpRequest,
	std::string &output)
{
	std::string name;

	std::map<std::string,std::string> attributes;

	if ( !parseDirective(directive,name,attributes) ) {
		return false;
	}

	if ( name=="include" )
	{
		std::string fileUri = attributes["file"];

		if ( httpRequest.getSite()!=NULL && Util::UriUtil::isValid(fileUri) )
		{
			if ( !Util::UriUtil::isAbsolute(fileUri) ) {
				fileUri = Util::UriUtil::getParentSegment(httpRequest.getUri()) + "/" + fileUri;
			}

			std::string filePath = httpRequest.getSite()->getRealPath(fileUri);
			FILE *file = fopen(filePath.c_str(),"rb");
			if ( file!=NULL )
			{
				std::string script;
				if ( parseFile(file,httpRequest,script) ) {
					output = script;
				}

				fclose(file);
			}

			return true;
		}
	}

	return false;
}
示例#9
0
// policy            = directive-list
// directive-list    = [ directive *( ";" [ directive ] ) ]
//
void ContentSecurityPolicy::parse(const String& policy)
{
    ASSERT(!m_havePolicy);

    if (policy.isEmpty())
        return;

    const UChar* position = policy.characters();
    const UChar* end = position + policy.length();

    while (position < end) {
        const UChar* directiveBegin = position;
        skipUtil(position, end, ';');

        String name, value;
        if (parseDirective(directiveBegin, position, name, value)) {
            ASSERT(!name.isEmpty());
            addDirective(name, value);
        }

        ASSERT(position == end || *position == ';');
        skipExactly(position, end, ';');
    }
}
示例#10
0
文件: erlang.c 项目: simlrh/ctags
static void findErlangTags (void)
{
	vString *const module = vStringNew ();
	const unsigned char *line;

	while ((line = fileReadLine ()) != NULL)
	{
		const unsigned char *cp = line;

		if (*cp == '%')  /* skip initial comment */
			continue;
		if (*cp == '"')  /* strings sometimes start in column one */
			continue;

		if ( *cp == '-')
		{
			++cp;  /* Move off of the '-' */
			parseDirective(cp, module);
		}
		else if (isIdentifierFirstCharacter ((int) *cp))
			parseFunctionTag (cp, module);
	}
	vStringDelete (module);
}