Latest 1.0.0
Homepage https://github.com/NoodleOfDeath/PastaParser
License MIT
Platforms ios 10.0
Dependencies SwiftyXMLParser
Authors

CI Status
Version
License
Platform

The goal of PastaParser is to provide a lightweight and extensible framework for tokenizing and parsing stream of characters using a user defined grammar definition that can attribute meaning to occurrences and/or sequences of characters that match any number of custom rules belonging to that grammar. Using this framework should allow developers to not only define any number of custom languages without the need for a complete project rebuild (just the addition of a simple XML file or ParserParser grammar package using the .ppgrammar package extension), utilize syntax highlighting, identifier and scope recognition, code recommendation, and much more.

Support to import and convert ANTLR4 grammar files to PastaParser grammar file format is a long term goal of this project, as well.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

iOS/macOS – Swift (CocoaPods)

pod 'PastaParser'

Java (Maven)

<dependency>
    <groupId>com.noodleofdeath</groupId>
    <artifactId>pastaparser</artifactId>
    <version>1.0.0</version>
</dependency>

Author

NoodleOfDeath, [email protected]

License

PastaParser is available under the MIT license. See the LICENSE file for more info.

Usage

Swift

import XCTest
import PastaParser

class PastaParserTests: XCTestCase {

    func testExample() {
        guard
            let grammarFile = Bundle(for: type(of: self)).path(forResource: "grammars/public.swift-source", ofType: "ppgrammar"),
            let sampleFile = Bundle(for: type(of: self)).path(forResource: "samples/Test", ofType: "swift")
            else { XCTFail(); return }
        do {
            let grammar = try PPCompoundGrammar(file: grammarFile)
            let text = try String(contentsOfFile: sampleFile)
            let engine = PPCompoundGrammarEngine(grammar: grammar)
            engine.process(text, options: .verbose)
        } catch {
            print(error)
            XCTFail()
        }
    }

}

Java

import static org.junit.Assert.fail;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.junit.Test;

import com.noodleofdeath.pastaparser.io.engine.SyntaxEngine;
import com.noodleofdeath.pastaparser.io.engine.impl.BaseTextSyntaxEngine;
import com.noodleofdeath.pastaparser.io.lexer.Lexer;
import com.noodleofdeath.pastaparser.io.parser.Parser;
import com.noodleofdeath.pastaparser.io.token.TextToken;
import com.noodleofdeath.pastaparser.model.grammar.CompoundGrammar;
import com.noodleofdeath.pastaparser.model.grammar.impl.BaseCompoundGrammar;

class PastaParserSystemTest {

    private static String SAMPLES_DIRECTORY = "../../samples";
    private static String GRAMMARS_DIRECTORY = "../../grammars";

    public static void main(String[] args) throws Exception {
        testGrammar();
    }

    @Test
    public static void testGrammar() throws Exception {

        File file = new File(SAMPLES_DIRECTORY + "/Test.swift");
        FileInputStream fis;
        String characterStream = "";
        try {
            fis = new FileInputStream(file);
            byte[] data = new byte[(int) file.length()];
            fis.read(data);
            fis.close();
            characterStream = new String(data, "UTF-8");
        } catch (FileNotFoundException error) {
            error.printStackTrace();
            fail();
        } catch (IOException error) {
            error.printStackTrace();
            fail();
        }

        CompoundGrammar Grammar = new BaseCompoundGrammar(GRAMMARS_DIRECTORY + "/public.swift-source");
        SyntaxEngine<String, TextToken, Lexer<String, TextToken>, Parser<String, TextToken>> engine = new BaseTextSyntaxEngine(Grammar);
        engine.process(characterStream, true);

    }

}

Latest podspec

{
    "name": "PastaParser",
    "version": "1.0.0",
    "summary": "Simple, extensible, and scalable grammar parsing engine.",
    "description": "The goal of PastaParser is to provide a lightweight and extensible framework for tokenizing and parsing stream of characters using a user defined grammar definition that can attribute meaning to occurrences and/or sequences of characters that match any number of custom rules belonging to that grammar. Using this framework should allow developers to not only define any number of custom languages without the need for a complete project rebuild (just the addition of a simple XML file or ParserParser grammar package using the .ppgrammar package extension), utilize syntax highlighting, identifier and scope recognition, code recommendation, and much more.nnSupport to import and convert ANTLR4 grammar files to PastaParser grammar file format is a long term goal of this project, as well.",
    "homepage": "https://github.com/NoodleOfDeath/PastaParser",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "NoodleOfDeath": "[email protected]"
    },
    "source": {
        "git": "https://github.com/NoodleOfDeath/PastaParser.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.0",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "source_files": "src/swift/PastaParser/Classes/**/*{h,m,swift}",
    "dependencies": {
        "SwiftyXMLParser": [
            "4.0"
        ]
    }
}

Pin It on Pinterest

Share This