-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
a textmate like language is generated but the match should be made in…
…to a regex; this is also very barebones
- Loading branch information
1 parent
b04d7d1
commit 5626e6e
Showing
4 changed files
with
152 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package gen | ||
import upickle.default.{ReadWriter => RW, macroRW} | ||
|
||
/** | ||
* Common Grammar Language | ||
*/ | ||
case class CGL(scopeName: String, fileTypes: String, patterns: Seq[MatchPattern]) { | ||
def addPattern(mp: MatchPattern): CGL = { | ||
CGL(scopeName, fileTypes, patterns = patterns :+ mp) | ||
} | ||
} | ||
object CGL{ | ||
implicit val rw: RW[CGL] = macroRW | ||
} | ||
|
||
|
||
|
||
case class MatchPattern(name: String, `match`: String) | ||
object MatchPattern { | ||
implicit val rw: RW[MatchPattern] = macroRW | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
package gen | ||
|
||
class Main { | ||
import hre.io.{RWFile, Readable} | ||
import upickle.default.{macroRW, ReadWriter => RW} | ||
import upickle._ | ||
import java.io.File | ||
import org.antlr.v4.runtime | ||
import org.antlr.v4.runtime.{CharStreams, CommonTokenStream} | ||
import vct.antlr4.generated.ANTLRv4Parser.Rules0Context | ||
import vct.antlr4.generated.ANTLRv4ParserPatterns.{GrammarSpec0, RuleSpec0, Rules0} | ||
import vct.antlr4.generated.{ANTLRv4Lexer, ANTLRv4Parser} | ||
|
||
import java.io.FileNotFoundException | ||
|
||
case object Main { | ||
|
||
def parse() = { | ||
val readable: Readable = RWFile(new File("C:\\Development\\Vercors-Dev\\vercors\\src\\parsers\\antlr4\\LangPVLLexer.g4")) | ||
try { | ||
readable.read { reader => | ||
val stream: runtime.CharStream = CharStreams.fromReader(reader, readable.fileName) | ||
val lexer = new ANTLRv4Lexer(stream) | ||
val tokens = new CommonTokenStream(lexer) | ||
val parser = new ANTLRv4Parser(tokens) | ||
parser.grammarSpec() | ||
} | ||
} catch { | ||
case f: FileNotFoundException => throw f | ||
} | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
var textMateGrammar = CGL(args(0), args(1), Nil) | ||
val tree = parse() | ||
tree match { | ||
case GrammarSpec0(grammarDecl, prequelConstructs, rules, modeSpec, _) => | ||
rules match { | ||
case Rules0(specRules) => | ||
for (ruleText <- specRules.map(rule => rule.getText)) | ||
if (ruleText.matches(".*\\{.*\\}.*")) | ||
textMateGrammar = textMateGrammar.addPattern( | ||
MatchPattern(ruleText.substring(ruleText.indexOf('{') + 2, ruleText.indexOf("}") - 2), | ||
ruleText.split('\'')(1)) | ||
) | ||
} | ||
} | ||
print(upickle.default.write(textMateGrammar, indent = 2)) | ||
} | ||
|
||
} | ||
|