modernc.org/cc@v1.0.1/trigraphs.l (about)

     1  %{
     2  // Copyright 2016 The CC Authors. All rights reserved.
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  // Based on [0], 6.4.
     7  //
     8  
     9  // Implements translation phases 1 and 2 of [0], 5.1.1.2.
    10  %}
    11  
    12  %yyc c
    13  %yyn c = t.Next()
    14  %yym t.Mark()
    15  %yyt t.sc
    16  
    17  %s TRIGRAPHS
    18  
    19  %{
    20  package cc
    21  
    22  import (
    23          "fmt"
    24  )
    25  
    26  const (
    27          _ = iota
    28          scTRIGRAPHS
    29  )
    30  
    31  func (t *trigraphsReader) scan() (r int) {
    32          c := t.Enter()
    33  %}
    34  
    35  %%
    36          c = t.Rule0()
    37  
    38  <TRIGRAPHS>"??!"        return '|'
    39  <TRIGRAPHS>"??'"        return '^'
    40  <TRIGRAPHS>"??("        return '['
    41  <TRIGRAPHS>"??)"        return ']'
    42  <TRIGRAPHS>"??-"        return '~'
    43  <TRIGRAPHS>"??/"        return '\\'
    44  <TRIGRAPHS>"??<"        return '{'
    45  <TRIGRAPHS>"??="        return '#'
    46  <TRIGRAPHS>"??>"        return '}'
    47  
    48  \\\r?\n|\r |
    49  <TRIGRAPHS>"??/"\r?\n
    50  
    51  %%
    52          if c, ok := t.Abort(); ok {
    53                  return c
    54          }
    55          
    56          goto yyAction
    57  }