Пример #1
0
/* records */
static void parseKeywords (tokenInfo * const token, boolean local)
{
	switch (token->keyword)
	{
	case KEYWORD_END:
		fileSkipToCharacter (';');
		break;
	case KEYWORD_CONSTANT:
		parseConstant (local);
		break;
	case KEYWORD_TYPE:
		parseTypes (token);
		break;
	case KEYWORD_SUBTYPE:
		parseTypes (token);
		break;
	case KEYWORD_ENTITY:
		parseModule (token);
		break;
	case KEYWORD_COMPONENT:
		parseModule (token);
		break;
	case KEYWORD_FUNCTION:
		parseSubProgram (token);
		break;
	case KEYWORD_PROCEDURE:
		parseSubProgram (token);
		break;
	case KEYWORD_PACKAGE:
		parsePackage (token);
		break;
	default:
		break;
	}
}
Пример #2
0
TextPackage *TextPackageNewWithString(const char *string, const char *path, DFError **error)
{
    TextPackage *package = TextPackageNew();
    if (!parsePackage(package,string,path,error)) {
        TextPackageRelease(package);
        return NULL;
    }
    else
        return package;
}
Пример #3
0
bool ProjectParserMixin::parseProjectStatement(const ProjectParseContextSPtr& context, const CommentSPtr& comment)
{
    TokenizerPtr& tokenizer = context->tokenizer;

    TokenPtr core;

    if (tokenizer->check(Token::TYPE_IDENTIFIER, "core"))
    {
        core = tokenizer->current();
        tokenizer->shift();
        skipComments(context);
    }

    if (tokenizer->check(Token::TYPE_IDENTIFIER, "section"))
    {
        SectionSPtr section = parseSection(context, comment);
        if (section)
        {
            context->mProject << section;
        }
    }
    else
    if (tokenizer->check(Token::TYPE_IDENTIFIER, "package"))
    {
        if (!core)
        {
            *context <<= errorMessage(context, Message::p_unknownStatment)
                         << Message::Context("package")
                         << Message::Options("core");
        }
        PackageSPtr package = parsePackage(context);
        if (!core || !package)
            return false;

        core.reset();
        context->mProject->set_corePackage(package);
    }
    else
    {
        *context <<= errorMessage(context, Message::p_unknownStatment)
                     << Message::Context("top")
                     << Message::Options("section");
        tokenizer->shift();
    }

    return true;
}
void AudioSourceManager::loadPackage(std::string pathOnDisk)
{
    auto parse = JSON::parse(File(pathOnDisk));
    
    var package = parse[Identifier("package")];
    parsePackage(parse);
    
    std::vector<std::string> sampleNames;
    
    for(auto& package: packages)
    {
        for(auto& source: package.getSources())
        {
            sampleNames.emplace_back(source.info);
        }
    }

    auto files = swapNames(pathOnDisk, sampleNames);
    fileManager.loadFiles(files);
}
Пример #5
0
static void parseSqlFile (tokenInfo *const token)
{
    do
    {
	readToken (token);
	switch (token->keyword)
	{
	    case KEYWORD_cursor:    parseSimple (token, SQLTAG_CURSOR); break;
	    case KEYWORD_declare:   parseBlock (token, FALSE); break;
	    case KEYWORD_function:  parseSubProgram (token); break;
	    case KEYWORD_package:   parsePackage (token); break;
	    case KEYWORD_procedure: parseSubProgram (token); break;
	    case KEYWORD_subtype:   parseSimple (token, SQLTAG_SUBTYPE); break;
	    case KEYWORD_table:     parseTable (token); break;
	    case KEYWORD_trigger:   parseSimple (token, SQLTAG_TRIGGER); break;
	    case KEYWORD_type:      parseType (token); break;
	    default:                break;
	}
    } while (! isKeyword (token, KEYWORD_end));
}
Пример #6
0
static void parseGoFile (tokenInfo *const token)
{
	do
	{
		readToken (token);

		if (isType (token, TOKEN_KEYWORD))
		{
			switch (token->keyword)
			{
				case KEYWORD_package:
					parsePackage (token);
					break;
				case KEYWORD_func:
					parseFunctionOrMethod (token);
					break;
				case KEYWORD_const:
					parseConstTypeVar (token, GOTAG_CONST);
					break;
				case KEYWORD_type:
					parseConstTypeVar (token, GOTAG_TYPE);
					break;
				case KEYWORD_var:
					parseConstTypeVar (token, GOTAG_VAR);
					break;
				default:
					break;
			}
		}
		else if (isType (token, TOKEN_OPEN_PAREN) || isType (token, TOKEN_OPEN_CURLY) ||
			isType (token, TOKEN_OPEN_SQUARE))
		{
			skipToMatched (token);
		}
	} while (token->type != TOKEN_EOF);
}
Пример #7
0
int main(int argc, char *argv[])
{
    
    pANTLR3_UINT8 filename;
    pANTLR3_INPUT_STREAM input=NULL;
    pProtoJSLexer lxr;
    pANTLR3_COMMON_TOKEN_STREAM tstream;
    pProtoJSParser psr;
    ProtoJSParser_protocol_return     pbjAST;
    if (argc < 2 || argv[1] == NULL)
        filename = (pANTLR3_UINT8)"./input";
    else
        filename = (pANTLR3_UINT8)argv[1];
    const char * outputFilename="output";
    if (argc>=3) {
        outputFilename=argv[2];
    }
    char * csOut=NULL;
    char * cppOut=NULL;
    char * cppInclude=NULL;
    int argindex;
    const char *outputInternalNamespace="_ProtoJS_Internal";
    const char *outputExternalNamespace="";
    for (argindex=3;argindex<argc;++argindex) {
        
        if (strncmp(argv[argindex],"--cpp=",6)==0) {
            cppOut=argv[argindex]+6;
        }
        if (strncmp(argv[argindex],"--cs=",5)==0) {
            csOut=argv[argindex]+5;
        }
        if (strncmp(argv[argindex],"--include=",10)==0) {
            cppInclude=argv[argindex]+10;
        }
        if (strncmp(argv[argindex],"--inamespace=",13)==0) {
            outputInternalNamespace=argv[argindex]+13;
        }
        if (strncmp(argv[argindex],"--namespace=",12)==0) {
            outputExternalNamespace=argv[argindex]+12;
        }
    }
    char*package=parsePackage((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace);
    pANTLR3_HASH_TABLE qualifiedTypes=antlr3HashTableNew(11);
    parseTypes((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace,package,qualifiedTypes);
    if(generateASTProto((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace,package,qualifiedTypes,&pbjAST,&lxr,&psr,&tstream,&input)) {
        pANTLR3_COMMON_TREE_NODE_STREAM    nodes;
        nodes   = antlr3CommonTreeNodeStreamNewTree(pbjAST.tree, ANTLR3_SIZE_HINT); // sIZE HINT WILL SOON BE DEPRECATED!!
        pANTLR3_STRING s = nodes->stringFactory->newRaw(nodes->stringFactory);
        grammarToString(nodes->tnstream,nodes->root,NULL,s);
        FILE*fp=fopen(outputFilename,"w");
        if (!fp) {
            perror("Unable to open output file!");
            exit(2);
        }
        if (s->size>1)
            fwrite(s->chars,s->size-1,1,fp);
        fclose(fp);
        stringFree(s);
        nodes   ->free  (nodes);        nodes   = NULL;
    }
    psr->free(psr);
    psr = NULL;
    
    tstream->free(tstream);
    tstream = NULL;
    
    
    lxr->free(lxr);
    lxr = NULL;
    input->close(input);
    input = NULL;
    return 0;
}