Text Mate มองไปข้างหลังหลังจากความยาวอักขระที่ไม่คงที่

ฉันกำลังทำงานกับการเน้นไวยากรณ์สำหรับภาษาการเขียนโปรแกรมที่ไม่รองรับโดย Visual Studio Code การไฮไลต์ทำงานได้ดี แต่ฉันประสบปัญหาในการเน้นโค้ดต่อไปนี้:

pool[] Test1 t1;
pool[1] Test2 t2;
pool[10] Test3 t3;

ฉันกำลังเน้นคำว่า "พูล" โดยใช้:

"storages": {
    "patterns": [{
        "name": "storage.type.ceu",
        "match": "\\bpool\\b"
    }]
},

และมันก็ใช้งานได้ แต่ฉันต้องการเน้นคำว่า Test1, Test2 และ Test3 ด้วยเช่นกัน

ความคิดเดียวของฉันคือการใช้การมองด้านหลังในแง่ลบ เช่นนี้:

(?<=pool\[\d*\]\s+)([A-Z])\w+

ฉันสร้างลิงก์ออนไลน์ด้วยแนวคิดนี้: https://regexr.com/4793u

แต่ oniguruma (regex ที่ใช้โดย TextMate - และ Ruby) ไม่อนุญาตให้ใช้ lookaround จาก doc:

(?=subexp)         look-ahead
  (?!subexp)         negative look-ahead
  (?<=subexp)        look-behind
  (?<!subexp)        negative look-behind

                     Subexp of look-behind must be fixed-width.
                     But top-level alternatives can be of various lengths.
                     ex. (?<=a|bc) is OK. (?<=aaa(?:b|cd)) is not allowed.

                     In negative look-behind, capturing group isn't allowed,
                     but non-capturing group (?:) is allowed.

ไม่มีใครรู้ทางเลือกอื่นเพื่อเน้นไวยากรณ์นี้หรือไม่




คำตอบ (1)


คุณสามารถใช้กลุ่มจับภาพ ที่นี่ฉันจับภาพ 3 กลุ่ม แต่กำหนดขอบเขตให้กับกลุ่มที่ 2 เท่านั้น

"storages": {
    "patterns": [{
        "match": "^(\w+\[\d*\])\s+(\w+)\s+(\w+);$",
        "captures": {
            "2": {
                "name": "storage.type.ceu"
            }
        }
    }]
},
person Matt    schedule 28.01.2019
comment
ขอบคุณมาก. การแก้ปัญหาได้ผลอย่างมีเสน่ห์ - person Anny Caroline; 29.01.2019