diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b1046af2fa79f2adb177505fe8b5ed8b3298331..10e01a6dcbc6b62b04fff3ca7909b07fcbb2d2af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog for the repository +## 2020-09-03 +- Added src/comment + - single and multiline comments + +- Added src/ast + - abstract syntax tree example ## 2020-08-31 - Initial README.md - Setup simple example \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..612c9c330b81548ffc436acf5611cd8b5825f29b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,558 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +dependencies = [ + "memchr", +] + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" + +[[package]] +name = "ascii-canvas" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff8eb72df928aafb99fe5d37b383f2fe25bd2a765e3e5f7c365916b6f2463a29" +dependencies = [ + "term", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" + +[[package]] +name = "blake2b_simd" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if", + "lazy_static", +] + +[[package]] +name = "d7050e_2020" +version = "0.1.0" +dependencies = [ + "lalrpop", + "lalrpop-util", + "regex", +] + +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "docopt" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f525a586d310c87df72ebcd98009e57f1cc030c8c268305287a476beb653969" +dependencies = [ + "lazy_static", + "regex", + "serde", + "strsim", +] + +[[package]] +name = "either" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" + +[[package]] +name = "ena" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" +dependencies = [ + "log", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fixedbitset" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" + +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" +dependencies = [ + "autocfg", +] + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "indexmap" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e47a3566dd4fd4eec714ae6ceabdee0caec795be835c223d92c2d40f1e8cf1c" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + +[[package]] +name = "lalrpop" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f55673d283313791404be21209bb433f128f7e5c451986df107eb5fdbd68d2" +dependencies = [ + "ascii-canvas", + "atty", + "bit-set", + "diff", + "docopt", + "ena", + "itertools", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax", + "serde", + "serde_derive", + "sha2", + "string_cache", + "term", + "unicode-xid", +] + +[[package]] +name = "lalrpop-util" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7e88f15a7d31dfa8fb607986819039127f0161058a3b248a146142d276cbd28" +dependencies = [ + "regex", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" + +[[package]] +name = "log" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "petgraph" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "phf_shared" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" +dependencies = [ + "siphasher", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom", + "redox_syscall", + "rust-argon2", +] + +[[package]] +name = "regex" +version = "1.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" + +[[package]] +name = "rust-argon2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19" +dependencies = [ + "base64", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + +[[package]] +name = "serde" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + +[[package]] +name = "siphasher" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" + +[[package]] +name = "string_cache" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2940c75beb4e3bf3a494cef919a747a2cb81e52571e212bfbd185074add7208a" +dependencies = [ + "lazy_static", + "new_debug_unreachable", + "phf_shared", + "precomputed-hash", + "serde", +] + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + +[[package]] +name = "syn" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "term" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" +dependencies = [ + "byteorder", + "dirs", + "winapi", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index a4ab3bcfe4528280efb90451737b0ae4d1ba8d60..c1eec0cc513444f0b046329aa6472a7bd4ba6749 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,11 @@ regex = "1.3.9" [[bin]] name = "minimal" path = "src/minimal/main.rs" + +[[bin]] +name = "comments" +path = "src/comments/main.rs" + +[[bin]] +name = "ast" +path = "src/ast/main.rs" diff --git a/src/ast/ast.rs b/src/ast/ast.rs new file mode 100644 index 0000000000000000000000000000000000000000..e79e70de9cab432b6a84b5ac4e10179b50c3db3e --- /dev/null +++ b/src/ast/ast.rs @@ -0,0 +1,7 @@ +// ast + +#[derive(Debug)] +pub enum NumOrId { + Num(usize), + Id(String), +} \ No newline at end of file diff --git a/src/ast/main.rs b/src/ast/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..2a0f6624d6b3f24a0f215bee20eee2f062967803 --- /dev/null +++ b/src/ast/main.rs @@ -0,0 +1,19 @@ +use lalrpop_util::lalrpop_mod; + +lalrpop_mod!(pub parser, "/ast/parser.rs"); + +use parser::*; + +pub mod ast; + +fn main() { + println!("minimal"); + println!("{:?}", NumOrIdParser::new().parse("123")); + println!("{:?}", NumOrIdParser::new().parse("a1_a")); +} + +#[test] +fn parse_num_or_id() { + // println!("{:?}", NumOrIdParser::new().parse("123")); + // println!("{:?}", NumOrIdParser::new().parse("a1_a")); +} diff --git a/src/ast/parser.lalrpop b/src/ast/parser.lalrpop new file mode 100644 index 0000000000000000000000000000000000000000..d749efaba2644b25cd0beced5b5b05d3a66e21e5 --- /dev/null +++ b/src/ast/parser.lalrpop @@ -0,0 +1,18 @@ +use std::str::FromStr; + +use crate::ast::*; + +grammar; + +pub NumOrId : NumOrId = { + Num => NumOrId::Num(<>), + Id => NumOrId::Id(<>), +} + +pub Num: usize = { + r"[0-9]+" => usize::from_str(<>).unwrap(), +}; + +pub Id: String = { + r"([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|_)*" => String::from_str(<>).unwrap(), +}; diff --git a/src/comments/main.rs b/src/comments/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..8a822c98d9e5a7a3ecad4fa42ca9fe813bd7c351 --- /dev/null +++ b/src/comments/main.rs @@ -0,0 +1,38 @@ +use lalrpop_util::lalrpop_mod; + +lalrpop_mod!(pub parser, "/comments/parser.rs"); + +use parser::*; + +fn main() { + println!("comments"); +} + +#[test] +fn parse_id() { + println!( + "{:?}", + IdParser::new().parse( + " + + //a1_a // + + /* + a1_a + */ + a1_a + " + ) + ); +} + +#[test] +fn parse_num() { + println!("{:?}", NumParser::new().parse("123")); +} + +#[test] +fn parse_num_or_id() { + println!("{:?}", NumOrIdParser::new().parse("123")); + println!("{:?}", NumOrIdParser::new().parse("a1_a")); +} diff --git a/src/comments/parser.lalrpop b/src/comments/parser.lalrpop new file mode 100644 index 0000000000000000000000000000000000000000..1372d50e8c0b180caf2510af2e518a262801843b --- /dev/null +++ b/src/comments/parser.lalrpop @@ -0,0 +1,55 @@ +use std::str::FromStr; + +grammar; + +match { + // The default whitespace skipping is disabled an `ignore pattern` is specified + r"\s*" => { }, + // Skip `// comments` + r"//[^\n\r]*" => { }, + // Skip `/* comments */` + r"/\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*])*\*/" => { }, + _ +} + +pub NumOrId = { + Num => <>.to_string(), + Id, +} + +pub Num: usize = { + r"[0-9]+" => usize::from_str(<>).unwrap(), +}; + +pub Id: String = { + r"([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|_)*" => String::from_str(<>).unwrap(), +}; + +// lets try to break down the multi-line comment +// +// should allow patterns like +// /* +// ... +// */ +// and +// /* /* +// */ +// */ +// but reject patterns like +// /* /* +// */ +// and +// /* */ */ +// +// Rather tricky right... +// +// /\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*])*\*/ +// the outer "/\* ... \*/" requires start and end "/*" ... "*/" +// so let's look closer at "([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*])*" +// the trailing "*", just means any number of +// "[^\*]*\*+[^\*/])*([^\*]*\*+|[^\*]" +// +// "[^\*]*\*+[^\*/])*" +// "[^\*]*"" any number or Not("*"), e.g. 0123 +// "\*" one or many "*", e.g. *, or **** +// .... ehhh I gave up, regexp is haaaaaaarrrrrrrd, another day perhaps \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a319e9138f38ddf0983b19743eb6e3f4f6379f93..a7b0dbd15c51b37b79693a8c9d75647a16ac45e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,11 +5,11 @@ lalrpop_mod!(pub grammar); use grammar::*; fn main() { - println!("hello world"); + println!("Parse an Id {:?}", IdParser::new().parse("abcd")); } #[test] fn hello() { - println!("Hello in test") + println!("Parse an Id {:?}", IdParser::new().parse("abcd")); } diff --git a/src/minimal/main.rs b/src/minimal/main.rs index 1f5731be37427916bffece74868abcda7e82c282..57491867b38712c3eb1a67c3445dd6673a4b60bd 100644 --- a/src/minimal/main.rs +++ b/src/minimal/main.rs @@ -4,29 +4,10 @@ lalrpop_mod!(pub parser, "/minimal/parser.rs"); use parser::*; -fn main() {} - -#[test] -fn parse_id() { - println!( - "{:?}", - IdParser::new().parse( - " - - //a1_a // - - /* - a1_a - */ - a1_a - " - ) - ); -} - -#[test] -fn parse_num() { - println!("{:?}", NumParser::new().parse("123")); +fn main() { + println!("minimal"); + println!("{:?}", NumOrIdParser::new().parse("123")); + println!("{:?}", NumOrIdParser::new().parse("a1_a")); } #[test] diff --git a/src/minimal/parser.lalrpop b/src/minimal/parser.lalrpop index 1372d50e8c0b180caf2510af2e518a262801843b..f8d09917b2db19bdd07e0fbd41e9fad7ff273a2d 100644 --- a/src/minimal/parser.lalrpop +++ b/src/minimal/parser.lalrpop @@ -2,16 +2,6 @@ use std::str::FromStr; grammar; -match { - // The default whitespace skipping is disabled an `ignore pattern` is specified - r"\s*" => { }, - // Skip `// comments` - r"//[^\n\r]*" => { }, - // Skip `/* comments */` - r"/\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*])*\*/" => { }, - _ -} - pub NumOrId = { Num => <>.to_string(), Id, @@ -24,32 +14,3 @@ pub Num: usize = { pub Id: String = { r"([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|_)*" => String::from_str(<>).unwrap(), }; - -// lets try to break down the multi-line comment -// -// should allow patterns like -// /* -// ... -// */ -// and -// /* /* -// */ -// */ -// but reject patterns like -// /* /* -// */ -// and -// /* */ */ -// -// Rather tricky right... -// -// /\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*])*\*/ -// the outer "/\* ... \*/" requires start and end "/*" ... "*/" -// so let's look closer at "([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*])*" -// the trailing "*", just means any number of -// "[^\*]*\*+[^\*/])*([^\*]*\*+|[^\*]" -// -// "[^\*]*\*+[^\*/])*" -// "[^\*]*"" any number or Not("*"), e.g. 0123 -// "\*" one or many "*", e.g. *, or **** -// .... ehhh I gave up, regexp is haaaaaaarrrrrrrd, another day perhaps \ No newline at end of file