re: Writing a DSL parser using PegJS VIEW POST


PegJS and other parser combinator libraries are great when you want to parse something that is not amenable to regular expressions but please don't use it to make more external DSLs. For everything that you can use an external DSL for you could have just as well used a small library or framework in an actual programming language. External DSLs don't have syntax highlighting, linting, and error checking and they basically throw away years of effort that actual programming languages have invested in their tooling. We don't need more external DSLs. If you must for some reason make a DSL then use a language that is suited for making internal DSLs like Ruby.

The example in the post

User.ScheduleAppointment has { 
  a UserId userId 
  an AppointmentDatetime appointmentDatetime
  a Location location from {
    a LocationName locationName from location
    a Latitude latitude
    a Longitude longitude

could just as easily have been written as a small internal DSL in Ruby or any other language for that matter without losing all the benefits of syntax highlighting and modern IDE support

describe command: 'User.ScheduleAppointment' do
  field('userId', 'UserId')
  field('appointmentDatetime', 'AppointmentDatetime')
  field('location', 'Location', [
    field('locationName', 'LocationName', ['location']),
    field('latitude', 'Latitude'),
    field('longitude', 'Longitude')

Moreover internal DSLs are much easier to debug when issues invariably arise and external DSLs often don't have any kind of debugging capabilities so user are forced to jump through all sorts of hoops to debug an issue.

code of conduct - report abuse