diff --git a/LICENSE b/LICENSE index 6352157..e69de29 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2025 Tan Kian-ting and contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/Project.toml b/Project.toml index 5faab6e..9d4a457 100644 --- a/Project.toml +++ b/Project.toml @@ -3,6 +3,11 @@ uuid = "de6df24e-a306-4916-96f6-3ab6c7568c2f" authors = ["Tan Kian-ting and contributors"] version = "1.0.0-DEV" +[deps] +ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" +ParserCombinator = "fae87a5f-d1ad-5cf0-8f61-c941e1580b46" +libharu_jll = "d4e8948d-4b7e-5538-9d15-404f6f0a9070" + [compat] julia = "1.6.7" diff --git a/example/ex1 copy.ug b/example/ex1 copy.ug new file mode 100644 index 0000000..fc7d141 --- /dev/null +++ b/example/ex1 copy.ug @@ -0,0 +1,7 @@ +%123%@foo text%456 7% % + +8 9 10% + +{@foo} + +{@foo|@bar} \ No newline at end of file diff --git a/example/ex1.ug b/example/ex1.ug new file mode 100644 index 0000000..a8c2978 --- /dev/null +++ b/example/ex1.ug @@ -0,0 +1,2 @@ +@foo +{@foo|@bar|12\|} \ No newline at end of file diff --git a/src/parsing.jl b/src/parsing.jl new file mode 100644 index 0000000..534e124 --- /dev/null +++ b/src/parsing.jl @@ -0,0 +1,52 @@ +module Parsing +using ParserCombinator +abstract type Node end +struct ID<:Node val end +struct SEQ<:Node val end # like (a b c) in scheme +struct ELE<:Node val end #an element in a seq +struct ESC_CHAR<:Node val end # character preceded by escape char "\" + +#= +grammar rules of uahgi +=# + +comment = p"\%[^%]+\%" +newline = p"(\r?\n)" +space = p"[ \t]" + +id_name = p"[_a-zA-Z][_0-9a-zA-Z]*" > ID +id = E"@" + id_name + +char = p"[^ \n\r\t\\]"#[1:2,:?] + +# chars should be preceded by "\" are \, {, }, |, @, % +esc_char = p"[\{\|\}\@\%]" > ESC_CHAR +esc_combined = E"\\" + esc_char +#= +seq = (foo x1 x2 " ") +=> {@foo|x1|x2| } +=# +char_and_combined = char | esc_combined +seq_item = id | Repeat(char_and_combined) |> ELE +seq_item_rest = E"|" + seq_item +seq_inner = seq_item + (seq_item_rest)[0:end] |> SEQ +seq = E"{" + seq_inner + E"}" + + +part = seq | comment | space | newline | id | char +all = Repeat(part) + Eos() + +function parse(input) + print(input) + b = parse_one(input, all) + print("\n" * string(b) * "\n") + + #print(parse_one(, Pattern(r".b."))) +end +# Write your package code here. +#export dog + +#dog = 1.2 + + +end \ No newline at end of file diff --git a/src/uahgi.jl b/src/uahgi.jl index 16191e7..08a57bf 100644 --- a/src/uahgi.jl +++ b/src/uahgi.jl @@ -1,5 +1,31 @@ module uahgi +include("./parsing.jl") +using .Parsing +using ArgParse -# Write your package code here. +function parse_commandline() + #= please see: + https://carlobaldassi.github.io/ArgParse.jl/stable/ + =# + s = ArgParseSettings() + @add_arg_table! s begin + "FILE" + help = "the file path to be converted." + required = true + end + + return parse_args(s) end + + +function main() + parsed_args = parse_commandline() + file_path = parsed_args["FILE"] + file_content = open(f->read(f, String), file_path) + Parsing.parse(file_content) +end + +main() +end +